基于CListView的SDI应用程序中的选择更改事件 [英] Selection changed event in CListView based SDI application

查看:175
本文介绍了基于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应用程序中的选择更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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