How to make an MDI child window stay on top of its siblings?

回眸只為那壹抹淺笑 提交于 2019-12-02 02:51:19

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

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?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!