I want to simulate a click on a button located in a dialog box.
I have the handle to that window. This is an Abort/Retry/Ignore kind of window.
I don't want to go with simulating a click having X and Y coordinates as it doesn't suit my needs.
SendMessage(hParent, WM_COMMAND, MAKEWPARAM(IdOfButton, BN_CLICKED), (LPARAM)hwndOfButton);
Typically you can get away without the hwndOfButton
, if you don't know it - depends on the dialog's implementation!
It can be SendMessage
or PostMessage
, depending on your use case.
Send a BM_CLICK
message to the HWND of the button:
SendMessage(hButton, BM_CLICK, 0, 0);
That causes the button to receive WM_LBUTTONDOWN
and WM_LBUTTONUP
messages, and the parent to receive an BN_CLICKED
notification, as if the user had physically clicked on the button.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With