Hot tracking list item selection in a combo box(组合框中的热跟踪列表项选择)
问题描述
我有一个组合框,我需要在用户更改选择时拦截选择的更改,只需将鼠标悬停而无需点击.这是用于显示有关用户悬停的项目的补充信息.
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
不会完成这项工作,因为只有当用户实际上通过单击组合框项目之一更改了选择或当向上/向下键被按下.
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.
插图
例如:我需要知道用户何时将鼠标从条目 2
移动到条目 33
.
E.g: I need to know when the user moves the mouse from the entry 2
to the entry 33
.
推荐答案
这是基于 你提到的c#文章:
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("
");
}
}
if (msg == WM_NCDESTROY)
{
RemoveWindowSubclass(hwnd, ComboProc, uIdSubClass);
}
return DefSubclassProc(hwnd, msg, wParam, lParam);
}
...
SetWindowSubclass(hComboBox, ComboProc, 0, 0);
这是在 Windows 10 上测试过的.
This was tested on Windows 10.
这只能报告下拉列表中的悬停选择,不能改变选择.
This can only report the hover selection in drop down list, it can't change the selection.
这篇关于组合框中的热跟踪列表项选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:组合框中的热跟踪列表项选择
基础教程推荐
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01