I am reading data from the serial-port in one window application which is already build by Bill Acceptor Company. Now i want to read the value from that application to my window application. I am using Sender.send key for this and it is working fine when i click on button event but i want to use timer and when i use this, I get an Exception in my .NET application saying "SendKeys cannot run inside this application because the application is not handling Windows messages".
Any help?
Loading

Vijay YadavPosted Feb 29, 2012, 2:05 AM
Thanks a lot.
I agree with you. But the thing is that I ma not able to do this even with WM_SETText and WM_GETTEXT.
I hope you have understood my requirement clearly. Please help me and meanwhile i will start the new thread.
Sam HobbsPosted Feb 29, 2012, 1:56 AM
If however you are askinghow to use WM_COPY and WM_PASTE to solve a different problem then you need to create a separate thread for that.
Since this thread has gotten so long, it is better to create a new thread for this discussion also. In your new thread you need to explain the details of the requirements for your program; not the programming details of how to do it but the requirements of what the program needs to do. In other words, it is my understanding that you need to execute another program, wait for the program to start communications then get text from a textbox. I think we do not have enough of the details like that of what you need.
Vijay YadavPosted Feb 29, 2012, 1:22 AM
Sam HobbsPosted Feb 29, 2012, 12:51 AM
WM_COPY is for copying a textbox's contents to the clipboard and WM_PASTE is for putting text into a textbox from the clipboard'.
Vijay YadavPosted Feb 29, 2012, 12:02 AM
I have gone thtrough the document and i tried to do but unsucessful.
As i don't know how to do it exactly and while searching, I came across postmessage WM_COPy and WM_Paste but don't how to implement.
Still trying.
Vijay YadavPosted Feb 28, 2012, 7:28 AM
Sam HobbsPosted Feb 28, 2012, 6:53 AM
It will be exciting to get it to work for you. I really hope that the time I have already spent will be beneficial for you.
Vijay YadavPosted Feb 28, 2012, 6:29 AM
I will go throuogh this and let you know.
Please go to sleep as it is too late now. And Sorry for the inconvinience caused to you.
Sam HobbsPosted Feb 28, 2012, 6:20 AM
The control ids are different for all the controls shown in that image. Assuming the controls are textboxes, you need to use 3E8, 3E9 and 3EF in the second parameter of the GetDlgItem function for each of the controls.
You will need to spend some time learning what the functions do. I will try to explain anything you need help with but you need to also read the documentation. When using the Windows API, windows are identified by a window handle.
Please look at the documentation of SendMessage; it is important that you understand how it works. The first parameter of SendMessage is the window handle. The second parameter is the message id. The other two parameters are the wparam and the lparam. The value of wparam and the lparam depends on what the message is. You can look up in the MSDN what each message is, for example WM_GETTEXT message.
The GetWindowThreadProcessId is used here to get the process id for a window handle. I use it here to ensure that I have the correct window handle for the Save As dialog. You might not need to do that in your program.
The GetDlgItem function is used to determine the window handle of a control when we know what the control id is but we do not know what the handle is.
FindWindowEx is used to find a window that matches a specified criteria. Here I use it to find the Save As dialog box. You might not need to do that in your program.
I can understand that programmers not experienced with Windows programming using the Windows API would be confused by the Windows API.
It is nearly 5 PM for you in India but it is after 3 AM for me. I need to get to sleep soon.
Vijay YadavPosted Feb 28, 2012, 5:30 AM
Vijay YadavPosted Feb 28, 2012, 4:19 AM
Vijay YadavPosted Feb 28, 2012, 3:53 AM
I am not getting you. I want to know how to call that applciation and hide it as i don't want to display that application.
Sam HobbsPosted Feb 28, 2012, 2:56 AM
Sam HobbsPosted Feb 28, 2012, 2:24 AM
Vijay YadavPosted Feb 28, 2012, 2:18 AM
Here it goes,
Window 000D0678 "ID003 Basic Driver V1.6" #32770
000606B0 'START COMMUNICATION BUTTON'
000B079C 'ACCEPT BILL'
000606B2 'EDIT'
As soon as the communication is established through serial port 'Edit' will get value and I need to copy this to my application and click the "Accept Bill" button without allowing this application to activate means it should be hidden.
Vulpes and Sam, I am trying to get this done soon as i don't have much time now. Please help me.
Vijay YadavPosted Feb 28, 2012, 1:17 AM
Vijay YadavPosted Feb 28, 2012, 12:59 AM
I went through the explanation of Spy++, now the thing is that, the file which i sent you in that there is one panel and inside that there is four button and for all four button i get the same id or it is showing the Id of that panel.
Can you please suggest?
Sam HobbsPosted Feb 28, 2012, 12:41 AM
Sam HobbsPosted Feb 28, 2012, 12:38 AM
Note for me, I had to use the x64 version of Spy++; the x86 version did not work with Notepad. You will find the 64-bit version in the same directory as the x86 version.
Vijay YadavPosted Feb 28, 2012, 12:23 AM
Thanks for your reply.
I want to know that how can we find the textbox id and button id in order to perform the operation as the application is already build by other company.
I have attached the image file of that aplication, please have a look.
All I need to first the copy the data from 'Denomination' tetxbox which is readonly and then i need to press the 'Accept Bill' button and that value should get copied to my application.
Sam HobbsPosted Feb 27, 2012, 9:58 PM
Sam HobbsPosted Feb 27, 2012, 9:53 PM
The following is a console program that executes Notepad, puts some text into it,
then does a save but then it clicks the cancel button instead of saving the
data. I do not consider this to be production-quality in the sense that I would
add more error checking at least. This is a sample; at least it shows that it is
possible.
Note that control id values such as in the TextBoxId, CancelButtonId
and FileMenuId are usually constant for every application so once you
determine those values for the application you ned to do this for, you can use
those values in your program without a need to modify the ids unless the other
program changes and the values it uses has changed.
{{{{}}/// /// Find the Save As dialog. I't kno how reliable this is; this is/// just for demostration purposes.////// Process id of the other process///Window handle for the Save As dialog {}}}Sam HobbsPosted Feb 27, 2012, 3:44 PM
And remember, you can click a button directly instead of sending an enter key to do that.
VulpesPosted Feb 27, 2012, 2:48 PM
Sam HobbsPosted Feb 27, 2012, 6:24 AM
Note that messages are not enough for controls that were created for 32-bit Windows. You say, what? I mean that SendMessage and PostMessage will work for Edit controls (TextBoxes) and ListBoxes because they existed in 16-bit Windows. So it is possible to use controls in other processes because Windows still supports use of the controls that existed in 16-bit Windows in the same way that they were used. Other controls, such as the ListView control, cannot be controlled so easily. So it depends on the application whether messages will work. If it can work, then it is what most experienced Windows developers would use.
The next level of sophistication is system hooks. You can use C# to do a low-level keyboard hook that can be used for just the one process. The problem is that a keyboard hook is not enough, so you will need to use a little C++ to use hooks.
There is something even more technical than hooks; that is to inject code into the other process. That is something you (your company) needs to spend a lot of money just to use it in a commercial application. Well, there might be more economical versions, but it is not free and/or you need to be very experienced with Windows to do any of that.
Vijay YadavPosted Feb 27, 2012, 6:11 AM
I need to copy the value from another application and paste it in my applicaitona and hit the enter the button of that application afetre copying. so how to do that?
VulpesPosted Feb 27, 2012, 5:26 AM
Your only hope is to use PostMessage or, if you need to wait for each keystroke to be processed, SendMessage.
Vijay YadavPosted Feb 27, 2012, 2:32 AM
I tried this but it doesn't perform the action on that application as the application gets hide, it sends the 'enter key' to my application button.
VulpesPosted Feb 24, 2012, 9:55 AM
Vijay YadavPosted Feb 23, 2012, 7:57 AM
I don't want to kill a process, all I want is to just hide that application because as I am using timer after every 3 second the focus move to another application and vice versa. I want to know is there any other alternative so that I should not use timer.
For example ATM machine,
Already there is one screen, as soon as we swipe the ATM card, the event gets fired automatically and it move to the next page i.e. the PIN page where we enter the PIN number.
I want to do something like that. Any idea?
Sam HobbsPosted Feb 20, 2012, 10:57 PM
As indicated in my reply to the other thread, I agree that using something such as PostMessage is better if it is possible, hoever PostMessage is asynchronous. It is better to use SendMessage if possible. It can be critical to use the appropriate one.
VulpesPosted Feb 20, 2012, 11:20 AM
Vijay YadavPosted Feb 20, 2012, 10:16 AM
Now the question is I don't the that another application to get activate over my application, when the serial port connnection gets established that second application( from where I'm copying the data to the label text of my application) gets activated and i don't to show that application to the user. Any idea?
VulpesPosted Feb 20, 2012, 9:56 AM
http://www.c-sharpcorner.com/Forums/Thread/112138/sending-data-from-one-application-to-another-application-fi.aspx
so we don't get locked out as the post count reaches 40 (or so) which I've seen happen on several occasions in the past.
For the benefit of Pramod and anyone else reading this thread, we currently have this code which is producing no error but the label is blank:
So "USA 20" is in the Clipboard and should therefore be in the text variable and (initially at least) in label1.Text. I'd check the value in the debugger or do a MessageBox.Show just after that line to make sure it is.
So what then is in label10.Text?
Vijay YadavPosted Feb 20, 2012, 7:43 AM
Pramod Kumar NandagiriPosted Feb 20, 2012, 7:40 AM
system.windows.forms.sendkeys.sendwait("your key");
i think this may work in timer control