Reputation: 34489
I'm sure this is possible somehow, but not sure if there are a few too many hoops to jump through to make it worthwhile, hoping someone might point me in the right direction. I've got a problem (related to an installer) whereby I have a dialog popup quite regularly which I need to press cancel on.
What I'd like to do is close it programatically/maybe via a service so it stops getting in my way (assuming I can't fix the root issue). So, what I'm wondering is if there is a way to grab a handle to the window somehow (checking it's correct maybe by doing a text comparison on the label), then locating a control on the window (cancel button) and sending an event to it?
If anyone knows how I might achieve this or some starters that'd be great.
Upvotes: 1
Views: 2212
Reputation: 34592
Two ways to do this:
btnCancel
, then this would suffice btnCancel.Click()
. Unless I am mistaken, that you are talking about a window of a process that is not yours, then my first suggestion would do. Since you did not say, if you are talking about your own application or a process's window that is not yours...then Oliver's suggestion might be easier...
But that begs the question: why would you want to do that as you are assuming there is a Cancel button somewhere...
Hope this helps, Best regards, Tom.
Upvotes: 0
Reputation: 45071
Take a look into AutoIt3. It can do such casts quite easy and if you dig a little deeper into it, you'll find out which WindowsAPI calls it uses to do its stuff. These APIs you can then PInvoke in C# if you really need it there. Otherwise just write an AutoIt script to perform your task.
Upvotes: 1