如何在窗口的WM_WINDOWPOSCHANGED消息响应函数里面知道该窗口跳到顶端去了

悟迟 2011-12-06 06:09:16
如何在窗口的WM_WINDOWPOSCHANGED消息响应函数里面知道该窗口跳到顶端去了

一个对话框被另一个程序调BringWindowToTop函数跳到最顶端,
或者被鼠标键盘等操作点到顶端
如何让它跳出来时做点事情
...全文
659 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wozhaosummer 2011-12-07
  • 打赏
  • 举报
回复
通过观察发现,鼠标点出该窗口,键盘切换出,BringWindowToTop掉出该窗口
void OnWindowPosChanged(WINDOWPOS* lpwndpos)里面可以这样写,
BOOL bSWP_DRAWFRAME = ((lpwndpos->flags & SWP_DRAWFRAME ) == SWP_DRAWFRAME );
BOOL bSWP_FRAMECHANGED = ((lpwndpos->flags & SWP_FRAMECHANGED ) == SWP_FRAMECHANGED );
BOOL bSWP_HIDEWINDOW = ((lpwndpos->flags & SWP_HIDEWINDOW ) == SWP_HIDEWINDOW );
BOOL bSWP_NOACTIVATE = ((lpwndpos->flags & SWP_NOACTIVATE ) == SWP_NOACTIVATE );
BOOL bSWP_NOCOPYBITS = ((lpwndpos->flags & SWP_NOCOPYBITS ) == SWP_NOCOPYBITS );
BOOL bSWP_NOMOVE = ((lpwndpos->flags & SWP_NOMOVE ) == SWP_NOMOVE );
BOOL bSWP_NOOWNERZORDER = ((lpwndpos->flags & SWP_NOOWNERZORDER ) == SWP_NOOWNERZORDER );
BOOL bSWP_NOREDRAW = ((lpwndpos->flags & SWP_NOREDRAW ) == SWP_NOREDRAW );
BOOL bSWP_NOREPOSITION = ((lpwndpos->flags & SWP_NOREPOSITION ) == SWP_NOREPOSITION );
BOOL bSWP_NOSENDCHANGING = ((lpwndpos->flags & SWP_NOSENDCHANGING) == SWP_NOSENDCHANGING);
BOOL bSWP_NOSIZE = ((lpwndpos->flags & SWP_NOSIZE ) == SWP_NOSIZE );
BOOL bSWP_NOZORDER = ((lpwndpos->flags & SWP_NOZORDER ) == SWP_NOZORDER );
BOOL bSWP_SHOWWINDOW = ((lpwndpos->flags & SWP_SHOWWINDOW ) == SWP_SHOWWINDOW );
BOOL bTop = (
bSWP_DRAWFRAME == FALSE &&
bSWP_FRAMECHANGED == FALSE &&
bSWP_HIDEWINDOW == FALSE &&
bSWP_NOACTIVATE == FALSE &&
bSWP_NOCOPYBITS == FALSE &&
bSWP_NOMOVE == TRUE &&
bSWP_NOOWNERZORDER == FALSE &&
bSWP_NOREDRAW == FALSE &&
bSWP_NOREPOSITION == FALSE &&
bSWP_NOSENDCHANGING == FALSE &&
bSWP_NOSIZE == TRUE &&
bSWP_NOZORDER == FALSE &&
bSWP_SHOWWINDOW == FALSE);
if (bTop == TRUE)
{
// 感觉这个方法有些不是很优美,不知道有没有啥缺陷或者更好的方法
}
悟迟 2011-12-07
  • 打赏
  • 举报
回复
补充,在该函数中,除了窗口跳出来需要做些事情,其它动作不需要相应
  • 打赏
  • 举报
回复
HWND desWnd = ::GetDesktopWindow();
HWND topWnd = ::GetTopWindow(desWnd);
if(topWnd == this->m_hWnd)
{
//说明自己在顶层
}
yuucyf 2011-12-06
  • 打赏
  • 举报
回复
在OnWindowPosChanged应该这样就可以吧?
if (!(lpwndpos->flags & SWP_NOACTIVATE))
{
}

SWP_NOACTIVATE Does not activate the window. If this flag is not set, the window is activated and moved to the top of either the topmost or non-topmost group (depending on the setting of the hWndInsertAfter parameter).

hwndInsertAfter
Specifies the position of the window in Z order (front-to-back position). This member can be a handle to the window behind which this window is placed, or can be one of the special values listed with the SetWindowPos function.
Eleven 2011-12-06
  • 打赏
  • 举报
回复
GetForegroundWindow() ??
枚举窗口EnumWindows()得到第一个窗口判断是否和你指定的窗口HWND相等?

16,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧