dialog based app making modeless dialogs 
Author Message
 dialog based app making modeless dialogs

I have created a few modeless dialogs in a dialog based app, but their
window z positioning isn't that fantastic.

If I let Create use the app main window as the parent when I create the
dialog, each modeless window always sits in front of the main window,
regardless of whether it has the focus or not. If I close these windows
then the main window retrieves the focus again.

I notice someone suggested using GetDesktopWindow() as the parent
instead. Now the modeless dialogs sit behind the main window if the main
window has the focus, but when i close them, the main app window doesn't
regain focus.

What I want is a combination of the two. Modeless dialogs that sit
behind the main window if it has the focus and also return the focus to
the main window when they close.

Thanks,

Chris.

PS As I was writing this I tried something. Adding a
AfxGetMainWnd()->BringWindowToTop(); to the OnClose handlers of these
dialogs. While this works, is there a better way to do this?
--
Chris Cheshire
Software Developer
Northgate Communications Australia
Phone : +61 2 9918 4306
Fax : +61 2 9973 2003

  "Real programmers don't write specs - users "
  "should consider themselves lucky to get any "
  "programs at all and take what they get."



Tue, 01 Jan 2002 03:00:00 GMT  
 dialog based app making modeless dialogs
1. Add a datamember to the moddless dialogs that contains the handle to the
main dialog window

HWND m_hwndMain;

Then you have to overirde the on Destroy function and clall the SetFocus
function with the Mainwindow handle as Param.

void CModdlessDlg::OnDestroy()
{
    CDialog::OnDestroy();
    ::SetFocus( m_hwndMain );

Quote:
}

Normaly this should set the focus back to your main dialog window

Hope this helps, Kurt



Tue, 01 Jan 2002 03:00:00 GMT  
 dialog based app making modeless dialogs
You don't need a special data member. Do
    AfxGetMainWnd()->SetFocus();

in the OnDestroy handler.

Note that there are some hazards in using the desktop as the "main window".
A modeless dialog is a popup window, which means that by definition it WILL
sit on top of (but not be clipped by) its parent. If the parent is the
desktop, then the window will always obscure the desktop, the same way it
obscured your parent. Also, if the window can be hidden behind the parent,
you need a mechanism for bringing it to the top so you can see it. This
should not only include bringing it to the top, but also making sure it is
visible (multimonitor 98/2K systems will make this a new problem to address.
I've seen it happen: a window is dragged to a different monitor with a
different resolution, and parts of the image are lost because it doesn't
recognize the new monitor characteristics).
                                                                joe


Quote:
> 1. Add a datamember to the moddless dialogs that contains the handle to
the
> main dialog window

> HWND m_hwndMain;

> Then you have to overirde the on Destroy function and clall the SetFocus
> function with the Mainwindow handle as Param.

> void CModdlessDlg::OnDestroy()
> {
>     CDialog::OnDestroy();
>     ::SetFocus( m_hwndMain );
> }

> Normaly this should set the focus back to your main dialog window

> Hope this helps, Kurt



Wed, 02 Jan 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Modeless dialog in a dialog-based app

2. Very serious problem making Dialog based MFC app

3. Modeless dialog based MFC app?

4. Overlapping dialog app and modeless dialog

5. dialog within dialog based apps

6. Showing taskbar visible dialog from dialog based app

7. 2nd Dialog never appears in Dialog based app

8. Dialog-based app and modal dialog

9. HOWTO: hide dialog when a dialog-based app starts

10. PBM: Message box not displayed after main dialog box is closed in MFC dialog-based app

11. Dialog-Based App and Main Dialog Problem

12. Destroy Dialog for Dialog based app

 

 
Powered by phpBB® Forum Software