protected void UpdateClipRegion(ClipRegionChangeType regionChangeType = ClipRegionChangeType.FromPropertyChange)
        {
            var hwndSource = (HwndSource)PresentationSource.FromVisual(this);

            if (hwndSource == null)
            {
                return;
            }
            RECT lpRect;

            NativeMethods.GetWindowRect(hwndSource.Handle, out lpRect);
            var windowPlacement = NativeMethods.GetWindowPlacement(hwndSource.Handle);

            UpdateClipRegion(hwndSource.Handle, windowPlacement, regionChangeType, lpRect);
        }
        private static RECT GetClientRectRelativeToWindowRect(IntPtr hwnd)
        {
            RECT lpRect1;

            NativeMethods.GetWindowRect(hwnd, out lpRect1);
            RECT lpRect2;

            NativeMethods.GetClientRect(hwnd, out lpRect2);
            var point = new Core.Platform.Point {
                X = 0, Y = 0
            };

            NativeMethods.ClientToScreen(hwnd, ref point);
            lpRect2.Offset(point.X - lpRect1.Left, point.Y - lpRect1.Top);
            return(lpRect2);
        }
        public void UpdateWindowPos()
        {
            var  targetWindowHandle = TargetWindowHandle;
            RECT lpRect;

            NativeMethods.GetWindowRect(targetWindowHandle, out lpRect);
            NativeMethods.GetWindowPlacement(targetWindowHandle);

            if (!IsVisible)
            {
                return;
            }
            switch (_direction)
            {
            case Dock.Left:
                Border.Height = lpRect.Height;
                Left          = lpRect.Left - 9;
                Top           = lpRect.Top - 9;
                Width         = 9;
                Height        = lpRect.Height + 18;
                break;

            case Dock.Top:
                Border.Width = lpRect.Width + 2;
                Left         = lpRect.Left - 9;
                Top          = lpRect.Top - 9;
                Width        = lpRect.Width + 18;
                Height       = 9;
                break;

            case Dock.Right:
                Border.Height = lpRect.Height;
                Left          = lpRect.Right;
                Top           = lpRect.Top - 9;
                Width         = 9;
                Height        = lpRect.Height + 18;
                break;

            default:
                Border.Width = lpRect.Width + 2;
                Left         = lpRect.Left - 9;
                Top          = lpRect.Bottom;
                Width        = lpRect.Width + 18;
                Height       = 9;
                break;
            }
        }
        private Cursor GetCursor(IntPtr lParam)
        {
            var  xlParam = NativeMethods.GetXlParam(lParam.ToInt32());
            var  ylParam = NativeMethods.GetYlParam(lParam.ToInt32());
            RECT lpRect;

            NativeMethods.GetWindowRect(new WindowInteropHelper(this).Handle, out lpRect);

            switch (_direction)
            {
            case Dock.Left:
                if (ylParam - 18 < lpRect.Top)
                {
                    return(Cursors.SizeNWSE);
                }
                return(ylParam + 18 > lpRect.Bottom ? Cursors.SizeNESW : Cursors.SizeWE);

            case Dock.Top:
                if (xlParam - 18 < lpRect.Left)
                {
                    return(Cursors.SizeNWSE);
                }
                return(xlParam + 18 > lpRect.Right ? Cursors.SizeNESW : Cursors.SizeNS);

            case Dock.Right:
                if (ylParam - 18 < lpRect.Top)
                {
                    return(Cursors.SizeNESW);
                }
                return(ylParam + 18 > lpRect.Bottom ? Cursors.SizeNWSE : Cursors.SizeWE);

            default:
                if (xlParam - 18 < lpRect.Left)
                {
                    return(Cursors.SizeNESW);
                }
                return(xlParam + 18 > lpRect.Right ? Cursors.SizeNWSE : Cursors.SizeNS);
            }
        }