Getting the handle of a different program

Started by
1 comment, last by SadBurger 20 years, 6 months ago
Okay, I''m still a pretty new windows program, so take it easy on me guys ;-) I need to know how(if) to get the handle of another running application? Lets say for instance I wanted to make a macro program for the Point-of-sale program at work. I could program scripts into my macro program, and then it would send the appropriate keystrokes to the POS. i''m sure there must be some way to do this, because Macro programs abound for just about every game out there. And once I have the handle, how can I send keystrokes to the other program? Just stuff a MSG and sendmessage it? Will this work even if the program is a console program or only if it is a windows program? I have been trying to figure this out for about a month and figured I might as well post it on here, you guys usually know the answers to everyone''s problems :-) Thanks in advance, Sully
Advertisement
If you know the window title of the other application''s main window, use the FindWindow() function to get a handle to it, then use SendMessage() or PostMessage to send the relevant messages (probably either WM_KEYDOWN or WM_CHAR.)
Will this work even if the program is a console program or only if it is a windows program?

It depends.

Have you read about window classes and window callback procs?

SendMessage(hwnd, msg, wparam, lparam)

Basically, the callback proc of hwnd gets the message. If you send a message that hwnd doesn''t handle, the default handler gets it. Most of the time that means nothing will happen, but sometimes...

With a console program there is a window too - however, it''s a special system class window that operates indepedently of the program. The callback proc governing the console window is not found in the program running in the console. So, a message sent to the console window won''t likely make it to the program running in the console subsystem.

If you want to play around with sending messages to various windows, check out this: MessageSender
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man

This topic is closed to new replies.

Advertisement