Ejemplo n.º 1
0
 private static IntPtr FindTopLevelWindow(IntPtr hWnd)
 {
     while (hWnd != IntPtr.Zero && ScreenLocation.IsChildWindow(hWnd))
     {
         hWnd = NativeMethods.GetParent(hWnd);
     }
     return(hWnd);
 }
Ejemplo n.º 2
0
        public static HwndSource FindTopLevelHwndSource(UIElement element)
        {
            HwndSource hwndSource = (HwndSource)PresentationSource.FromVisual((Visual)element);

            if (hwndSource != null && ScreenLocation.IsChildWindow(hwndSource.Handle))
            {
                hwndSource = HwndSource.FromHwnd(ScreenLocation.FindTopLevelWindow(hwndSource.Handle));
            }
            return(hwndSource);
        }