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}"); } }
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); }
// Returns a Proxy element corresponding to the specified screen coordinates. internal override ProxySimple ElementProviderFromPoint(int x, int y) { NativeMethods.HDHITTESTINFO HitTestInfo = new NativeMethods.HDHITTESTINFO(); HitTestInfo.pt = new NativeMethods.Win32Point(x, y); int index = -1; if (Misc.MapWindowPoints(IntPtr.Zero, _hwnd, ref HitTestInfo.pt, 1)) { unsafe { index = XSendMessage.XSendGetIndex(_hwnd, NativeMethods.HDM_HITTEST, IntPtr.Zero, new IntPtr(&HitTestInfo), Marshal.SizeOf(HitTestInfo.GetType())); } } // make sure that hit-test happened on the header item itself if (index != -1 && (NativeMethods.HHT_ONHEADER == (HitTestInfo.flags & 0x000F))) { return(CreateHeaderItem(GetItemFromIndex(index))); } return(this); }