Archived

This topic is now archived and is closed to further replies.

Getting the handle of a different program

This topic is 5176 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites