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


Pramod Kumar NandagiriRank #6,963 · 252 reputationPosted Feb 20, 2012, 2:40 AM EST
system.windows.forms.sendkeys.sendwait("your key");
i think this may work in timer control
Vijay YadavRank #1,637 · 943 reputationPosted Feb 20, 2012, 2:43 AM EST
VulpesRank #55 · 29.2K reputationPosted Feb 20, 2012, 4:56 AM EST
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 YadavRank #1,637 · 943 reputationPosted Feb 20, 2012, 5:16 AM EST
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?
VulpesRank #55 · 29.2K reputationPosted Feb 20, 2012, 6:20 AM EST
Sam HobbsRank #107 · 20.5K reputationPosted Feb 20, 2012, 5:57 PM EST
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.
Vijay YadavRank #1,637 · 943 reputationPosted Feb 23, 2012, 2:57 AM EST
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?
VulpesRank #55 · 29.2K reputationPosted Feb 24, 2012, 4:55 AM EST
Vijay YadavRank #1,637 · 943 reputationPosted Feb 26, 2012, 9:32 PM EST
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.
VulpesRank #55 · 29.2K reputationPosted Feb 27, 2012, 12:26 AM EST
Your only hope is to use PostMessage or, if you need to wait for each keystroke to be processed, SendMessage.
Vijay YadavRank #1,637 · 943 reputationPosted Feb 27, 2012, 1:11 AM EST
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?
Sam HobbsRank #107 · 20.5K reputationPosted Feb 27, 2012, 1:24 AM EST
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.
VulpesRank #55 · 29.2K reputationPosted Feb 27, 2012, 9:48 AM EST
Sam HobbsRank #107 · 20.5K reputationPosted Feb 27, 2012, 10:44 AM EST
And remember, you can click a button directly instead of sending an enter key to do that.
Sam HobbsRank #107 · 20.5K reputationPosted Feb 27, 2012, 4:53 PM EST
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.
static extern int GetWindowThreadProcessId(IntPtr handle, out int processId);static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, string lParam);static extern IntPtr FindWindowEx(IntPtr parentHandle, int childAfter, string lclassName, int windowTitle);Console .WriteLine("Process id: {0:X}; Main window: {1:X}; TextBox {2:X} " , OtherProcess.Id,Sam HobbsRank #107 · 20.5K reputationPosted Feb 27, 2012, 4:58 PM EST
Vijay YadavRank #1,637 · 943 reputationPosted Feb 27, 2012, 7:23 PM EST
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 HobbsRank #107 · 20.5K reputationPosted Feb 27, 2012, 7:38 PM EST
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.
Sam HobbsRank #107 · 20.5K reputationPosted Feb 27, 2012, 7:41 PM EST
Vijay YadavRank #1,637 · 943 reputationPosted Feb 27, 2012, 7:59 PM EST
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?
Vijay YadavRank #1,637 · 943 reputationPosted Feb 27, 2012, 8:17 PM EST
Vijay YadavRank #1,637 · 943 reputationPosted Feb 27, 2012, 9:18 PM EST
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.
Sam HobbsRank #107 · 20.5K reputationPosted Feb 27, 2012, 9:24 PM EST
Sam HobbsRank #107 · 20.5K reputationPosted Feb 27, 2012, 9:56 PM EST
Vijay YadavRank #1,637 · 943 reputationPosted Feb 27, 2012, 10:53 PM EST
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.
Vijay YadavRank #1,637 · 943 reputationPosted Feb 27, 2012, 11:19 PM EST
Vijay YadavRank #1,637 · 943 reputationPosted Feb 28, 2012, 12:30 AM EST
Sam HobbsRank #107 · 20.5K reputationPosted Feb 28, 2012, 1:20 AM EST
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 YadavRank #1,637 · 943 reputationPosted Feb 28, 2012, 1:29 AM EST
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 HobbsRank #107 · 20.5K reputationPosted Feb 28, 2012, 1:53 AM EST
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 YadavRank #1,637 · 943 reputationPosted Feb 28, 2012, 2:28 AM EST
Vijay YadavRank #1,637 · 943 reputationPosted Feb 28, 2012, 7:02 PM EST
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.
Sam HobbsRank #107 · 20.5K reputationPosted Feb 28, 2012, 7:51 PM EST
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 YadavRank #1,637 · 943 reputationPosted Feb 28, 2012, 8:22 PM EST
Sam HobbsRank #107 · 20.5K reputationPosted Feb 28, 2012, 8:56 PM EST
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 YadavRank #1,637 · 943 reputationPosted Feb 28, 2012, 9:05 PM EST
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.