Esempio n. 1
0
        private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (msg == (int)WM.SHOWWINDOW)
            {
                if ((int)lParam == 3 && this.Visibility != Visibility.Visible) // 3 == SW_PARENTOPENING
                {
                    handled = true;                                            //handle this message so window isn't shown until we want it to
                }
            }
            if (msg == (int)WM.MOUSEACTIVATE)
            {
                handled = true;
                return(new IntPtr(3));
            }

            if (msg == (int)WM.LBUTTONDOWN)
            {
                var pt = new Point((int)lParam & 0xFFFF, ((int)lParam >> 16) & 0xFFFF);
                NativeMethods.PostMessage(ownerHandle, (uint)WM.NCLBUTTONDOWN, (IntPtr)getHitTestValue(pt), IntPtr.Zero);
            }
            if (msg == (int)WM.NCHITTEST)
            {
                var    ptScreen = new Point((int)lParam & 0xFFFF, ((int)lParam >> 16) & 0xFFFF);
                Point  ptClient = PointFromScreen(ptScreen);
                Cursor cursor   = getCursor(ptClient);
                if (cursor != Cursor)
                {
                    Cursor = cursor;
                }
            }

            return(IntPtr.Zero);
        }
Esempio n. 2
0
        private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            RECT rect;

            switch ((WM)msg)
            {
            case WM.SHOWWINDOW:
                if ((int)lParam == 3 && this.Visibility != Visibility.Visible) // 3 == SW_PARENTOPENING
                {
                    handled = true;                                            //handle this message so window isn't shown until we want it to
                }
                break;

            case WM.MOUSEACTIVATE:
                handled = true;
                if (this.ownerHandle != IntPtr.Zero)
                {
                    Standard.NativeMethods.SendMessage(this.ownerHandle, Standard.WM.ACTIVATE, wParam, lParam);
                }
                return(new IntPtr(3));

            case WM.LBUTTONDOWN:
                if (this.ownerHandle != IntPtr.Zero && UnsafeNativeMethods.GetWindowRect(this.ownerHandle, out rect))
                {
                    Point pt;
                    if (WinApiHelper.TryGetRelativeMousePosition(this.handle, out pt))
                    {
                        NativeMethods.PostMessage(this.ownerHandle, (uint)WM.NCLBUTTONDOWN, (IntPtr)this.getHitTestValue(pt, rect), IntPtr.Zero);
                    }
                }
                break;

            case WM.NCHITTEST:
                Cursor cursor = null;
                if (this._owner.ResizeMode == ResizeMode.NoResize || this._owner.ResizeMode == ResizeMode.CanMinimize)
                {
                    cursor = this._owner.Cursor;
                }
                else
                {
                    if (this.ownerHandle != IntPtr.Zero && UnsafeNativeMethods.GetWindowRect(this.ownerHandle, out rect))
                    {
                        Point pt;
                        if (WinApiHelper.TryGetRelativeMousePosition(this.handle, out pt))
                        {
                            cursor = this.getCursor(pt, rect);
                        }
                    }
                }
                if (cursor != null && cursor != this.Cursor)
                {
                    this.Cursor = cursor;
                }
                break;
            }
            return(IntPtr.Zero);
        }