views:

1066

answers:

2

This question is related to my previous one.

I have an MFC (VC6) MDI Application which has several MDI child windows acting as different views for one document.

Is it possible to set one of those frames to stay on top of the others?
I have tried to call

SetWindowPos(
   &GetParentFrame()->wndTopMost,
   0, 0, 0, 0,
   SWP_NOMOVE | SWP_NOSIZE);

and

ModifyStyleEx(0, WS_EX_TOPMOST);

from the CMDIChildWnd but neither appears to work.

+1  A: 

In your CMDIChildWnd class (usually CChildFrame), add a static HWND m_hTopWnd. Set it equal to the HWND of the child you want to be always on top.

Handle WM_WINDOWPOSCHANGED in CChildFrame. In the handler, check if the current m_hWnd == m_hTopWnd. If not, call

::SetWindowPos(m_hTopWnd, HWND_TOP, 0, 0, 0, 0, 
    SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);

This way whenever the position of any MDI child window is set, the "always on top" window will be pushed back to the top.

Also handle WM_CLOSE and when the top window is closing, set m_hTopWnd = NULL.

See also: CodeProject article and MSDN knowledgebase

Aidan Ryan
+1  A: 

Are you sure it's good UI design to keep a child window on top of the others? Shouldn't this become a separate topmost frame? Or a control bar?

Serge - appTranslator
I'm quite sure that it is *not* good UI design but that argument was not convincing to The Decision Maker...
mxp