PDA

View Full Version : c++ send mouse click to specific window handle


nightthepope
03-12-2005, 07:44 PM
Hi I was wondering how I would go about sending a mouse click to another window which I already know the handle to.

I want it to be able to click a button within the window even when the window is minimized.

Could anyone give me a function or some help on this?

I've tried messing around with PostMessage() but I haven't been able to nail it.

Thank you in advance.

Dr. Evil
03-12-2005, 09:25 PM
There's a function called mouse_event() (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/mouseinput/mouseinputreference/mouseinputfunctions/mouse_event.asp) which might be what you're looking for.

nightthepope
03-12-2005, 11:03 PM
I might be wrong but that function seems to look like it will only work if my app is on the screen.

I was looking for something where I could be able to send mouseclicks to a program window that has been minimized.

nightthepope
03-12-2005, 11:57 PM
Actually theres a button in the window, and I know the handle to the window, I just want the mouse to click the button; even when the window is minimized. Will sending a WM_MOUSEDOWN and WM_MOUSEUP to the window I know the handle to be able to click the button inside of it?

aman
03-13-2005, 12:19 AM
It's been awhile since I've done this, but if I remember correctly you need to send your event to the button handle, not the main window. If a window gets a buttondown event, what will it do with it if it doesn't know what was clicked? Also, I dont think it will work on minimized windows.

Anyway, check here for a great example on how to send messages to any window.. http://www.codeguru.com/Cpp/W-P/win32/article.php/c4543/

nightthepope
03-13-2005, 04:51 AM
That makes sense, any idea on how I could find the button handle if I have the window handle?

Dr. Evil
03-13-2005, 09:27 AM
If you're just trying to simulate a button event and the app is one in particular, why don't you try to find the button's ID and send the main window a WM_COMMAND message with that button's ID as the low word of the wParam and BN_CLICKED as the high word. And you could find the ID by simply enumerating the child windows and comparing the text on each window with that of which you're looking for.

Mhtml
03-13-2005, 11:52 AM
Well there is an easier method to find the button, just use-
FindWindow() or FindWindowEx()

And sending WM_COMMAND is probably a good idea, but either way will work. Or rather should work.