我正在开发MFC SDI应用程序。我的观点来自CListView
类。我想处理列表控件的选择更改事件。我无法添加WM_NOTIFY
消息处理程序,因为我不知道如何获取创建的列表视图的ID。请帮帮我。
答案 0 :(得分:1)
您只需将以下内容添加到消息地图中:
ON_NOTIFY_REFLECT(LVN_ITEMCHANGED, &OnItemChanged)
这是你的事件处理程序:
void CMyListView::OnItemChanged(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// Did the item state change?
if (pNMListView->uChanged & LVIF_STATE)
{
// Did the item selection change?
const bool oldSelState = (pNMListView->uOldState & LVIS_SELECTED) != 0x0;
const bool newSelState = (pNMListView->uNewState & LVIS_SELECTED) != 0x0;
const bool selStateChanged = oldSelState != newSelState;
if(selStateChanged)
{
// TODO: handle selection change; use newSelState where appropriate
}
}
*pResult = 0;
}