以下是确定项目检查状态是否已更改的正确方法:
void CAttrSelectorDlg::OnLvnItemchangedAttrList(NMHDR* pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
int nItem = pNMLV->iItem;
// get old check box state
BOOL bPrevState = ( BOOL ) ( ( ( pNMLV->uOldState & LVIS_STATEIMAGEMASK ) >> 12 ) - 1 );
if ( bPrevState < 0 ) // On startup there's no previous state
bPrevState = FALSE; // assing as false (unchecked)
// get new check box state
BOOL bNewState = ( BOOL ) ( ( ( pNMLV->uNewState & LVIS_STATEIMAGEMASK ) >> 12 ) - 1 );
if ( bNewState < 0 ) // non-check box notification
bNewState = FALSE;
if (bPrevState != bNewState)
{
// state changed. DO STUFF
}
*pResult = 0;
}
对于您的任务,我建议使用删除按钮删除选定(选中)项目:
for (int i=0; i<m_AttrList.GetItemCount(); i++)
{
BOOL bCheck = m_AttrList.GetCheck(i);
if (bCheck)
{
// item is checked
}
}