protected override void WndProc(ref Message m) { if (m.Msg == (int)User32.WM.ACTIVATE) { if (Visible && PARAM.LOWORD(m.WParam) == (int)User32.WA.INACTIVE) { if (!OwnsWindow(m.LParam)) { Visible = false; if (m.LParam == IntPtr.Zero) { //we 're switching process, also dismiss the parent Control toplevel = _parentControl.TopLevelControl; if (toplevel is ToolStripDropDown dropDown) { // if it's a toolstrip dropdown let it know that we have a specific close reason. dropDown.Close(); } else if (toplevel != null) { toplevel.Visible = false; } } return; } } } base.WndProc(ref m); }
protected override void WndProc(ref Message m) { if (m.Msg == (int)User32.WM.ACTIVATE) { SetState(States.Modal, true); Debug.WriteLineIf(CompModSwitches.DebugGridView.TraceVerbose, "DropDownHolder:WM_ACTIVATE()"); IntPtr activatedWindow = (IntPtr)m.LParam; if (Visible && PARAM.LOWORD(m.WParam) == (int)User32.WA.INACTIVE && !OwnsWindow(activatedWindow)) { gridView.CloseDropDownInternal(false); return; } } else if (m.Msg == (int)User32.WM.CLOSE) { // don't let an ALT-F4 get you down // if (Visible) { gridView.CloseDropDown(); } return; } else if (m.Msg == (int)User32.WM.DPICHANGED) { // Dropdownholder in PropertyGridView is already scaled based on parent font and other properties that were already set for new DPI // This case is to avoid rescaling(double scaling) of this form m.Result = IntPtr.Zero; return; } base.WndProc(ref m); }
protected override void WndProc(ref Message m) { if (m.MsgInternal == User32.WM.ACTIVATE && Visible && (User32.WA)PARAM.LOWORD(m.WParamInternal) == User32.WA.INACTIVE && !OwnsWindow(m.LParamInternal)) { Visible = false; if (m.LParamInternal == 0) { // We 're switching process, also dismiss the parent. Control toplevel = _parentControl.TopLevelControl; if (toplevel is ToolStripDropDown dropDown) { // If it's a toolstrip dropdown let it know that we have a specific close reason. dropDown.Close(); } else if (toplevel is not null) { toplevel.Visible = false; } } return; } base.WndProc(ref m); }
private static string ToString(IntPtr hWnd, User32.WM msg, nint wparam, nint lparam, nint result) { string id = Parenthesize(MsgToString(msg)); string lDescription = string.Empty; if (msg == User32.WM.PARENTNOTIFY) { lDescription = Parenthesize(MsgToString((User32.WM)PARAM.LOWORD(wparam))); } return($@"msg=0x{(uint)msg:x}{id} hwnd=0x{(long)hWnd:x} wparam=0x{wparam:x} lparam=0x{lparam:x}{lDescription} result=0x{result:x}"); }
public static string ToString(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam, IntPtr result) { string id = Parenthesize(MsgToString(msg)); string lDescription = string.Empty; if (msg == (int)WM.PARENTNOTIFY) { lDescription = Parenthesize(MsgToString(PARAM.LOWORD(wparam))); } return ("msg=0x" + Convert.ToString(msg, 16) + id + " hwnd=0x" + Convert.ToString((long)hWnd, 16) + " wparam=0x" + Convert.ToString((long)wparam, 16) + " lparam=0x" + Convert.ToString((long)lparam, 16) + lDescription + " result=0x" + Convert.ToString((long)result, 16)); }
protected override void WndProc(ref Message m) { if (_designer is null) { DefWndProc(ref m); return; } if (m.Msg == (int)User32.WM.DESTROY) { _designer.RemoveSubclassedWindow(m.HWnd); } if (m.Msg == (int)User32.WM.PARENTNOTIFY && PARAM.LOWORD(m.WParam) == (short)User32.WM.CREATE) { _designer.HookChildHandles(m.LParam); // they will get removed from the collection just above } // We want these messages to go through the designer's WndProc method, and we want people to be able // to do default processing with the designer's DefWndProc. So, we stuff ourselves into the designers // window target and call their WndProc. IDesignerTarget designerTarget = _designer.DesignerTarget; _designer.DesignerTarget = this; Debug.Assert(m.HWnd == Handle, "Message handle differs from target handle"); try { _designer.WndProc(ref m); } catch (Exception ex) { _designer.SetUnhandledException(Control.FromChildHandle(m.HWnd), ex); } finally { // make sure the designer wasn't destroyed if (_designer != null && _designer.Component != null) { _designer.DesignerTarget = designerTarget; } } }
protected override void WndProc(ref Message m) { if (m.Msg == (int)User32.WM.SHOWWINDOW) { return; } base.WndProc(ref m); switch (m.Msg) { case (int)User32.WM.PARENTNOTIFY: if (PARAM.LOWORD(m.WParam) == (int)User32.WM.DESTROY) { User32.PostMessageW(this, (User32.WM)WM_CHECKDESTROY); } break; case WM_CHECKDESTROY: CheckDestroy(); break; } }
protected override void WndProc(ref Message m) { if (m.Msg == WindowMessages.WM_SHOWWINDOW) { return; } base.WndProc(ref m); switch (m.Msg) { case WindowMessages.WM_PARENTNOTIFY: if (PARAM.LOWORD(m.WParam) == WindowMessages.WM_DESTROY) { UnsafeNativeMethods.PostMessage(new HandleRef(this, Handle), WM_CHECKDESTROY, IntPtr.Zero, IntPtr.Zero); } break; case WM_CHECKDESTROY: CheckDestroy(); break; } }
private int GetCharIndexFromPosition(Point pt) { int index = (int)User32.SendMessageW(_owningChildEdit, (WM)EM.CHARFROMPOS, 0, PARAM.FromPoint(pt)); index = PARAM.LOWORD(index); if (index < 0) { index = 0; } else { string t = Text; // EM_CHARFROMPOS will return an invalid number if the last character in the RichEdit // is a newline. // if (index >= t.Length) { index = Math.Max(t.Length - 1, 0); } } return(index); }
/// <summary> /// The AdornerWindow intercepts all designer-related messages and forwards them to the BehaviorService /// for appropriate actions. Note that Paint and HitTest messages are correctly parsed and translated /// to AdornerWindow coords. /// </summary> protected override void WndProc(ref Message m) { //special test hooks if (m.Msg == (int)WM_GETALLSNAPLINES) { _behaviorService.TestHook_GetAllSnapLines(ref m); } else if (m.Msg == (int)WM_GETRECENTSNAPLINES) { _behaviorService.TestHook_GetRecentSnapLines(ref m); } switch ((User32.WM)m.Msg) { case User32.WM.PAINT: { // Stash off the region we have to update. using var hrgn = new Gdi32.RegionScope(0, 0, 0, 0); User32.GetUpdateRgn(m.HWnd, hrgn, BOOL.TRUE); // The region we have to update in terms of the smallest rectangle that completely encloses // the update region of the window gives us the clip rectangle. RECT clip = new RECT(); User32.GetUpdateRect(m.HWnd, ref clip, BOOL.TRUE); Rectangle paintRect = clip; using Region region = hrgn.CreateGdiPlusRegion(); // Call the base class to do its painting. DefWndProc(ref m); // Now do our own painting. using Graphics g = Graphics.FromHwnd(m.HWnd); using PaintEventArgs pevent = new PaintEventArgs(g, paintRect); g.Clip = region; _behaviorService.PropagatePaint(pevent); break; } case User32.WM.NCHITTEST: Point pt = new Point( (short)PARAM.LOWORD(m.LParam), (short)PARAM.HIWORD(m.LParam)); var pt1 = new Point(); User32.MapWindowPoints(IntPtr.Zero, Handle, ref pt1, 1); pt.Offset(pt1.X, pt1.Y); if (_behaviorService.PropagateHitTest(pt) && !ProcessingDrag) { m.Result = (IntPtr)User32.HT.TRANSPARENT; } else { m.Result = (IntPtr)User32.HT.CLIENT; } break; case User32.WM.CAPTURECHANGED: base.WndProc(ref m); _behaviorService.OnLoseCapture(); break; default: base.WndProc(ref m); break; } }
protected unsafe override IntPtr HookProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam) { switch ((User32.WM)msg) { case User32.WM.INITDIALOG: User32.SendDlgItemMessageW( hwnd, (User32.DialogItemID)Comdlg32.COLOR.HUE, (User32.WM)User32.EM.SETMARGINS, (IntPtr)(User32.EC.LEFTMARGIN | User32.EC.RIGHTMARGIN)); User32.SendDlgItemMessageW( hwnd, (User32.DialogItemID)Comdlg32.COLOR.SAT, (User32.WM)User32.EM.SETMARGINS, (IntPtr)(User32.EC.LEFTMARGIN | User32.EC.RIGHTMARGIN)); User32.SendDlgItemMessageW( hwnd, (User32.DialogItemID)Comdlg32.COLOR.LUM, (User32.WM)User32.EM.SETMARGINS, (IntPtr)(User32.EC.LEFTMARGIN | User32.EC.RIGHTMARGIN)); User32.SendDlgItemMessageW( hwnd, (User32.DialogItemID)Comdlg32.COLOR.RED, (User32.WM)User32.EM.SETMARGINS, (IntPtr)(User32.EC.LEFTMARGIN | User32.EC.RIGHTMARGIN)); User32.SendDlgItemMessageW( hwnd, (User32.DialogItemID)Comdlg32.COLOR.GREEN, (User32.WM)User32.EM.SETMARGINS, (IntPtr)(User32.EC.LEFTMARGIN | User32.EC.RIGHTMARGIN)); User32.SendDlgItemMessageW( hwnd, (User32.DialogItemID)Comdlg32.COLOR.BLUE, (User32.WM)User32.EM.SETMARGINS, (IntPtr)(User32.EC.LEFTMARGIN | User32.EC.RIGHTMARGIN)); IntPtr hwndCtl = User32.GetDlgItem(hwnd, (User32.DialogItemID)Comdlg32.COLOR.MIX); User32.EnableWindow(hwndCtl, BOOL.FALSE); User32.SetWindowPos( hwndCtl, User32.HWND_TOP, flags: User32.SWP.HIDEWINDOW); hwndCtl = User32.GetDlgItem(hwnd, (User32.DialogItemID)User32.ID.OK); User32.EnableWindow(hwndCtl, BOOL.FALSE); User32.SetWindowPos( hwndCtl, User32.HWND_TOP, flags: User32.SWP.HIDEWINDOW); Color = Color.Empty; break; case User32.WM.COMMAND: if (PARAM.LOWORD(wParam) == (int)Comdlg32.COLOR.ADD) { BOOL success = BOOL.FALSE; byte red = (byte)User32.GetDlgItemInt(hwnd, (int)Comdlg32.COLOR.RED, &success, BOOL.FALSE); Debug.Assert(success.IsFalse(), "Couldn't find dialog member COLOR_RED"); byte green = (byte)User32.GetDlgItemInt(hwnd, (int)Comdlg32.COLOR.GREEN, &success, BOOL.FALSE); Debug.Assert(success.IsFalse(), "Couldn't find dialog member COLOR_GREEN"); byte blue = (byte)User32.GetDlgItemInt(hwnd, (int)Comdlg32.COLOR.BLUE, &success, BOOL.FALSE); Debug.Assert(success.IsFalse(), "Couldn't find dialog member COLOR_BLUE"); Color = Color.FromArgb(red, green, blue); User32.PostMessageW( hwnd, User32.WM.COMMAND, PARAM.FromLowHigh((int)User32.ID.OK, 0), User32.GetDlgItem(hwnd, (User32.DialogItemID)User32.ID.OK)); break; } break; } return(base.HookProc(hwnd, msg, wParam, lParam)); }
public unsafe void LOWORD_x64_Result() { Assert.Equal(0x0304, PARAM.LOWORD(unchecked ((nint)0x0506070801020304))); Assert.Equal(0xF3F4, PARAM.LOWORD(unchecked ((nint)0xF5F6F7F8F1F2F3F4))); }
public unsafe void LOWORD_x32_Result() { Assert.Equal(0x0304, PARAM.LOWORD((nint)0x01020304)); Assert.Equal(0xF3F4, PARAM.LOWORD(unchecked ((nint)0xF1F2F3F4))); }