Beispiel #1
0
        IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (msg == Win32.WM_MOUSEACTIVATE)
            {
                handled = true;
                return(new IntPtr(Win32.MA_NOACTIVATE));
            }
            else if (msg == Win32.WM_ACTIVATE)
            {
                SetZOrder();
            }
            else if (msg == Win32.WM_GETMINMAXINFO)
            {
                unsafe {
                    MINMAXINFO *minMaxInfo = (MINMAXINFO *)lParam;
                    minMaxInfo->ptMinTrackSize = new POINT()
                    {
                        X = 0, Y = 0
                    };
                }

                // A safe inefficient version for the unsafe block above

                //var minMaxInfo = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof (MINMAXINFO));
                //minMaxInfo.ptMinTrackSize = new POINT();
                //Marshal.StructureToPtr(minMaxInfo, lParam, true);
            }
            else if (msg == Win32.WM_WINDOWPOSCHANGED)
            {
                UpdatePosition();
            }

            return(IntPtr.Zero);
        }
Beispiel #2
0
        private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (msg == Win32.WM_ACTIVATE)
            {
                if (Owned)
                {
                    m_hwndAdornerGroup.ActivateInGroupLimits(this);
                }
            }

            else if (msg == Win32.WM_GETMINMAXINFO)
            {
                unsafe
                {
                    MINMAXINFO *minMaxInfo = (MINMAXINFO *)lParam;
                    minMaxInfo->ptMinTrackSize = new POINT()
                    {
                        X = 0, Y = 0
                    };
                }

                // A safe inefficient version for the unsafe block above

                //var minMaxInfo = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof (MINMAXINFO));
                //minMaxInfo.ptMinTrackSize = new POINT();
                //Marshal.StructureToPtr(minMaxInfo, lParam, true);
            }

            return(IntPtr.Zero);
        }
Beispiel #3
0
        protected override void WndProc(ref Message m)
        {
            bool handled = false;

            if (m.MessageId == WindowMessages.WM_CLOSE)
            {
                Close();
            }
            else if (m.MessageId == WindowMessages.WM_DESTROY)
            {
                OnFormClosed(EventArgs.Empty);
            }
            else if (m.MessageId == WindowMessages.WM_GETMINMAXINFO)
            {
                unsafe
                {
                    MINMAXINFO *sizeInfo = (MINMAXINFO *)m.LParam;
                    sizeInfo->ptMinTrackSize = new Point(MinimumSize.width, MinimumSize.height);
                    sizeInfo->ptMaxTrackSize = new Point(MaximumSize.width, MaximumSize.height);
                }

                handled = true;
            }

            if (!handled)
            {
                base.WndProc(ref m);
            }
        }
Beispiel #4
0
        private unsafe bool HandleMinMaxSizes(IntPtr lParam)
        {
            bool isHandled = false;

            MINMAXINFO *mmi = (MINMAXINFO *)lParam;

            if (!_options.MinimumSize.IsEmpty)
            {
                mmi->ptMinTrackSize.X = _options.MinimumSize.Width;
                mmi->ptMinTrackSize.Y = _options.MinimumSize.Height;
                isHandled             = true;
            }

            if (!_options.MaximumSize.IsEmpty)
            {
                mmi->ptMaxTrackSize.X = _options.MaximumSize.Width;
                mmi->ptMaxTrackSize.Y = _options.MaximumSize.Height;
                isHandled             = true;
            }

            // https://stackoverflow.com/questions/39816031/maximize-window-maintaining-taskbar-limits
            if (_options.WindowFrameless && _options.WindowState == WindowState.Maximize)
            {
                IntPtr handle = MonitorFromWindow(GetDesktopWindow(), MONITOR.DEFAULTTONEAREST);

                MONITORINFOEXW monInfo = new MONITORINFOEXW(null);
                monInfo.cbSize = (uint)Marshal.SizeOf(monInfo);

                var captionHeight = GetSystemMetrics(SystemMetric.SM_CYCAPTION);

                GetMonitorInfoW(handle, ref monInfo);
                var workArea    = monInfo.rcWork;
                var monitorArea = monInfo.rcMonitor;
                mmi->ptMaxPosition.X = Math.Abs(workArea.left - monitorArea.left) - captionHeight / 2;
                mmi->ptMaxPosition.Y = Math.Abs(workArea.top - monitorArea.top);
                mmi->ptMaxSize.X     = Math.Abs(workArea.right - workArea.left) + captionHeight;
                mmi->ptMaxSize.Y     = Math.Abs(workArea.bottom - workArea.top) + captionHeight;

                isHandled = true;
            }

            return(isHandled);
        }
Beispiel #5
0
        private unsafe bool HandleMinMaxSizes(IntPtr lParam)
        {
            bool isHandled = false;

            MINMAXINFO *mmi = (MINMAXINFO *)lParam;

            if (!_options.MinimumSize.IsEmpty)
            {
                mmi->ptMinTrackSize.X = _options.MinimumSize.Width;
                mmi->ptMinTrackSize.Y = _options.MinimumSize.Height;
                isHandled             = true;
            }

            if (!_options.MaximumSize.IsEmpty)
            {
                mmi->ptMaxTrackSize.X = _options.MaximumSize.Width;
                mmi->ptMaxTrackSize.Y = _options.MaximumSize.Height;
                isHandled             = true;
            }

            return(isHandled);
        }
Beispiel #6
0
        private IntPtr ProcessWindowsMessage(IntPtr hWnd, WindowsMessages message, IntPtr wParam, IntPtr lParam)
        {
            switch ((WindowsMessages)message)
            {
            case WindowsMessages.CREATE:
                this.handle = hWnd;
                Created?.Invoke();
                break;

            case WindowsMessages.DESTROY:
                Destroyed?.Invoke();
                PostQuitMessage(0);
                break;

            case WindowsMessages.PAINT:
                break;

            case WindowsMessages.SIZE:
                Resized?.Invoke(new Vector2((float)(((uint)lParam) & 0xffff), (float)(((uint)lParam) >> 16)));
                break;

            case WindowsMessages.UNICHAR:
                DispatchCharEvent(CharEventType.Unicode, (char)wParam);
                break;

            case WindowsMessages.CHAR:
                char @char = (char)wParam;
                if (0 <= @char && @char < 0x80)
                {
                    Debug.Assert(charQueue.Count == 0);
                    DispatchCharEvent(CharEventType.Char, @char);
                }
                else
                {
                    charQueue.Add(@char);
                    if (charQueue.Count == 2)
                    {
                        Encoding encoding = Encoding.GetEncoding("GB2312");
                        var      @string  = encoding.GetString(new byte[] { (byte)charQueue[0], (byte)charQueue[1] });
                        Debug.Assert(@string.Length == 1);
                        charQueue.Clear();
                        DispatchCharEvent(CharEventType.Char, @string[0]);
                    }
                }
                break;

            case WindowsMessages.KEYDOWN:
            case WindowsMessages.SYSKEYDOWN:
            case WindowsMessages.KEYUP:
            case WindowsMessages.SYSKEYUP:
                var         keyboardEventType = ((uint)message & 1) == 0 ? KeyboardEventType.KeyDown : KeyboardEventType.KeyUp;
                VirtualKeys virtualKeys       = (VirtualKeys)wParam;
                bool        extended          = ((ulong)lParam & 0x01000000) != 0;
                switch (virtualKeys)
                {
                case VirtualKeys.Shift:
                    ulong scancode = ((ulong)lParam & 0x00ff0000) >> 16;
                    virtualKeys = (VirtualKeys)MapVirtualKey((uint)scancode, MapVirtualKeyMapTypes.MAPVK_VSC_TO_VK_EX);
                    break;

                case VirtualKeys.Control:
                    virtualKeys = extended ? VirtualKeys.RightControl : VirtualKeys.LeftControl;
                    break;

                case VirtualKeys.Menu:
                    virtualKeys = extended ? VirtualKeys.RightMenu : VirtualKeys.LeftMenu;
                    break;
                }
                this.DispatchKeyboradEvent(keyboardEventType, virtualKeys);
                break;

            case WindowsMessages.LBUTTONDOWN:
                this.DispatchMouseEvent(MouseEventType.MouseDown, VirtualKeys.LeftButton);
                break;

            case WindowsMessages.RBUTTONDOWN:
                this.DispatchMouseEvent(MouseEventType.MouseDown, VirtualKeys.RightButton);
                break;

            case WindowsMessages.MBUTTONDOWN:
                this.DispatchMouseEvent(MouseEventType.MouseDown, VirtualKeys.MiddleButton);
                break;

            case WindowsMessages.LBUTTONUP:
                this.DispatchMouseEvent(MouseEventType.MouseUp, VirtualKeys.LeftButton);
                break;

            case WindowsMessages.RBUTTONUP:
                this.DispatchMouseEvent(MouseEventType.MouseUp, VirtualKeys.RightButton);
                break;

            case WindowsMessages.MBUTTONUP:
                this.DispatchMouseEvent(MouseEventType.MouseUp, VirtualKeys.MiddleButton);
                break;

            case WindowsMessages.GETMINMAXINFO:
                unsafe
                {
                    MINMAXINFO *mminfo = (MINMAXINFO *)(lParam.ToPointer());
                    mminfo->ptMinTrackSize.X = 640;
                    mminfo->ptMinTrackSize.Y = 480;
                }
                break;
            }
            return(DefWindowProc(hWnd, (WindowsMessages)message, wParam, lParam));
        }