kampi
kampi

Reputation: 2484

How to send text to an application?

I am trying to make an application, which reads the data from a serial port (on the serial port there 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

Upvotes: 0

Views: 2506

Answers (5)

kichik
kichik

Reputation: 34704

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

Upvotes: 1

Alexandre C.
Alexandre C.

Reputation: 56956

The simplest method should be named pipes.

Upvotes: 0

Andrei Pana
Andrei Pana

Reputation: 4502

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.

Upvotes: 1

Abyx
Abyx

Reputation: 12918

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

Upvotes: 0

detunized
detunized

Reputation: 15289

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.

Upvotes: 0

Related Questions