从 Listview Control 复选框获取通知代码

2022-01-12 00:00:00 user-interface listview mfc listviewitem

我已经用 LVS_EX_CHECKBOXES | 实现了一个 ListView 控件.LVS_EX_INFOTIP 样式.我已经注册了从列表视图控件项中获取通知的函数.

I've implemented a ListView control with LVS_EX_CHECKBOXES | LVS_EX_INFOTIP style. I've registered function to get notified from list view control items using.

BEGIN_MESSAGE_MAP(Class, ParentClass)
ON_NOTIFY(LVN_GETINFOTIP,IDC_LIST2,OnClickCheckBox)
END_MESSAGE_MAP()

我的问题是,当您选择/取消选择 ListView 控件项目中的复选框时,将向父级发送什么通知代码..

My question is, what notification code will be sent to parent when you select/de-select the checkbox in the item of ListView control..

需要编写哪些代码来处理 OnClickCheckBox() 函数中的复选框选择?

What code need to be written to handle checkbox selection in the OnClickCheckBox() function ?

请帮帮我

推荐答案

你得到 item-changed-message 并且你必须找出复选框状态是否已经改变.

You get the item-changed-message and you have to find out, if the checkbox-state has been changed.

在消息映射中:

ON_NOTIFY_REFLECT(LVN_ITEMCHANGED, &CMyListView::OnLvnItemchanged)

事件处理程序:

void CMyListView::OnLvnItemchanged(NMHDR *pNMHDR, LRESULT *pResult)
{
    LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);

    if(pNMLV->uNewState == 8192) // Item checked
    {
        ...
    }
    else if(pNMLV->uNewState == 4096) // Item unchecked
    {
        ...
    }

    *pResult = 0;
}

相关文章