得到鼠标指针下面窗口句柄,而忽略的半透明窗口窗口、句柄、鼠标指针、而忽略

由网友(一懒众衫小)分享简介:我已经创建了一个半透明的形式(60%的不透明度与黑色的背景色),我的应用程序启动,最大化,在整个屏幕。基本上,它蒙上了灰色的整个桌面上。I've created a semi-transparent form (60% opacity with black background color) that my app...

我已经创建了一个半透明的形式(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:

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

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

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

I've tried to fix this in two ways:

我想应该有一种方法来获取窗口的hWnd直接下我的形式通过调用的 ChildWindowFromPointEx (假冒的桌面和 CWP_SKIPTRANSPARENT HWND的),但它不不像是会工作。我也打了[ChildWindowFromPoint] [4]和[RealChildWindowFromPoint] [5],但没有成功。 (PS雷蒙德陈将讨论这些调用之间的差异,这里< /一>,这在我看来,ChildWindowFromPointEx是专门做正是我需要的)

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.

呼叫 EnumWindows的()来获取顶级窗口的列表。 从该列表中删除您的半透明窗口。 对于列表中使用的每个窗口 PtInRegion()来确定鼠标是否在窗户上。删除所有不符合该法案的任何窗口。 使用 GetNextWindow(),从剩余的一个窗口开始走Z顺序,并找出哪些考生是在顶部。 Call EnumWindows() to get a list of top-level windows. Remove your semi-transparent window from this list. 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. 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.
阅读全文

相关推荐

最新文章