Jump to content
  • Advertisement
Sign in to follow this  
imadoki

Generating Windows Events

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

Please, I need help as fast as possible... I will greatly appreciate any input on this matter. The thing is I am developing a small client server program and it works also with javascript etc. Ok, so, I am using Win32 for one of the client apps and I need to automatically click one or more buttons at a specific location on the dialog box. Ok, I will restate it to reduce any confusion: I have a dialog box with a few buttons, like "accept", "decline" or "continue" and I want the program to automatically click on this button, i.e. I want the win32 app in C++ to generate the mouse click on a specific position (in this case, on the button, or on an edit box, to make it active), how do I do that? how do I generate the event of a mouse left button click at a specific x,y location in Win32 in C++ or C? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
SendMessage plus target window HWND plus WM_COMMAND plus target control ID.

You can also fuss with WM_LBUTTONDOWN, WM_LBUTTONUP and mouse coordinates, but that will probably entail a lot more work than it's worth.

Share this post


Link to post
Share on other sites
To simulate a left click at a given position(screen coords):

SetCursorPos(x, y);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

Hope that helps.

-AJ

Share this post


Link to post
Share on other sites
The easiest way to do this Imo is to use SendMessage like LessBread said, and send a "BM_CLICK" message.


HWND pTargetWindowHandle = FindWindowEx(FindWindow("Parent", NULL), NULL, "Child", NULL);

SendMessage(pTargetWindowHandle, BM_CLICK, NULL, NULL);






Check for errors in WindowHandle if you want.

Share this post


Link to post
Share on other sites
Quote:
Original post by Extrarius
Instead of mouse_event, use SendInput


Isn't mouse_event much easier to use though? I had a look at the SendInput function and mouse_event just seems alot simpler. Granted SendInput may be useful for other things that are more involved. But given the simplicity of what the OP wants to do, I'd say mouse_event does the job in a strightforward manner.

-AJ

Share this post


Link to post
Share on other sites
Listen to MSDN! -> "Windows NT/2000/XP: This function has been superseded. Use SendInput instead." :)

Share this post


Link to post
Share on other sites
Quote:
Original post by raz0r
Listen to MSDN! -> "Windows NT/2000/XP: This function has been superseded. Use SendInput instead." :)


Cleverly hidden at the top of the page [lol]

Share this post


Link to post
Share on other sites
If it is your app that is creating the dialog in the first place then just call the event handler for the button yourself directly. If it is your own set of apps that you could send the other app a custom message instructing it to call the event handler manually. In either case you don't have to futz with the pure evil that is simulating user input via SendInput / mouse_event / etc.

(sincerely hoping you're not trying to automatically click buttons on a security dialog on behalf of the actual user...)

Share this post


Link to post
Share on other sites
Thank you all. No, no, absolutely not. It is just that I am working on a quick fix till I get around to a new version of the client app. The old app was made by someone else and is hell to work on its source code, so until a new version can talk to the updated server, this is there as a stop gap method.

I will try all of the advised stuff later this evening. Thanks.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!