Send messages to some windows

Started by
4 comments, last by jwezorek 10 years, 11 months ago

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.

Advertisement

Read this as there is probably a better way of doing this in windows: http://blogs.msdn.com/b/oldnewthing/archive/2009/02/02/9388941.aspx

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

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()

If the window has focus then SendInput() should do the trick.

However, you'd probably be better off using the Skype API directly.

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

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.

This topic is closed to new replies.

Advertisement