开发者

How to send text to an application?

开发者 https://www.devze.com 2023-01-29 11:21 出处:网络
I am trying to make an application, which reads the data from a serial port (on the serial port there开发者_Python百科 is a barcode scanner plugged in), and then forwards it to an application. I can r

I am trying to make an application, which reads the data from a serial port (on the serial port there开发者_Python百科 is a barcode scanner plugged in), and then forwards it to an application. I can read data from serial port now, but i don't know, how to forward the read text, to an application, for example notepad. I tried to use SendMessage() API but it didn't succeed. Maybe i did something wrong. Could someone help me, and maybe show some example?

Thanks,

kampi


Sounds like you're looking for keybd_event or the newer SendInput. It allows you to simulate keyboard input.


HWND hwnd = FindWindow(NULL, L"Untitled - Notepad");
SendMessage(hwnd, WM_SETTEXT, NULL, (LPARAM)L"Hello!");

This will set the Notepad's title bar text to Hello. Of course, you can elaborate a bit to find Notepad's textbox control, or to find your own control in an application, or to find the control that has focus in the active foreground window (see GetForegroundWindow), but the idea is that once you have a hwnd of the window/control you want to set text, the above code should work.


If you want to send it to the Notepad, then it would be easier to save the text into a temporary file and then open it with the Notepad. From a Windows application this could be done using CreateProcess.

On the other hand, if you in control of how the receiver application is working, you could use different approaches, such as: pipes, window messages, shared memory and some others. This is a good place to start.


If you mean another application, you should use one of IPC methods.


The simplest method should be named pipes.

0

精彩评论

暂无评论...
验证码 换一张
取 消