How to send a CBN_SELCHANGE message when using CB_SETCURSEL?(使用 CB_SETCURSEL 时如何发送 CBN_SELCHANGE 消息?)
问题描述
使用CB_SETCURSEL 消息时,不会发送CBN_SELCHANGE 消息.
When using the CB_SETCURSEL message, the CBN_SELCHANGE message is not sent.
如何通知控件选择已更改?
How to notify a control that the selection was changed ?
附言
我在 Sexchange 网站上发现了一个非常丑陋 hack :
I found on the Sexchange site, a very ugly hack :
SendMessage( hwnd, 0x014F/*CB_SHOWDROPDOWN*/, 1, 0 );
SendMessage( hwnd, 0x014E/*CB_SETCURSEL*/, ItemIndex, 0 );
SendMessage( hwnd, 0x0201/*WM_LBUTTONDOWN*/, 0, -1 );
SendMessage( hwnd, 0x0202/*WM_LBUTTONUP*/, 0, -1 );
暂时会做...不是真的.
Will do for now... Not really.
P.S.2
为了解决我的问题,我会在评论中遵循 Ken 的建议.
For resolving my problem, I'll follow Ken's suggestion in the comments.
推荐答案
除非用户对选择进行了更改,否则不应使用 CBN_SELCHANGE.
You're not supposed to use CBN_SELCHANGE unless the change in selection was made by the user.
您没有指明您使用的是哪种语言;如果您这样做,则可以更轻松地为您提供解决方法.
You don't indicate what language you're using; it would make it easier to provide you with a workaround if you did so.
在 Delphi 中,OnChange() 将与组合框关联,您只需直接调用事件方法:
In Delp where an OnChange() would be associated with the combobox, you just call the event method directly:
// Send the CB_SETCURSEL message to the combobox
PostMessage(ComboBox1.Handle, CB_SETCURSEL, Whatever, WhateverElse);
// Directly call the OnChange() handler, which is the equivalent to CBN_SELCHANGE
ComboBox1Change(nil);
这篇关于使用 CB_SETCURSEL 时如何发送 CBN_SELCHANGE 消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 CB_SETCURSEL 时如何发送 CBN_SELCHANGE 消息?
基础教程推荐
- 提升 ASIO 流缓冲 2021-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- c++ STL设置差异 2022-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
