Ejemplo n.º 1
0
 public static extern IntPtr SendMessage(IntPtr hWnd, WindowsMessages windowsMessage, SysCommands sysCommand, IntPtr lParam);
Ejemplo n.º 2
0
 public static extern bool EnableMenuItem(IntPtr hMenu, SysCommands uIDEnableItem, MenuFlags uEnable);
Ejemplo n.º 3
0
        private void MouseEvent(IntPtr window, WINDOWINFO windowinfo, HitTestValues hitTest, WM message, WM ncMessage, IntPtr clientCursorPos, IntPtr screenCursorPos)
        {
            if (message == WM.LBUTTONDOWN || message == WM.MBUTTONDOWN || message == WM.RBUTTONDOWN)
            {
                var topParent = GetAncestor(window, GetAncestorFlags.GetRoot);

                if (topParent != _lastWindow)
                {
                    IntPtr        result;
                    MouseActivate mouseActivateResult;
                    if (
                        SendMessageTimeout(window, (uint)WM.MOUSEACTIVATE, topParent,
                                           MAKELPARAM((int)hitTest, (int)message),
                                           SendMessageTimeoutFlags.SMTO_ABORTIFHUNG | SendMessageTimeoutFlags.SMTO_NORMAL, 100,
                                           out result) != IntPtr.Zero &&
                        (((mouseActivateResult = (MouseActivate)result) == MouseActivate.MA_ACTIVATEANDEAT) ||
                         mouseActivateResult == MouseActivate.MA_NOACTIVATEANDEAT))
                    {
                        return;
                    }

                    NativeMethods.SetWindowPos(topParent, new IntPtr(HWND_TOPMOST), 0, 0, 0, 0,
                                               SetWindowPosFlags.IgnoreMove | SetWindowPosFlags.IgnoreResize | SetWindowPosFlags.ShowWindow);
                    _lastWindow = topParent;
                }
            }

            NativeMethods.PostMessage(new HandleRef(null, window), WM.SETCURSOR, window,
                                      MAKELPARAM((int)hitTest, (int)message));

            if (hitTest == HitTestValues.HTCLIENT)
            {
                NativeMethods.PostMessage(new HandleRef(null, window), message, (IntPtr)MK_LBUTTON, clientCursorPos);
                return;
            }

            SysCommands command = 0;

            switch (hitTest)
            {
            case HitTestValues.HTSYSMENU:
                if (ncMessage == WM.NCLBUTTONDBLCLK)
                {
                    command = SysCommands.SC_CLOSE;
                }
                else if (ncMessage == WM.NCRBUTTONUP || ncMessage == WM.NCLBUTTONDOWN)
                {
                    command = (SysCommands)0xFFFF;
                }
                break;

            case HitTestValues.HTMINBUTTON:
                if (ncMessage == WM.NCLBUTTONUP)
                {
                    if (((WindowStyles)windowinfo.dwStyle & WindowStyles.WS_MINIMIZEBOX) != 0)
                    {
                        command = SysCommands.SC_MINIMIZE;
                    }
                }
                else if (ncMessage == WM.NCRBUTTONUP)
                {
                    command = (SysCommands)0xFFFF;
                }
                break;

            case HitTestValues.HTMAXBUTTON:
                if (ncMessage == WM.NCLBUTTONUP)
                {
                    if (((WindowStyles)windowinfo.dwStyle & WindowStyles.WS_MAXIMIZEBOX) != 0)
                    {
                        command = ((WindowStyles)windowinfo.dwStyle & WindowStyles.WS_MAXIMIZE) == 0
                                ? SysCommands.SC_MAXIMIZE
                                : SysCommands.SC_RESTORE;
                    }
                }
                else if (ncMessage == WM.NCRBUTTONUP)
                {
                    command = (SysCommands)0xFFFF;
                }
                break;

            case HitTestValues.HTCLOSE:
                if (ncMessage == WM.NCLBUTTONUP)
                {
                    command = SysCommands.SC_CLOSE;
                }
                else if (ncMessage == WM.NCRBUTTONUP)
                {
                    command = (SysCommands)0xFFFF;
                }
                break;

            case HitTestValues.HTHELP:
                if (ncMessage == WM.NCLBUTTONUP)
                {
                    command = SysCommands.SC_CONTEXTHELP;
                }
                else if (ncMessage == WM.NCRBUTTONUP)
                {
                    command = (SysCommands)0xFFFF;
                }
                break;

            case HitTestValues.HTMENU:
                if (ncMessage == WM.NCLBUTTONDOWN)
                {
                    NativeMethods.PostMessage(new HandleRef(null, window), (WM)VncMessage, (IntPtr)VMW_EXECUTE_MENU, IntPtr.Zero);
                }
                else if (ncMessage == WM.NCMOUSEMOVE)
                {
                    NativeMethods.PostMessage(new HandleRef(null, window), (WM)VncMessage, (IntPtr)VMW_HILITE_MENU, IntPtr.Zero);
                }
                break;

            case HitTestValues.HTCAPTION:
                if (ncMessage == WM.NCLBUTTONDBLCLK)
                {
                    NativeMethods.PostMessage(new HandleRef(null, window), ncMessage, (IntPtr)hitTest, clientCursorPos);
                }
                else if (ncMessage == WM.NCRBUTTONUP)
                {
                    command = (SysCommands)0xFFFF;
                }
                break;

            default:
                NativeMethods.PostMessage(new HandleRef(null, window),
                                          message,
                                          (IntPtr)MK_LBUTTON, clientCursorPos);
                NativeMethods.PostMessage(new HandleRef(null, window), ncMessage, (IntPtr)hitTest, screenCursorPos);
                break;
            }

            if (command != 0)
            {
                if (command == (SysCommands)0xFFFF)
                {
                    NativeMethods.PostMessage(new HandleRef(null, window), WM.CONTEXTMENU, (IntPtr)command, clientCursorPos);
                }
                else
                {
                    NativeMethods.PostMessage(new HandleRef(null, window), WM.SYSCOMMAND, (IntPtr)command, clientCursorPos);
                }
            }
        }