如何在使用CB_SETCURSEL时发送CBN_SELCHANGE消息? [英] How to send a CBN_SELCHANGE message when using CB_SETCURSEL?

查看:1542
本文介绍了如何在使用CB_SETCURSEL时发送CBN_SELCHANGE消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 CB_SETCURSEL 讯息时,不会传送 CBN_SELCHANGE 讯息。



如何通知对照组选择已更改?



PS / p>

我在 Sexchange 网站,一个非常丑陋的黑客:

  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);

现在...不是真的。



PS2



为了解决我的问题,我将在评论中跟踪Ken的建议。

解决方案

除非用户进行了选择更改,否则不应使用CBN_SELCHANGE。



您不会指明您使用的是哪种语言;



在Delphi中,OnChange()会与组合框相关联,您只需调用事件方法:

  //将CB_SETCURSEL消息发送到组合框
PostMessage(ComboBox1.Handle,CB_SETCURSEL,Whatever ,WhateverElse);

//直接调用OnChange()处理程序,这相当于CBN_SELCHANGE
ComboBox1Change(nil);


When using the CB_SETCURSEL message, the CBN_SELCHANGE message is not sent.

How to notify a control that the selection was changed ?

P.S.

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

For resolving my problem, I'll follow Ken's suggestion in the comments.

解决方案

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.

In Delphi, 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消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆