Sign in to follow this  

Send messages to some windows

This topic is 1716 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

I want to create an app that can send a message to the skype window saying that i pressed button x.(just an example)

 

How would I do that? I heard about spy++ but I have a hard time finding how to actually use it in code.

Share this post


Link to post
Share on other sites

You could:

 

OPTION 1:

1) as prep work, call WindowFromPoint() to manually get the Skype window's name by hovering over it on your desktop (or just google for it ;) ) - just call it as response to a WM_MOUSEMOVE in a test application

2) programmatically call FindWindow() to look for the window name from 1 and get the HWND

 

OPTION 2:

1) use the process name as a starting point

 

3) GetWindowThreadProcessId() returns the process's ID from HWND

4) Enumerate and get the process' main thread from the window handle (I'm pretty sure it's the first one)

5) Send the message using PostThreadMessage()

Share this post


Link to post
Share on other sites

Solved it.Decided to use FindWindow() to get the window's hwnd.The I use SendMessage to create an artificial mouse click.

Share this post


Link to post
Share on other sites

Solved it.Decided to use FindWindow() to get the window's hwnd.The I use SendMessage to create an artificial mouse click.

 

This might not work the way you expect if you need to send keystrokes though.

 

In the case of keyboard events more happens when you type than just a WM_*  msg popping up in some windows message queue and it is impossible for these events to arise in a non-foreground window under normal use, so merely fabricating windows messages usually doesn't do what you want it to do. The way to do this that actually works for keyboards is to make the target window foreground and use SendInput(...) as someone said above; although, I don't think it is possible to foreground an arbitrary window across processes the way that it was years ago ... so not sure.

 

Actually I'm slightly surprised sending a WM_LBUTTONDOWN or whatver actually worked. This can have all kinds of unexpected results, if the target window proc uses GetCursorPos() instead of the coordinates in the WPARAM etc.

Share this post


Link to post
Share on other sites
Sign in to follow this