CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2005
    Posts
    41

    Making a dialog box appear above another

    Hi

    I have a problem with dialog boxes I was hoping someone could help me with:

    I have a dialog based project where I am creating another window from the main dialog OnInitDialog function:

    BOOL CFCMDlg::OnInitDialog()
    {
    ...........
    m_canvas.Create(IDD_CANVAS, this);
    m_canvas.ShowWindow(SW_SHOWNORMAL);
    ...........
    }

    The problem is that I want the main dialog window (CFCMDlg) to always be on top of the new window (CCanvas). Even if I select the main dialog window (CFCMDlg) it always appears behind the new window (CCanvas).

    Is there something I can add / modify which will make the CCanvas dialog box always appear behind the CFCMDlg dialog box regardless of what is currently selected?

    Thanks,

    Robbie

  2. #2
    Join Date
    May 2006
    Location
    Norway
    Posts
    1,709

    Re: Making a dialog box appear above another

    Hi

    Try to set the CFCMDlgs Topmost property to true. That ensures that your dialog will take z-order precedence over all non-topmost windows.

    Hope this helps!

    Thx

  3. #3
    Join Date
    Apr 2005
    Posts
    41

    Re: Making a dialog box appear above another

    Hi

    Thanks for the very quick reply.

    I couldn't find the "topmost" property however I selected the "Set Foreground" option for the main dialog box. Is the topmost property on the properties sheet for the dialog box?

    When I do this the main dialog box does indeed have the focus however the second window (CCanvas) still appears above.

    Have you got any more ideas I could try in order to ensure the main dialog window (CFCMDlg) appears above the second window (CCanvas)?

    Thanks

  4. #4
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Making a dialog box appear above another

    Code:
    BOOL CFCMDlg::OnInitDialog()
    {
    // ...
       m_canvas.Create(IDD_CANVAS, this);
    // ...
    }
    ...creates a modeless dialog owned by CFCMDlg. The main behavior of an owned window is that it is always in the top of its owner. So setting "top-most" for CFCMDlg (you can do that by a call of SetWindowPos) is useless. i.e. its owned window(s) will remain in front of it.
    If you want the new created window to stay always behind, then you have to change owner - owned relationship.
    Like in next example:
    Code:
    BOOL CFCMDlg::OnInitDialog()
    {
    // ...  
       m_canvas.Create(IDD_CANVAS, CWnd::GetDesktopWindow()); // owned by desktop window
       // change owner - owned relationship
       SetWindowLong(m_hWnd, GWL_HWNDPARENT, (LONG)m_canvas.m_hWnd);
       SetOwner(&m_canvas);
       m_canvas.ShowWindow(SW_SHOWNORMAL);
       
       return TRUE;
    }
    Last edited by ovidiucucu; October 15th, 2006 at 09:38 AM.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  5. #5
    Join Date
    Apr 2005
    Posts
    41

    Re: Making a dialog box appear above another

    Hi

    Thank you very much for showing me what to do. It works great now - cheers!

    Robbie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured