Link to home
Start Free TrialLog in
Avatar of tijskex
tijskex

asked on

ShellExecute WaitForSingleObject Troubles with MDI-apps.

Hi,
I want to run other applications from within my app and detect when they are closed. I know how to write the code (ShellExecuteEx and use the hProcess Pointer with WaitForSingleObjectEx). However I have two problems with this implementation:
First problem: when I close MSWord, it takes more than 5 secs. until my application detects Word is closed (probably Word does a lot of finalization after making its main window invisible). However I want to have a dialog popped up in my program the moment the Plugin Application (e.g. Word) is closed and the user returns to my program asking him to upload his document to a server.
Second problem: some applications like Word, Acrobat Reader, Internet Explorer (pity they are so popular) do not return a hProcess handle when opening more than one document. So I cannot use the WaitForSingleObject API call. Is there a possibility to get a handle to the document itself so I can detect when the user closes them?

Thanks in advance,
Bart.

PS I'm searching for a general solution, not a MSWord specific solution.
Avatar of nestorua
nestorua

HI,
I think you want to know the moment the child window of the main window of the external process is about
to close. For this task I recommend you to use Hooks.
Sincerely,
Nestorua.
Avatar of tijskex

ASKER

Can you be a bit more concrete? How do I use these hooks?
How do I detect when the which child window is related to my document file and how do I detect when it is closed?
ASKER CERTIFIED SOLUTION
Avatar of Madshi
Madshi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
HI,
With the hook WH_CBT you can catch the moment when the Child window is about to close and forbid it or do what do you want to before allowing it to close.
Sincerely,
Nestorua.
Avatar of tijskex

ASKER

My fear is that Madshi is right, because I don't think I can ever be sure from which window I receive messages. I mean: if I open two documents and I receive a close hook, I do not know which of the two documents is closed (in case of Word I guess I could look at the caption, but this is no general solution). So probably I will have to make a combination of all kinds of solutions (e.g. in case application is WinWord to this, else to that...).

I leave the question open for a while in case someone has a better solution.





 
HI,
You receive the message from that window which is about to close, so take its handle and work with it.
Sincerely,
Nestorua.
Avatar of tijskex

ASKER

The problem is just to know which window belongs to which document. When I open two documents in a MDI-program (like word), and then I receive a WH_CBT message, how can I know which of the two documents is closed. So I'm looking for a method that returns me the window handle of the document  I opened with ShellExecuteEx. In that way when I receive a WH_CBT message I can compare it with a list of open documents and my program know which document is closed.
tijskex:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.