Incorrect listview hittesting
-
INTRODUCTION: I am trying to determine if user clicked on item or above/below listview. Listview is in report mode, with extended styles full row select and grid lines. PROBLEM: I am not able to get correct results, based on the docs for LVHITTESTINFO. MY EFFORTS TO SOLVE THE PROBLEM: I have made checkboxes with same caption as the values in LVHITTESTINFO in my main window. These are LVHT_ABOVE, LVHT_BELOW, LVHT_NOWHERE, LVHT_TOLEFT, LVHT_TORIGHT and LVHT_ONITEM. My goal is to check the ones with same caption as returned result from hittesting. I have captured the mouse in my main window in response to WM_LBUTTONDOWN and am doing the hittesting in WM_LBUTTONUP handler. This was the easiest way for me to code the smallest SSCCE/code snippets that can be posted here. Here is the relevant code:
case WM_LBUTTONDOWN:
// reset checkboxes
CheckDlgButton(hWnd, 3000, BST_UNCHECKED);
CheckDlgButton(hWnd, 3100, BST_UNCHECKED);
CheckDlgButton(hWnd, 3200, BST_UNCHECKED);
CheckDlgButton(hWnd, 3300, BST_UNCHECKED);
CheckDlgButton(hWnd, 3400, BST_UNCHECKED);
CheckDlgButton(hWnd, 3500, BST_UNCHECKED);
// capture the mouse
SetCapture(hWnd);
break;
case WM_LBUTTONUP:
{
// extract coordinates
POINT pt = { 0 };
pt.x = GET_X_LPARAM(lParam);
pt.y = GET_Y_LPARAM(lParam);
// do the hittesting
ClientToScreen(hWnd, &pt);
ScreenToClient(GetDlgItem(hWnd, 2000), &pt);LVHITTESTINFO lvhti = { 0 }; lvhti.pt = pt; ListView\_HitTest(GetDlgItem(hWnd, 2000), &lvhti); // check appropriate checkboxes if ((lvhti.flags & LVHT\_ABOVE) == LVHT\_ABOVE) CheckDlgButton(hWnd, 3000, BST\_CHECKED); if ((lvhti.flags & LVHT\_BELOW) == LVHT\_BELOW) CheckDlgButton(hWnd, 3100, BST\_CHECKED); if ((lvhti.flags & LVHT\_NOWHERE) == LVHT\_NOWHERE) CheckDlgButton(hWnd, 3200, BST\_CHECKED); if ((lvhti.flags & LVHT\_ONITEM) == LVHT\_ONITEM) CheckDlgButton(hWnd, 3300, BST\_CHECKED); if ((lvhti.flags & LVHT\_TOLEFT) == LVHT\_TOLEFT) CheckDlgButton(hWnd, 3400, BST\_CHECKED); if ((lvhti.flags & LVHT\_TORIGHT) == LVHT\_TORIGHT) CheckDlgButton(hWnd, 3500, BST\_CHECKED); // release mouse capture ReleaseCapture();
}
break;TESTING PRINCIPLE: Testing is done in the following way: I click on main windows client area, hold left mouse button down, and drag cursor over item/above
-
INTRODUCTION: I am trying to determine if user clicked on item or above/below listview. Listview is in report mode, with extended styles full row select and grid lines. PROBLEM: I am not able to get correct results, based on the docs for LVHITTESTINFO. MY EFFORTS TO SOLVE THE PROBLEM: I have made checkboxes with same caption as the values in LVHITTESTINFO in my main window. These are LVHT_ABOVE, LVHT_BELOW, LVHT_NOWHERE, LVHT_TOLEFT, LVHT_TORIGHT and LVHT_ONITEM. My goal is to check the ones with same caption as returned result from hittesting. I have captured the mouse in my main window in response to WM_LBUTTONDOWN and am doing the hittesting in WM_LBUTTONUP handler. This was the easiest way for me to code the smallest SSCCE/code snippets that can be posted here. Here is the relevant code:
case WM_LBUTTONDOWN:
// reset checkboxes
CheckDlgButton(hWnd, 3000, BST_UNCHECKED);
CheckDlgButton(hWnd, 3100, BST_UNCHECKED);
CheckDlgButton(hWnd, 3200, BST_UNCHECKED);
CheckDlgButton(hWnd, 3300, BST_UNCHECKED);
CheckDlgButton(hWnd, 3400, BST_UNCHECKED);
CheckDlgButton(hWnd, 3500, BST_UNCHECKED);
// capture the mouse
SetCapture(hWnd);
break;
case WM_LBUTTONUP:
{
// extract coordinates
POINT pt = { 0 };
pt.x = GET_X_LPARAM(lParam);
pt.y = GET_Y_LPARAM(lParam);
// do the hittesting
ClientToScreen(hWnd, &pt);
ScreenToClient(GetDlgItem(hWnd, 2000), &pt);LVHITTESTINFO lvhti = { 0 }; lvhti.pt = pt; ListView\_HitTest(GetDlgItem(hWnd, 2000), &lvhti); // check appropriate checkboxes if ((lvhti.flags & LVHT\_ABOVE) == LVHT\_ABOVE) CheckDlgButton(hWnd, 3000, BST\_CHECKED); if ((lvhti.flags & LVHT\_BELOW) == LVHT\_BELOW) CheckDlgButton(hWnd, 3100, BST\_CHECKED); if ((lvhti.flags & LVHT\_NOWHERE) == LVHT\_NOWHERE) CheckDlgButton(hWnd, 3200, BST\_CHECKED); if ((lvhti.flags & LVHT\_ONITEM) == LVHT\_ONITEM) CheckDlgButton(hWnd, 3300, BST\_CHECKED); if ((lvhti.flags & LVHT\_TOLEFT) == LVHT\_TOLEFT) CheckDlgButton(hWnd, 3400, BST\_CHECKED); if ((lvhti.flags & LVHT\_TORIGHT) == LVHT\_TORIGHT) CheckDlgButton(hWnd, 3500, BST\_CHECKED); // release mouse capture ReleaseCapture();
}
break;TESTING PRINCIPLE: Testing is done in the following way: I click on main windows client area, hold left mouse button down, and drag cursor over item/above