I would like to know whether a button in an external app is clicked.
Before I had to do the clicking myself, for which I used the following code:
//Get window
IntPtr wrapUp = Win32API.FindWindowByText(Win32API.GetDesktopWindow(), "WRAP-UP");
if ((int)wrapUp > 0)
{
Win32API.SetFocus(wrapUp);
IntPtr okButton = Win32API.FindWindowByText(wrapUp, "OK");
Win32API.SetFocus(okButton);
Win32API.PostMessage(okButton, Win32API.BM_CLICK, 0, 0);
}
But now I need to know when the user clicks that button.
Is there a way to do this?
I’ve been searching a bit and I’ve found several ways to perform the clicking from code, but not for listening to an event.
You can use SetWinEventHook to set an event hook function and listen to
EVENT_OBJECT_INVOKEDwhich indicates that an object was invoked (such as a button clicked).