VC中判断指定窗口是否被其他窗口遮挡

    本来是想判断当前窗口是否在最前面,无奈办法用尽就是不行,于是想换个思路:判断指定窗口是否被其他窗口遮挡。然后掘网三尺,找到了这个:

bool CTestTray2Dlg::IsCoveredByOtherWindow(HWND hWnd)
{
 RECT rcTarget;
 ::GetWindowRect(hWnd, &rcTarget);

 bool isChild = (WS_CHILD == (::GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD));

 if (::GetDesktopWindow() == hWnd)
  hWnd = ::GetWindow(::GetTopWindow(hWnd), GW_HWNDLAST);

 do{
  HWND hCurWnd = hWnd;

  while(NULL != (hWnd = ::GetNextWindow(hWnd, GW_HWNDPREV))){
   if (::IsWindowVisible(hWnd)){
    RECT rcWnd;
    ::GetWindowRect(hWnd, &rcWnd);

    if(!((rcWnd.right < rcTarget.left) || (rcWnd.left > rcTarget.right) ||
     (rcWnd.bottom < rcTarget.top) || (rcWnd.top > rcTarget.bottom))){
     return true;
    }
   }
  }

  if(isChild){
   hWnd = ::GetParent(hCurWnd);
   isChild = hWnd ? (WS_CHILD == (::GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD)) : false;
  }
  else
   break;
 }while(true);

 return false;
}

    大意是自底向上层层遍历窗口,检查是否有窗口与指定窗口有重叠的地方。

    试了下,还行。勉强解决了一问题,感谢网友:Pear(crabshai)

    还有他的好贴:http://topic.csdn.net/u/20081007/23/4c84494d-6caa-4eb2-a2c4-2f73c67e8a63.html

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值