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

最后都变了- 提交于 2019-12-02 12:34:41

问题


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:


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




回答2:


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?



来源:https://stackoverflow.com/questions/594375/how-to-make-an-mdi-child-window-stay-on-top-of-its-siblings

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