在鼠标指针下获取窗口句柄,同时忽略半透明窗口
【腾讯云】亏本大甩卖,服务器4核16G 1年370元(带宽12M,系统盘120GB SSD盘,月流量2000GB)!!!!!!
云产品 配置 价格
服务器 1核2G,带宽5M,系统盘50GB SSD盘,月流量500GB 38元/年
MySQL 1核1G 19元/年
服务器 16核32G,带宽18M,系统盘250GB SSD盘,月流量5000GB 1197元/年
点我进入腾讯云,查看更多详情

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.

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. Temporarily hide my form (OR, temporarily set my form's opacity to 0.0)
  2. Call [GetCursorPos][1]
  3. Call [WindowFromPoint][2]
  4. Show my form again

The problem with this approach is that my form / the screen blinks, which I don't like.

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)

  • 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.

Any help would be greatly appreciated.

#0

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

  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.

推荐文章

文本视图页面滚动

文本视图页面滚动

推荐文章

如何避免在查询中多次与同一个表联接?

如何避免在查询中多次与同一个表联接?

推荐文章

Python-从文件行中剥离时间戳和用户名

Python-从文件行中剥离时间戳和用户名

推荐文章

Windows CE使用UTF-16或UCS-2?

Windows CE使用UTF-16或UCS-2?

推荐文章

Asp.Net MVC2部署

Asp.Net MVC2部署

推荐文章

RIA服务和通用存储库模式

RIA服务和通用存储库模式

推荐文章

如何使用Android SyncAdapter?

如何使用Android SyncAdapter?

推荐文章

事件机器::defer+ruby

事件机器::defer+ruby

推荐文章

JComboBox-空项没有ItemEvents

JComboBox-空项没有ItemEvents

推荐文章

.NET C#:是否可以自动导入TLB(半-)并将PreserveSig添加到一种类型?

.NET C#:是否可以自动导入TLB(半-)并将PreserveSig添加到一种类型?

推荐文章

用于在catch中仅加载必需类的GWT延迟绑定

用于在catch中仅加载必需类的GWT延迟绑定

推荐文章

如何防止AppletClassLoader在查找类/其他资源时命中服务器?

如何防止AppletClassLoader在查找类/其他资源时命中服务器?

推荐文章

如何在spring加载应用程序上下文之后执行作业?

如何在spring加载应用程序上下文之后执行作业?

推荐文章

IIS中的默认文档

IIS中的默认文档

推荐文章

Python:向dict列表或关联数组添加元素

Python:向dict列表或关联数组添加元素

推荐文章

如何使用TabbedPane tab changes在NetBeans IDE内置的Applet中显示不同的面板?

如何使用TabbedPane tab changes在NetBeans IDE内置的Applet中显示不同的面板?