Selection changed event in CListView based SDI application(基于 CListView 的 SDI 应用程序中的选择更改事件)
问题描述
我正在开发 MFC SDI 应用程序.我的视图是从 CListView 类派生的.我想处理列表控件的选择更改事件.我无法添加 WM_NOTIFY 消息处理程序,因为我不知道如何获取创建的列表视图的 ID.请帮帮我.
I am developing MFC SDI application. My view is derived from CListView class. I would like to handle the selection changed event for the list control. I'm not able to add WM_NOTIFY message handler as I don't know how to get the ID of the created listview. Please help me.
推荐答案
您所要做的就是将以下内容添加到您的消息映射中:
All you have to do is add the following to your message map:
ON_NOTIFY_REFLECT(LVN_ITEMCHANGED, &OnItemChanged)
这是您的事件处理程序:
And here is your event handler:
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;
}
这篇关于基于 CListView 的 SDI 应用程序中的选择更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:基于 CListView 的 SDI 应用程序中的选择更改事件
基础教程推荐
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
