By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,459 Members | 1,472 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,459 IT Pros & Developers. It's quick & easy.

Q: Automaticly click ok when a message dialog appears.

P: n/a
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
Jul 11 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

"Martin Arvidsson, Visual Systems AB" <ma**************@vsab.netwrote in
message news:uR**************@TK2MSFTNGP03.phx.gbl...
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
Jul 11 '08 #2

P: n/a
Thank you!

That realy solved my problem.

Regards
Martin

"Andrew Faust" <an****@andrewfaust.comskrev i meddelandet
news:67**********************************@microsof t.com...
>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

"Martin Arvidsson, Visual Systems AB" <ma**************@vsab.netwrote in
message news:uR**************@TK2MSFTNGP03.phx.gbl...
>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

Aug 11 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.