Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello all,

I am controlling a WPF application from another windows application through UI Automation.

Now, I know how to click a button through UI automation (through Invoke control), but lets say if I am clicking some dialog button manually in WPF application than how would I know if the button has been clicked inside the Windows Form Application?

In short I want to get the handle of the button click after it has been clicked inside the windows form application from where i am controlling the wpf application.

What I have tried:

I have clicked the button through UI Automation but how to get the handle
Posted
Updated 2-Sep-19 23:01pm

1 solution

To find the handle of the button, you can use FindWindowEx:
FindWindowExA function (winuser.h) | Microsoft Docs[^]
pinvoke.net: FindWindowEx (user32)[^]

And then, if you want to listen for clicks on that button, you can use SetWindowsHookEx:
SetWindowsHookExA function (winuser.h) | Microsoft Docs[^]
pinvoke.net: SetWindowsHookEx (user32)[^]

I can't give a lot more concrete guidance because my experience with these functions is limited, but these are roughly the steps that you can take.
 
Share this answer
 
Comments
Faran Saleem 3-Sep-19 6:02am    
No, I dont want to find the handle of the button, I just want to know if the button has been clicked or not
Thomas Daniels 3-Sep-19 6:15am    
You'll still need the hook, at least. At some point you may also need the handle of the button (to differentiate between other clicks), although I have not found any examples of this so now I'm not sure if it's even possible to do that. I'd still recommend looking into SetWindowsHookEx because it's the closest you can get.
Faran Saleem 3-Sep-19 8:26am    
Okay thanks I will explore it

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