得到鼠标指针下面窗口句柄,而忽略的半透明窗口 [英] Get window handle underneath mouse pointer, while ignoring a semi-transparent window

查看:158
本文介绍了得到鼠标指针下面窗口句柄,而忽略的半透明窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个半透明的形式(60%的不透明度与黑色的背景色),我的应用程序启动,最大化,在整个屏幕。基本上,它蒙上了灰色的整个桌面上。

I've created a semi-transparent form (60% opacity with black background color) that my app launches, maximized, over the entire screen. Basically, it casts a gray color on the entire desktop.

当用户将鼠标悬停在桌面上的窗口,我想获得该窗口的句柄(HWND)。

When the user mouses-over a window on the desktop, I want to get that window's handle (hWnd).

最简单的方法来做到这一点,这是为我工作,就是:

The easy way to do this, which is working for me, is:

  1. 在暂时隐藏我的表单(OR,临时设置我的窗体的不透明度为0.0)
  2. 在调用[GetCursorPos] [1]
  3. 在调用[WindowFromPoint] [2]
  4. 在此再次显示我的状态

使用这种方法的问题是,我的表/屏幕闪烁,这是我不喜欢的。

我试图解决这个问题有两种方式:

I've tried to fix this in two ways:

  • I figure there should be a way to get the hWnd of the window directly underneath my form by calling ChildWindowFromPointEx (passing-in the hWnd of the desktop and CWP_SKIPTRANSPARENT), but it doesn't seem to work. I also played with [ChildWindowFromPoint][4] and [RealChildWindowFromPoint][5] with no success. (P.S. Raymond Chen discusses the differences between these calls, here and it seems to me that ChildWindowFromPointEx is designed to do exactly what I need)

我试过$ P $用pventing从刷新整个桌面(一种冻结的画面瞬间的)(1)的SendMessage(GetDesktopWindow(),WM_SETREDRAW,假,0) 之前,我躲在自己的状态和(2)的SendMessage(GetDesktopWindow(),WM_SETREDRAW,真实,0)后,我隐藏自己的形式。这不工作很正确:屏幕的某些区域会冻结,一些奇怪的黑块会出现,等我知道,但是,(1)不工作,因为有一次我叫(1)并没有调用(2)和我的桌面出现完全冻结(不得不重新启动,甚至TaskMgr没有提供正确的)。我也尝试过使用SuspendLayout和ResumeLayout在我的形式,但我不认为他们是为了应付我的情况。

I tried preventing the entire desktop from refreshing (kind of "freezing" the screen momentarily) by using (1) SendMessage(GetDesktopWindow(), WM_SETREDRAW, false, 0) before I hide my form and (2) SendMessage(GetDesktopWindow(), WM_SETREDRAW, true, 0) after I hide my form. This didn't work quite right: some areas of the screen would freeze, some weird black blocks would appear, etc. I do know, however, that (1) does work, because one time I called (1) and didn't call (2) and my desktop appeared completely frozen (had to reboot, even TaskMgr didn't render correctly). I also tried using SuspendLayout and ResumeLayout on my form, but I don't think they are meant to handle my case.

任何帮助将是很大的AP preciated。

Any help would be greatly appreciated.

推荐答案

您可以做,因为你需要超越什么标准功能提供自定义检查自己。

You can do the checking yourself since your need to customise beyond that what the standard functions offer.

  1. 呼叫 EnumWindows的()来获取顶级窗口的列表。
  2. 从该列表中删除您的半透明窗口。
  3. 对于列表中使用的每个窗口 PtInRegion()来确定鼠标是否在窗户上。删除所有不符合该法案的任何窗口。
  4. 使用 GetNextWindow(),从剩余的一个窗口开始走Z顺序,并找出哪些考生是在顶部。
  1. Call EnumWindows() to get a list of top-level windows.
  2. Remove your semi-transparent window from this list.
  3. For each window in the list use PtInRegion() to determine whether or not the mouse is over the window. Remove any windows that don't fit the bill.
  4. Use GetNextWindow(), starting from one of the remaining windows to walk the z-order and find out which of the candidates is at the top.

这篇关于得到鼠标指针下面窗口句柄,而忽略的半透明窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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