protected override void WndProc(ref Message m) { switch (m.Msg) { case 0x7b: //WM_CONTEXTMENU { int lp = m.LParam.ToInt32(); Point pt = new Point(((lp << 16) >> 16), lp >> 16); pt = PointToClient(pt); IntPtr hHdr = HeaderHandle; var hti = new NativeMethods.HDHITTESTINFO(pt); int item = NativeMethods.SendMessage(hHdr, NativeMethods.HeaderMessage.HitTest, 0, hti).ToInt32(); if (item != -1) { if (ColumnContextMenuStrip != null) { ColumnContextMenuStrip.Show(this, pt); } } } break; case 0x204E: // WM_NOTIFY WmReflectNotify(ref m); break; case 0x0200: // WM_MOUSEMOVE return; case 0x0202: // WM_LBUTTONUP default: break; } try { base.WndProc(ref m); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"ListViewEx WndProc Error: {m} - {ex}"); } }
private void WmReflectNotify(ref Message m) { var nm = (NativeMethods.NMHDR)m.GetLParam(typeof(NativeMethods.NMHDR)); if (nm.code == (int)NativeMethods.ListViewNotifications.ColumnDropDown) { var nmlv = (NativeMethods.NMLISTVIEW)m.GetLParam(typeof(NativeMethods.NMLISTVIEW)); var iCol = nmlv.iSubItem; NativeMethods.RECT rc = new NativeMethods.RECT(); NativeMethods.SendMessage(HeaderHandle, (uint)NativeMethods.HeaderMessage.GetItemDropDownRect, (IntPtr)iCol, ref rc); rc = RectangleToClient(rc); if (ColumnContextMenuStrip != null) { ColumnContextMenuStrip.Tag = iCol; ColumnContextMenuStrip.Show(this, rc.X, rc.Bottom); } } }
protected override void WndProc(ref Message m) { switch (m.Msg) { case 0x7b: //WM_CONTEXTMENU { int lp = m.LParam.ToInt32(); Point pt = new Point(((lp << 16) >> 16), lp >> 16); IntPtr hHdr = HeaderHandle; if (0 != NativeMethods.MapWindowPoints(IntPtr.Zero, hHdr, ref pt, 1)) { var hti = new NativeMethods.HDHITTESTINFO(pt); int item = NativeMethods.SendMessage(hHdr, NativeMethods.HeaderMessage.HitTest, 0, hti).ToInt32(); if (item != -1) { if (ColumnContextMenuStrip != null) { ColumnContextMenuStrip.Show(pt); } } } } break; case 0x204E: // WM_NOTIFY WmReflectNotify(ref m); break; case 0x0200: // WM_MOUSEMOVE return; case 0x0202: // WM_LBUTTONUP default: break; } base.WndProc(ref m); }