Automation and window focus

Hi,

I have a (minor?) problem with an MFC application that I wrote, it uses MS Word to do some spellchecking.

(To connect to Word I use the #import compiler directive to get some usefull wrappers to Word for automation.)

The program consists of one dialog (it's a dialog based application), the main window, from where the user can activate the spellchecking.

When spellchecking is activated, I currently call ->EnableWindow(false) on all the controls in the window, and then I use the Word Spellchecker.

Now the problem, when the Word spellchecker is shown, if the user tries to click on different things in the main window (behind the word spellchecker window), a "Server Busy" dialog is shown, not allways, but sometimes, stating that basicly the program is busy. The program is of cause busy waiting for the Word spellchecker to finnish, but this can be confusing and disrupt the program.

So basicly, calling ->EnableWindow(false) on the controls in the main window dialog doesn't stop it from trying to handle input messages. BUT doing this keeps the z-order of all the applications/dialogs/windows correct, no problems at all.

To get rid of that "Server Busy" problem I tried to call ->EnableWindow(false) on the main window dialog instead of all the components. This results in the window refusing any input what so ever, as it should, so I never get the "Server Busy" problem. Instead I get a new, worse, problem, whenever the Word Spellchecker dialog closes, my window will not remain at its z-order, since it is diabled, it can not take focus, resulting in any other application being brought to front, hiding my window.

According to the documentation for ->EnableWindow it clearly states that this behaviour is what to expect, what you should do is enable the window, before the other dialog, in this case word spellchecker, closes, that way the main window will get the focus and not any other application.

But how can I do that? Since it's not my window that closes, but a window from an automated component that doesn't know anything about parent windows or dialogs.

I'm somewhat new to MFC, so I don't know exactly what to do in this situation. There must be something I can override, right?

This problem shouldn't be limited to only automating Word, it could probably happen when automating anything that has windows or dialogs.
[2490 byte] By [UncleRedz] at [2007-11-18 8:13:46]