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:
- Temporarily hide my form (OR, temporarily set my form’s opacity to 0.0)
- Call [GetCursorPos][1]
- Call [WindowFromPoint][2]
- 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.
You can do the checking yourself since your need to customise beyond that what the standard functions offer.
EnumWindows()to get a list of top-level windows.PtInRegion()to determine whether or not the mouse is over the window. Remove any windows that don’t fit the bill.GetNextWindow(), starting from one of the remaining windows to walk the z-order and find out which of the candidates is at the top.