如何使MDI子窗口停留在其兄弟姐妹之上? [英] How to make an MDI child window stay on top of its siblings?

查看:165
本文介绍了如何使MDI子窗口停留在其兄弟姐妹之上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题与我的上一个状态有关一个.

我有一个MFC(VC6)MDI应用程序,该应用程序具有多个MDI子窗口,它们充当一个文档的不同视图.

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);

ModifyStyleEx(0, WS_EX_TOPMOST);

来自CMDIChildWnd,但似乎都不起作用.

from the CMDIChildWnd but neither appears to work.

推荐答案

在您的CMDIChildWnd类(通常为CChildFrame)中,添加一个静态HWND m_hTopWnd.将其设置为等于您希望始终位于顶部的孩子的HWND.

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.

处理CChildFrame中的WM_WINDOWPOSCHANGED.在处理程序中,检查当前的m_hWnd == m_hTopWnd.如果没有,请致电

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);

这样,无论何时设置任何MDI子窗口的位置,总是在顶部"窗口都将被推回顶部.

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

也处理WM_CLOSE,并且在关闭顶部窗口时,将m_hTopWnd = NULL设置.

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

另请参见: CodeProject文章 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆