A customer had a Win32 common controls ListView in single-click mode. This has a side effect of enabling hover effects: When the mouse hovers over an item, the cursor changes to a hand, and the item gets highlighted in the hot-track color. How can they suppress these hover effects while still having single-click activation?

When the user hovers over an item, the ListView sends a LVN_HOT­TRACK notification, and you can suppress all hot-tracking effects by returning 1.

// WndProc
case WM_NOTIFY:
{
    auto nm = (NMLISTVIEW*)lParam;
    if (nm->hdr.code == LVN_HOTTRACK)
    {
        return 1;
    }
}
break;

If you are doing this from a dialog box, you need to set the DWLP_MSG­RESULT to the desired return value, which is 1 in this case, and then return TRUE to say “I handled the message; use the value I put into DWLP_MSG­RESULT.”

// DlgProc
case WM_NOTIFY:
{
    auto nm = (NMLISTVIEW*)lParam;
    if (nm->hdr.code == LVN_HOTTRACK)
    {
        SetWindowLongPtr(hDlg, DWLP_MSGRESULT, 1);
        return TRUE;
    }
}
break;

The post How do I suppress the hover effects when I put a Win32 common controls ListView in single-click mode? appeared first on The Old New Thing.


From The Old New Thing via this RSS feed