Пример #1
0
        public static bool GetParentWindowHandle(this Visual element, out IntPtr hwnd)
        {
            hwnd = IntPtr.Zero;
            HwndSource wpfHandle = PresentationSource.FromVisual(element) as HwndSource;

            if (wpfHandle == null)
            {
                return(false);
            }

            hwnd = Win32Helper.GetParent(wpfHandle.Handle);
            if (hwnd == IntPtr.Zero)
            {
                hwnd = wpfHandle.Handle;
            }
            return(true);
        }
Пример #2
0
        public static void SetParentToMainWindowOf(this Window window, Visual element)
        {
            var wndParent = Window.GetWindow(element);

            if (wndParent != null)
            {
                window.Owner = wndParent;
            }
            else
            {
                IntPtr parentHwnd;
                if (GetParentWindowHandle(element, out parentHwnd))
                {
                    Win32Helper.SetOwner(new WindowInteropHelper(window).Handle, parentHwnd);
                }
            }
        }
Пример #3
0
 public static void SetOwner(IntPtr childHandle, IntPtr ownerHandle)
 {
     Win32Helper.SetWindowLong(childHandle, -8, ownerHandle.ToInt32());
 }
Пример #4
0
 internal static Win32Helper.RECT GetWindowRect(IntPtr hWnd)
 {
     Win32Helper.RECT rECT = new Win32Helper.RECT();
     Win32Helper.GetWindowRect(hWnd, out rECT);
     return(rECT);
 }
Пример #5
0
 public static IntPtr GetOwner(IntPtr childHandle)
 {
     return(new IntPtr(Win32Helper.GetWindowLong(childHandle, -8)));
 }
Пример #6
0
 internal static Point GetMousePosition()
 {
     Win32Helper.Win32Point win32Point = new Win32Helper.Win32Point();
     Win32Helper.GetCursorPos(ref win32Point);
     return(new Point((double)win32Point.X, (double)win32Point.Y));
 }