Reputation: 2571
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.
Upvotes: 1
Views: 949
Reputation: 16328
You can use SetWinEventHook to set an event hook function and listen to EVENT_OBJECT_INVOKED
which indicates that an object was invoked (such as a button clicked).
Upvotes: 1