/// <include file='doc\ToolTip.uex' path='docs/doc[@for="ToolTip.GetWindowFromPoint"]/*' /> /// <devdoc> /// Returns the HWND of the window that is at the specified point. This /// handles special cases where one Control owns multiple HWNDs (i.e. ComboBox). /// </devdoc> /// <internalonly/> private IntPtr GetWindowFromPoint(Point screenCoords, ref bool success) { Control baseVar = TopLevelControl; IntPtr baseHwnd = IntPtr.Zero; if (baseVar != null) { baseHwnd = baseVar.Handle; } IntPtr hwnd = IntPtr.Zero; bool finalMatch = false; while (!finalMatch) { Point pt = screenCoords; if (baseVar != null) { pt = baseVar.PointToClientInternal(screenCoords); } IntPtr found = UnsafeNativeMethods.ChildWindowFromPointEx(new HandleRef(null, baseHwnd), pt.X, pt.Y, NativeMethods.CWP_SKIPINVISIBLE); if (found == baseHwnd) { hwnd = found; finalMatch = true; } else if (found == IntPtr.Zero) { finalMatch = true; } else { baseVar = Control.FromHandleInternal(found); if (baseVar == null) { baseVar = Control.FromChildHandleInternal(found); if (baseVar != null) { hwnd = baseVar.Handle; } finalMatch = true; } else { baseHwnd = baseVar.Handle; } } } if (hwnd != IntPtr.Zero) { Control ctl = Control.FromHandleInternal(hwnd); if (ctl != null) { Control current = ctl; while (current != null && current.Visible) { current = current.ParentInternal; } if (current != null) { hwnd = IntPtr.Zero; } success = true; } } return(hwnd); }