dismiss a dialog box from a NON-INTERACTIVE service

A

Alessio

Hi everybody,
I've been able to automate the mailmerge process with Microsoft
office 2003. Anyway, in some cases, it is still necessary to dismiss
an annoying dialog box unexpectedly shown by Word in the middle of the
whole process.
The application is able to dismiss the dialog box when the Word
automation server and the app itself run in the interactive desktop.
But when the app is started as a non-interactive service, it and the
word automation server are run in a different desktop, thus the dialog
box does not receive the keys sent by the app.
Anyone knows how to dismiss the dialog in this situation? I read
somewhere that any apps running in a non-interactive desktop don't
have the message queue, so it is useless to send them keyboard event
messages. So is it possible to make the app have its message queue? Or
is there any other way to make those dialogs be dismissed?

Thank you very much, and have a nice day
Alessio
 
D

Doug Robbins

What does the dialog box say?

If it's asking whether you want to print, use commands to execute the merge
to a new document, print the document then close it without saving it

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
A

Alessio

Hello Doug,
thank you for your reply, but I already investigated the reasons why
this dialog box is shown, with Cindy Meister (see messages in this
newsgroup, subject: AVOIDING "Select Data Source" dialog box?!?;
date:2004-05-26 08:28:30 PST).
The conclusion was that I have to dismiss the dialog simulating the
user interaction with the dialog.
I have no problem when the application is running in the interactive
desktop, but when the application is running as a service (NOT
interacting with the desktop), then it seems that the dialog box
cannot receive any user input (it simply ignores the keyboard messages
sent by the application?!?)
So, the only thing I need to know now is whether there is any way to
dismiss such a dialog when it is shown by a word automation server run
from a service not interacting with the desktop.
please let me know if you have any suggestions about it.
Thank you
Alessio
 
A

Alessio

Dear all,
I've solved it, and it was even simpler than I imagined!
The "solution" that wasn't working (suggested by MSDN) used the
keybd_event() function to simulate the pressure and release of the ESC
key, with the dialog box window being active. But that didn't work,
since Windows did NOT send the corresponding messages to the active
window, since it was running in a non-interactive desktop.
So, the solution is to directly send those messages to the window
itself, by using the good, old SendMessage() API, sending both
WM_KEYDOWN and WM_KEYUP messages. This makes the window to actually
receive the messages, proving also that its message pump is alive and
kicking. Obviously, you have to know the window handle of the dialog,
but that's not a problem.
Besides, it appears that it is possible to (programmatically) interact
with a service not interacting with the desktop.
Bye,
Alessio
 

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

Top