如何将鼠标双击添加到ListBox

How to add mouse double click to ListBox

到此代码:https://www.dreamincode.net/forums/topic/163804-microsoft-working-with-listboxes-part-i/

显示列表和循环很好。

可悲的是,我的大师从未完成他的代码。 因此计划将在名称上添加双击检测。怎么样?

        case WM_COMMAND:
        {

            return 0;
        }

是这样的吗? 11 是这个 child window 名字在哪里。

        case WM_COMMAND:
        {
            if (LOWORD(wparam) == 11) {
                if ((message) == LBN_DBLCLK) {
                    cout << "double click" << endl;
                }
            }
            return 0;
        }

不起作用

尝试替换:

if ((message) == LBN_DBLCLK)

与:

if (HIWORD (wParam) == LBN_DBLCLK)

文档 here.

首先,根据documentation

Parameters

wParam

The LOWORD contains the identifier of the list box. The HIWORD specifies the notification code.

lParam

Handle to the list box.

Remarks

This notification code is sent only by a list box that has the LBS_NOTIFY style.

所以第一步需要添加这个样式,用HIWORD (wParam)判断是否双击列表

那么如果需要获取列表的元素,就不要将LB_GETCURSEL发送到window_handle,而应该将它发送到This->listbox_handle,也就是[=32] =] 列表框的句柄。然后发送LB_GETTEXT文字内容即可获取

代码如下:

case WM_COMMAND:
{
    if (HIWORD(wparam) == LBN_DBLCLK) {
        TCHAR temp[100]{};
        int index = SendMessageW(This->listbox_handle, LB_GETCURSEL, 0, 0L);
        SendMessageW(This->listbox_handle, LB_GETTEXT, index, (LPARAM)temp);
        MessageBox(window_handle, temp, L"test", 0);
    }
    return 0;
}

它对我有用: