I have had sucess in the past using SendMessage and BN_CLICKED message (245) to click buttons in other processes. However, this does not work for WPF applications. Can anyone suggest an alternative?


Last time i did anything close to similar i had the luxury of just being able to do the ugly-easy thing: find the process, emulate keyboard tab presses untill i was where i wanted to go and then send enter. If thats an option google “SendKeys in wpf” or something to that effect to get a code snippet that’ll behave similar enough to winforms sendkeys to be usefull. Only really works if the layout is simple or the tabfocus was considered by whoever wrote the program.
The actual “correct” way to do stuff like that would be via https://docs.microsoft.com/en-us/dotnet/framework/ui-automation/ui-automation-overview from what i can tell.
a cursory google search turned up this where the 2nd edit seems to employ the above mentioned framework to do what you want but i didn’t test it:
https://stackoverflow.com/questions/46024070/click-wpf-button-from-another-application
If you own the other wpf process, consider implementing actual inter-process communication with named pipes, MSMQ, WCF etc. instead.
C# devs
null reference exceptions

source