Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to click a button that is located in another window(and that window in some other process).

I tried pretty much every technique...Sending messages with LMBUTTONDOWN,sending messages with WM_COMMAND,but nothing worked.

I got my hands on some delphi code that does the same thing,for the same window,the difference is that I need to do it in c++.

This is the delphi code:
Delphi
PostMessage(AHWND, WM_KEYDOWN, VK_RETURN, 0);
    Sleep(10);
    PostMessage(AHWND, WM_KEYUP, VK_RETURN, 0);


AHWND is the hwnd to the button.That code can be copy-pasted to c++,HOWEVER,it won't do anything.

Some help?
Posted
Comments
Sergey Alexandrovich Kryukov 10-May-13 16:49pm    
Click on another window. Do you have a mouse..? :-)
—SA

1 solution

First of all, let me tell you that you are probably trying to do a dirty things. Writing UI simulation mouse clicks is bad thing. However, I understand that it might be reasonably used for some special purposes: creation and playing back mouse/keyboard macro, creation of the demonstrations, etc.

What you are trying to do is not universal and not reliable, it cannot work in all cases. The only decent way to simulate the user input it this method:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[^].

This is a really low-level and universal function, it works exactly as it would do via a keyboard or a mouse driver. Always works.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900