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.
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.
Send a
BM_CLICK
message to the HWND of the button:That causes the button to receive
WM_LBUTTONDOWN
andWM_LBUTTONUP
messages, and the parent to receive anBN_CLICKED
notification, as if the user had physically clicked on the button.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
orPostMessage
, depending on your use case.Try this for OK:
Find the handle to the button that you want to click (by using
FindWindowEx
), and just send click message:Here is a complete function: