Q: Automaticly click ok when a message dialog appears.

  • Thread starter Thread starter Martin Arvidsson, Visual Systems AB
  • Start date Start date
M

Martin Arvidsson, Visual Systems AB

Hi!

I am constructing a program that will massverify some reports.

How ever there is a message dialog comming up saying that the report is up
to date or needs change.

Is there a way to detect when this dialog appears and send a key stroke or
send a message to the button on the dialog?

I know the title of the message dialog.

Regards
Martin
 
I assume the message boxes are being generated by a separate app that you
have no ability to modify?

You can do this using the Windows API. You can iterate through all the
windows with EnumWindows and EnumChildWindows and get the window text with
GetWindowText. Or you can search for the window directly with FindWindow and
FindWindowEx.

Once you have the handle to the window you can send a message to it via
SendMessage. If it's a standard dialog box, you can probably just send it
WM_KEYDOWN with a parameter of VK_ENTER.

You can find documentation on these APIs in C# on Pinvoke.net. You can also
google the functions I mentioned to find code samples.

As for getting a notification of a new message box, you could probably
create a windows event hook to do it. You can Google windows hooks to find
out more. That's probably overkill, though. I'd probably just use a timer to
have my app check for a new dialog box every 10 seconds or so.

Andrew Faust
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top