ComboBoxEx32 (CComboBoxEx) 键盘行为
我有一个 WTL 应用程序,它使用带有 CBS_DROPDOWNLIST
样式的扩展组合框控件(Win32 类 ComboBoxEx32
)。它工作得很好(我可以针对框中的每个项目都有图像),但键盘行为与普通组合框不同 - 按下某个键不会跳转到组合中以该字母开头的第一个项目。
例如,如果我将字符串“Arnold”、“Bob”和“Charlie”添加到组合中,然后选择该组合并按“B”,则不会选择“Bob”。
有谁知道如何进行这项工作?目前我能想到的唯一想法是以某种方式子类化“实际”组合框(我可以使用 CBEM_GETCOMBOCONTROL 消息获取该组合框的句柄)并处理 WM_CHARTOITEM 。这是一个 PITA,所以我想问问是否有其他人以前遇到过这个问题。
I have a WTL application that uses an extended combobox control (the Win32 class ComboBoxEx32
) with the CBS_DROPDOWNLIST
style. It works well (I can have images against each item in the box) but the keyboard behaviour is different to a normal combobox - pressing a key will not jump to the first item in the combo that starts with that letter.
For example, if I add the strings 'Arnold', 'Bob' and 'Charlie' to the combo, if I then select the combo and press 'B', then 'Bob' won't be selected.
Does anyone know how to make this work? Currently the only idea I can think of is to somehow subclass the 'actual' combobox (I can get the handle to this using the CBEM_GETCOMBOCONTROL
message) and process WM_CHARTOITEM
. This is a PITA so I thought I'd ask if anyone else has come across this issue before.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
最后,我挂钩了组合框控件(通过 CBEM_GETCOMBOCONTROL 获得)并捕获了 WM_CHARTOITEM 消息并执行了我自己的查找。如果其他人有兴趣,我可以发布代码。
In the end I hooked the combobox control (obtained with
CBEM_GETCOMBOCONTROL
) and trapped theWM_CHARTOITEM
message and performed my own lookup. I can post code if anyone else is interested.我创建了一个工作解决方案并想分享:
ComboBoxExKeyboardSupport.h
ComboBoxExKeyboardSupport.cpp
I created a working solution and want to share that:
ComboBoxExKeyboardSupport.h
ComboBoxExKeyboardSupport.cpp
我的建议是放弃 CComboBoxEx 并使用所有者绘制的常规组合框来绘制图标。 CComboBoxEx 与“正常”组合框略有不同,但在某种程度上我怀疑它是一个完整的重新实现。请注意所选项目与普通组合框中所选项目的外观略有不同。
使用 COwnerDraw mixin 可以很容易地实现 WTL 中的所有者绘制控件。
不是回答你的问题,只是让你知道这就是我现在处理 CComboBoxEx 的方式:)
My suggestion is to ditch CComboBoxEx and draw the icon with an owner-draw regular combo box. CComboBoxEx is slightly different from the 'normal' combobox but in just enough ways that I suspect it's a complete re-implementation. Notice how a selected item looks slightly different from one that is selected in a normal combo box, as well.
Owner draw controls in WTL are quite easy to implement with the COwnerDraw mixin.
Not an answer to your question, just letting you know that that's how I deal CComboBoxEx nowadays :)
在我们的应用程序中,您描述的键盘行为在版本之间丢失了。事实证明,我们删除了一个额外的清单依赖项,这导致了对旧版本 comctl32.dll (5.82) 的依赖。这行在项目设置中,配置属性->链接器->清单文件 ->其他清单依赖项:
type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processArchitecture='' publicKeyToken='6595b64144ccf1df' language=''
已修复我们。
使用 Dependency Walker,可以检查应用程序现在是否仅依赖于 comctl32.dll 版本 6.10,该版本具有正确的行为。
In our application, the keyboard behaviour you described was lost between versions. As it turns out, we removed an additional manifest dependency, which resulted in a dependency on an older version of comctl32.dll (5.82). This line in the project settings, Configuration Properties -> Linker -> Manifest File -> Additional Manifest Dependencies:
type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='' publicKeyToken='6595b64144ccf1df' language=''
fixed it for us.
Using Dependency Walker, one can check that the app is now only dependent on comctl32.dll version 6.10, which has the correct behaviour.