// Returns true if the message should be dropped. internal static IntPtr SendMessage(ref MSG msg, out bool drop, out bool quit) { drop = false; quit = false; Message m = Message.Create(msg.hwnd, (int)msg.message, msg.wParam, msg.lParam); if (Application.FilterMessage(ref m)) { drop = true; return(IntPtr.Zero); } switch ((Msg)msg.message) { case Msg.WM_KEYDOWN: case Msg.WM_SYSKEYDOWN: case Msg.WM_CHAR: case Msg.WM_SYSCHAR: case Msg.WM_KEYUP: case Msg.WM_SYSKEYUP: Control c = Control.FromHandle(msg.hwnd); // If we have a control with keyboard capture (usually a *Strip) // give it the message, and then drop the message if (keyboard_capture != null) { // WM_SYSKEYUP does not make it into ProcessCmdKey, so do it here if (msg.message == Msg.WM_SYSKEYDOWN) { if (m.WParam.ToInt32() == (int)Keys.Menu) { keyboard_capture.GetTopLevelToolStrip().Dismiss(ToolStripDropDownCloseReason.Keyboard); drop = true; return(IntPtr.Zero); } } m.HWnd = keyboard_capture.Handle; switch (keyboard_capture.PreProcessControlMessageInternal(ref m)) { case PreProcessControlState.MessageProcessed: drop = true; return(IntPtr.Zero); case PreProcessControlState.MessageNeeded: case PreProcessControlState.MessageNotNeeded: if (((msg.message == Msg.WM_KEYDOWN || msg.message == Msg.WM_CHAR) && !keyboard_capture.ProcessControlMnemonic((char)m.WParam))) { if (c == null || !ControlOnToolStrip(c)) { drop = true; return(IntPtr.Zero); } m.HWnd = msg.hwnd; } else { drop = true; return(IntPtr.Zero); } break; } } if (((c != null) && c.PreProcessControlMessageInternal(ref m) != PreProcessControlState.MessageProcessed) || (c == null)) { goto default; } break; case Msg.WM_LBUTTONDOWN: case Msg.WM_MBUTTONDOWN: case Msg.WM_RBUTTONDOWN: if (keyboard_capture != null) { Control c2 = Control.FromHandle(msg.hwnd); // the target is not a winforms control (an embedded control, perhaps), so // release everything if (c2 == null) { ToolStripManager.FireAppClicked(); goto default; } // If we clicked a ToolStrip, we have to make sure it isn't // the one we are on, or any of its parents or children // If we clicked off the dropped down menu, release everything if (c2 is ToolStrip) { if ((c2 as ToolStrip).GetTopLevelToolStrip() != keyboard_capture.GetTopLevelToolStrip()) { ToolStripManager.FireAppClicked(); } } else { Control dropDownParent = c2.Parent; while (dropDownParent != null) { if (dropDownParent is ToolStripDropDown) { if ((dropDownParent as ToolStripDropDown).GetTopLevelToolStrip() == keyboard_capture.GetTopLevelToolStrip()) { goto default; } break; } dropDownParent = dropDownParent.Parent; } if (!Control.IsChild(keyboard_capture.Handle, c2.Handle)) { ToolStripManager.FireAppClickedInternal(); goto default; } if (c2.TopLevelControl == null) { goto default; } ToolStripManager.FireAppClicked(); } } goto default; case Msg.WM_QUIT: quit = true; // make sure we exit break; default: XplatUI.TranslateMessage(ref msg); return(XplatUI.DispatchMessage(ref msg)); } return(IntPtr.Zero); }