How to send an event with a mouse click to a hidden window?

Recognizing that an interop bit may be required, how do I send a mouse click event to a window that is not currently displayed? I have an application that works as a service and tinkers with hidden windows, and I need to send an event with a mouse click on one of them, even if it cannot display the window.

In a normal way, I would just send a click on the screen in the appropriate place, but obviously this method will not work in this case. Ideas?

+2
c # winapi winforms
Oct. 25 '09 at 16:08
source share
2 answers

If you can get HWND windows, this is pretty easy. Use PostMessage () with WM_LBUTTONDOWN for left click.

Example: click on 10.10 (untested, C)

HWND hWnd = (hwnd of window) WORD mouseX = 10; WORD mouseY = 10; PostMessage(hWnd,WM_LBUTTONDOWN,0,MAKELPARAM(mouseX,mouseY)); 
+3
Oct 25 '09 at 16:23
source share

Use Spy ++ to find out which Windows messages are sent to the window when it is displayed, and you physically click it, and then use SendMessage to send these messages directly.

+2
Oct 25 '09 at 16:12
source share



All Articles