Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to detect when a dialog-based app is no longer receiving focus 1

Status
Not open for further replies.

jtrox

Technical User
Nov 22, 2002
8
US
I have a dialog-based app that can launch a modeless dialog and several other modal dialogs (although only one of the modal dialogs at a time). If another application is brought up, the modal dialog boxes are automatically moved to the background. However, the modeless dialog stays on top of any other applications. I'm looking for a way to detect when my app is not active so that I can hide the modeless dialog.

Using Spy++ I can see the messages WM_ACTIVATE and WM_ACTIVATEAPP being passed around, but they cannot be handled through ClassWizard (not presented as an option), and I tried trapping the message using the PreTranslateMessage function in the main dialog, but neither of these messages appear to be sent through the architecture to this dialog class.

Any suggestions for how to do this?
 
I never tried it but i would think you will recieve a WM_WINDOWPOSCHANGING message.

-pete
 
I think setting the parent window handle of your modeless dialog to the main dialog, should be sufficient. If a parent window is being send to the background, so should its children....
Greetings,
Rick
 
Thanks palbano and LazyMe -

I've been playing around with this and haven't made any headway. There is a WM_WINDOWPOSCHANGED message sent, but it isn't unique to the situation when the application is sent to the background. As for the parent window handle, it does appear that the parent of my modeless dialog is the main dialog box. I say this based on using Spy++ to inspect the modeless window.

Is there any way to handle the WM_ACTIVATEAPP or WM_ACTIVATETOPLEVEL messages? They clearly are sent at the time when I would want to hide the window.

Also, what would be the reason that the modeless window is staying on the top when the rest of the App is hidden? I've been looking at my property settings in the Resource Editor, I have the Style set to Popup and the Border set to Dialog Frame. I also have the options for Title bar and System menu set. I've tried many different combinations - nothing really behaves the way that I want it to.

Thanks for any on-going help,

Jason
 
>> Is there any way to handle the WM_ACTIVATEAPP or
>> WM_ACTIVATETOPLEVEL messages?

I don't know if that will help you but all messages can be handled in CWnd::WindowProc(...)

-pete
 
palbano -

Thanks, that actually did help. By overriding the WindowProc function in my dialog class, I am able to handle the WM_ACTIVATEAPP message. Then I can use the modeless window's ShowWindow function to manually display or hide the window as necessary. I then returned the function with a call to the original CWnd::WindowProc() function and all is well.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top