WTL中,定义CListBox的消息接收。
COMMAND_HANDLER_EX(IDB_HOME_DICT_KEY_LIST,LBN_SELCHANGE, OnListItemchanged)
死活都没有触发到 LBN_SELCHANGE 的消息。
开始以为是消息订阅的问题。
后来用接收所有消息的宏
用COMMAND_ID_HANDLER_EX(IDB_HOME_DICT_KEY_LIST, OnListItemMsg)
发现只看到有得到焦点和失去焦点的消息产生。
后查MSDN。
This notification message is not sent if the LB_SETCURSEL message changes the selection.
This notification message applies only to a list box that has the LBS_NOTIFY style.
For a multiple-selection list box, the LBN_SELCHANGE notification is sent whenever the user presses an arrow key, even if the selection does not change.
原来需要设置style为
LBS_NOTIFY后来修改为:
m_pKeyList = new CListBox;
m_pKeyList->Create(m_dlg->GetViewHWND(),
NULL,
NULL,
WS_VISIBLE | WS_CHILDWINDOW | LBS_NOTIFY ,
0,IDB_HOME_DICT_KEY_LIST);
终于能收到
LBN_SELCHANGE。