在ListCtrl中将多选框变为单选框的方法

在ListCtrl中将多选框变为单选框的方法:

假定ID为IDC_LIST1
增加:
ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, OnItemchangedList1)

函数实现:
void CTestDlg::OnItemchangedList1(NMHDR* pNMHDR, LRESULT* pResult)
{
    NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
    // TODO: Add your control notification handler code here
    *pResult = 0;
   
    static int lSelectItem=-1;
    if (pNMListView->uOldState == 0 && pNMListView->uNewState == 0)
        return;    // No change

    BOOL bPrevState = (BOOL)(((pNMListView->uOldState &
        LVIS_STATEIMAGEMASK)>>12)-1);   // Old check box state
    if (bPrevState < 0)    // On startup there's no previous state
        bPrevState = 0; // so assign as false (unchecked)

    // New check box state
    BOOL bChecked=(BOOL)(((pNMListView->uNewState & LVIS_STATEIMAGEMASK)>>12)-1);  
    if (bChecked < 0) // On non-checkbox notifications assume false
        bChecked = 0;

    if (bPrevState == bChecked) // No change in check box
        return;
   
    if(bChecked)
    {
        if(lSelectItem!=-1)
        {
            //already checked, reset the last checked item
            m_list.SetCheck(lSelectItem,FALSE);
        }
        lSelectItem=pNMListView->iItem;
    }
    else
    {
        //UnCheck,reset lSelectItem
        lSelectItem=-1;
    }
}

 
阅读更多
上一篇vc中常用文件操作
下一篇lib和dll文件的区别和联系
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭