Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows API
  4. Incorrect listview hittesting

Incorrect listview hittesting

Scheduled Pinned Locked Moved Windows API
csswpftestingbeta-testinghelp
2 Posts 2 Posters 12 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AlwaysLearningNewStuff
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • A AlwaysLearningNewStuff

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Please do not post the same question in multiple forums.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups