使用 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);
相关文章