コード例 #1
0
 private static IntPtr FindTopLevelWindow(IntPtr hWnd)
 {
     while (hWnd != IntPtr.Zero && ScreenLocation.IsChildWindow(hWnd))
     {
         hWnd = NativeMethods.GetParent(hWnd);
     }
     return(hWnd);
 }
コード例 #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);
        }