private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, ref LVHITTESTINFO lParam);
public static int ListView_SubItemHitTest(IntPtr hwnd, ref LVHITTESTINFO pinfo) { return HitTest(hwnd, 0x1039, ref pinfo); }
public static int ListView_SubItemHitTest(IntPtr hwnd, Point pt) { LVHITTESTINFO pinfo = new LVHITTESTINFO { pt = pt }; if (HitTest(hwnd, 0x1039, ref pinfo) < 0) { return -1; } return pinfo.iSubItem; }
private static int HitTest(IntPtr hwnd, int msg, ref LVHITTESTINFO pinfo) { return (int) SendMessage(hwnd, msg, IntPtr.Zero, ref pinfo); }
private bool HitTest(IntPtr ShellViewHandle, Point hitPoint, out int row, out int column) { // clear the output values row = column = -1; // set up some win32 api constant values const int LVM_FIRST = 0x1000; //const int LVM_SUBITEMHITTEST = (LVM_FIRST + 57); const int LVM_HITTEST = (LVM_FIRST + 18); const int LVHT_NOWHERE = 0x1; const int LVHT_ONITEMICON = 0x2; const int LVHT_ONITEMLABEL = 0x4; const int LVHT_ONITEMSTATEICON = 0x8; const int LVHT_EX_ONCONTENTS = 0x04000000; const int LVHT_ONITEM = (LVHT_ONITEMICON | LVHT_ONITEMLABEL | LVHT_ONITEMSTATEICON | LVHT_EX_ONCONTENTS); // set up the return value bool hitLocationFound = false; // initialise a hittest information structure LVHITTESTINFO lvHitTestInfo = new LVHITTESTINFO(); lvHitTestInfo.pt.x = hitPoint.X; lvHitTestInfo.pt.y = hitPoint.Y; // send the hittest message to find out where the click was if (SendMessage(ShellViewHandle, LVM_HITTEST, 0, ref lvHitTestInfo) != 0) { bool nowhere = ((lvHitTestInfo.flags & LVHT_NOWHERE) != 0); bool onItem = ((lvHitTestInfo.flags & LVHT_ONITEM) != 0); if (onItem && !nowhere) { row = lvHitTestInfo.iItem; column = lvHitTestInfo.iSubItem; hitLocationFound = true; } } else if (SendMessage(ShellViewHandle, LVM_FIRST, 0, ref lvHitTestInfo) != 0) { row = 0; hitLocationFound = true; } return hitLocationFound; }
private static extern int SendMessage(IntPtr hWnd, int msg, int wParam, ref LVHITTESTINFO lParam);