Link to home
Start Free TrialLog in
Avatar of Gumpster
Gumpster

asked on

Child Window Z-Order problem..

I have a CWnd top-level window and several CWnd derived child windows inside it.

How do I fix the Z-order of these child windows, even when the windows is clicked apon?
ASKER CERTIFIED SOLUTION
Avatar of elf_k
elf_k

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
Avatar of Gumpster
Gumpster

ASKER

The toplevel window will contain a series of child windows; each child window will contain some graphics on its own separate layer(like adobe photoshop).  Each window will have to be fixed in the z-order chain, even when the window is clicked apon and activated.  I want to be able to move/size each child window without bringing that window to the front.
Aha! When you want to avoid changing windows Z-Order you can catch WM_WINDOWPOSCHANGING message and "or" flags field of WINDOWPOS struct with SWP_NOZORDER. Your window will not change ZOrder in this case.
I think the solution is to override WM_WINDOWPOSCHANGING:

void CChildFrame::OnWindowPosChanging(WINDOWPOS* lpWinPos)
{
      lpWinPos->flags |= SWP_NOZORDER;
}
I tried this and it did not work.  This is because you can call SetWindowPos with the SWP_NOSENDCHANGING flag and no WM_WINDOWPOSCHANGING message is sent.

Instead I have trapped the WM_WINDOWPOSCHANGED message and added a SetWindowPos call there:

void CChildWindow::OnWindowPosChanged(WINDOWPOS FAR* lpwndpos)
{
      CWnd::OnWindowPosChanged(lpwndpos);
      
      if (m_pInsertAfter!=NULL)
            this->SetWindowPos(m_pInsertAfter, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE);
}

I tried this and it did not work.  This is because you can call SetWindowPos with the SWP_NOSENDCHANGING flag and no WM_WINDOWPOSCHANGING message is sent.

Instead I have trapped the WM_WINDOWPOSCHANGED message and added a SetWindowPos call there:

void CChildWindow::OnWindowPosChanged(WINDOWPOS FAR* lpwndpos)
{
      CWnd::OnWindowPosChanged(lpwndpos);
      
      if (m_pInsertAfter!=NULL)
            this->SetWindowPos(m_pInsertAfter, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE);
}