1
votes

I have a combo box and I need to intercept the changement of the selection while the user changes the selection by just hovering with the mouse without clicking. This is for displaying complementary information about the item the user is hovering over.

CBN_SELCHANGE won't do the job, because this message gets fired only when the user has actually changed the selection by clicking on one of the combo box items or when the up/down keys are pressed.

Apparently no message is fired while the user is just hovering over the the combobox.

Illustration

E.g: I need to know when the user moves the mouse from the entry 2 to the entry 33.

enter image description here

1
I cannot get my plain win32 combobox to hot track with the mouse. How are you managing it?David Heffernan
@DavidHeffernan, I can't. That's actually the question:. How to hot track.Jabberwocky
So you want to modify the behaviour of the standard combo box so that it hot tracks? That's a really bad idea in terms of UX.David Heffernan
@DavidHeffernan I actually want to display some complementary information about the item the user is hovering on.Jabberwocky
@DavidHeffernan I wasn't aware that this was called "hot tracking". By doing some research using the term "hot tracking", I've found this article on CodeProject which does what I want. It's for C#, and not C or C++, but I can probably use the information provided there.Jabberwocky

1 Answers

1
votes

This is c++ subclass based on c# article which you mentioned:

LRESULT CALLBACK ComboProc(HWND hwnd, UINT msg, WPARAM wParam, 
    LPARAM lParam, UINT_PTR uIdSubClass, DWORD_PTR)
{
    if (msg == WM_CTLCOLORLISTBOX)
    {
        COMBOBOXINFO ci = { sizeof(COMBOBOXINFO) };
        GetComboBoxInfo(hwnd, &ci);
        if (HWND(lParam) == ci.hwndList)
        {
            int pos = SendMessage(ci.hwndList, LB_GETCURSEL, 0, 0);
            OutputDebugStringA(std::to_string(pos).c_str());
            OutputDebugStringA("\n");
        }
    }

    if (msg == WM_NCDESTROY)
    {
        RemoveWindowSubclass(hwnd, ComboProc, uIdSubClass);
    }

    return DefSubclassProc(hwnd, msg, wParam, lParam);
}

...
SetWindowSubclass(hComboBox, ComboProc, 0, 0);

This was tested on Windows 10.

This can only report the hover selection in drop down list, it can't change the selection.