1

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.

3
  • I suspect this is going to be way more trouble than fixing the issue that's causing the dialog to pop-up, trouble both during the install and after it. After all, there has to be a good reason for a modal dialog popping up. Commented Jan 27, 2010 at 15:08
  • Indeed, it might well be and I'll probably be posting about that too. But this approach also helps improve my development skills and just seems way more fun! :) Commented Jan 27, 2010 at 15:09
  • see autohotkey.com, with source Commented Jan 27, 2010 at 16:30

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Two ways to do this:

  • To get the handle, when you talk about a window, use the FindWindow API, then you would have to enumerate the controls associated with that handle, and send a message WM_BUTTONDOWN, WM_BUTTONUP together to simulate a mouse click via using a SendMessage.
  • But the simpler method exists, suppose the cancel button is called 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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.