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.
这篇关于组合框中的热跟踪列表项选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:组合框中的热跟踪列表项选择
基础教程推荐
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- CString 到 char* 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
