protected override void WndProc(ref Message m) { //the link uses WM_LBUTTONDOWN but I found that it doesn't work if (m.Msg == WM_LBUTTONUP || m.Msg == WM_LBUTTONDOWN) { LVHITTESTINFO info = new LVHITTESTINFO(); //The LParamToPOINT function I adapted to not bother with // converting to System.Drawing.Point, rather I just made // its return type the POINT struct Point hitPoint = LParamToPoint(m.LParam); info.pt.x = hitPoint.X; info.pt.y = hitPoint.Y; //if the click is on the group header, exit, otherwise send message if (NativeMethods.SendMessage(this.Handle, LVM_SUBITEMHITTEST, -1, ref info) != -1) if ((info.flags & LVHITTESTFLAGS.LVHT_EX_GROUP_HEADER) != 0) return; //* if (m.Msg >= 0x201 && m.Msg <= 0x209) { Point pos = new Point(m.LParam.ToInt32() & 0xffff, m.LParam.ToInt32() >> 16); var hit = this.HitTest(pos); switch (hit.Location) { case ListViewHitTestLocations.AboveClientArea: case ListViewHitTestLocations.BelowClientArea: case ListViewHitTestLocations.LeftOfClientArea: case ListViewHitTestLocations.RightOfClientArea: case ListViewHitTestLocations.None: return; } } } else if (m.Msg == WM_LBUTTONDBLCLK || m.Msg == WM_RBUTTONDBLCLK || m.Msg == WM_RBUTTONUP || m.Msg == WM_RBUTTONDOWN) { if (m.Msg >= 0x201 && m.Msg <= 0x209) { Point pos = new Point(m.LParam.ToInt32() & 0xffff, m.LParam.ToInt32() >> 16); var hit = this.HitTest(pos); switch (hit.Location) { case ListViewHitTestLocations.AboveClientArea: case ListViewHitTestLocations.BelowClientArea: case ListViewHitTestLocations.LeftOfClientArea: case ListViewHitTestLocations.RightOfClientArea: case ListViewHitTestLocations.None: return; } } } base.WndProc(ref m); }
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, ref LVHITTESTINFO ht);
public static int HitTest(ObjectListView olv, ref LVHITTESTINFO hittest) { return (int)NativeMethods.SendMessage(olv.Handle, olv.View == View.Details ? LVM_SUBITEMHITTEST : LVM_HITTEST, -1, ref hittest); }
public static extern int SendMessage(HandleRef hWnd, int msg, IntPtr wParam, ref LVHITTESTINFO lParam);
private static extern int SendMessage(IntPtr hWnd, int msg, int wParam, ref LVHITTESTINFO ht);
private void ListView_SubItemHitTest(MouseEventsTypes met) { LVHITTESTINFO lvh = new LVHITTESTINFO(); lvh.pt = PointToClient(Control.MousePosition); IntPtr ptr = Marshal.AllocHGlobal( Marshal.SizeOf(lvh) ); Marshal.StructureToPtr(lvh, ptr, true); SendMessage(Handle, LVM_SUBITEMHITTEST, IntPtr.Zero, ptr); lvh = (LVHITTESTINFO)Marshal.PtrToStructure(ptr, typeof(LVHITTESTINFO)); Marshal.FreeHGlobal(ptr); // check if the item is valid if ((lvh.iItem >= 0) || (lvh.iSubItem >= 0)) { ItemSubItemClickEventArgs args = new ItemSubItemClickEventArgs(lvh.iItem, lvh.iSubItem, met); this.OnItemSubItemClick(args); } else this.Cursor = Cursors.Default; }
public static extern int SendMessage(IntPtr hwnd, uint msg, uint wParam, ref LVHITTESTINFO lParam);
public static extern IntPtr SendMessage(HandleRef hWnd, int msg, IntPtr wParam, ref LVHITTESTINFO lParam);
private static extern IntPtr SendHitTestMessage(HandleRef hWnd, int msg, int wParam, LVHITTESTINFO lParam);
public static int HitTest(ObjectListView olv, ref LVHITTESTINFO hittest) { return((int)NativeMethods.SendMessage(olv.Handle, olv.View == View.Details ? LVM_SUBITEMHITTEST : LVM_HITTEST, -1, ref hittest)); }
static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, ref LVHITTESTINFO lpBuffer, int nSize, ref int lpNumberOfBytesRead);
public static extern IntPtr SendMessage_LvHitTest(IntPtr hWnd, int Msg, IntPtr nIndex, ref LVHITTESTINFO pHitTestInfo);
internal static extern int SendMessage(IntPtr hWnd, int msg, int wParam, ref LVHITTESTINFO lParam);
private static extern bool SendMessage(IntPtr hWnd, Int32 msg, Int32 wParam, ref LVHITTESTINFO lParam);
/// <summary> /// 指定の座標にアイコンがないか /// </summary> /// <param name="hwnd"></param> /// <param name="x"></param> /// <param name="y"></param> /// <returns>アイコンがない場合はtrue</returns> private bool IsHitTestNoIcon(IntPtr hwnd, int x, int y) { int pID = 0; IntPtr hProcess = IntPtr.Zero; IntPtr p = IntPtr.Zero; try { POINT pt = new POINT(); pt.x = x; pt.y = y; ScreenToClient(hwnd, ref pt); GetWindowThreadProcessId(hwnd, ref pID); hProcess = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE, false, pID); if (hProcess != IntPtr.Zero) { LVHITTESTINFO lhi = new LVHITTESTINFO(); int dw = 0; lhi.pt = pt; p = VirtualAllocEx(hProcess, IntPtr.Zero, Marshal.SizeOf(lhi), MEM_COMMIT, PAGE_READWRITE); WriteProcessMemory(hProcess, p, ref lhi, Marshal.SizeOf(lhi), ref dw); SendMessage(hwnd, LVM_SUBITEMHITTEST, IntPtr.Zero, p); ReadProcessMemory(hProcess, p, ref lhi, Marshal.SizeOf(lhi), ref dw); return lhi.iItem < 0; } } finally { if (p != IntPtr.Zero) VirtualFreeEx(hProcess, p, 0, MEM_RELEASE); if (hProcess != IntPtr.Zero) CloseHandle(hProcess); } return false; }