参考http://www.cppblog.com/hlong/archive/2007/10/26/35217.html
1.先加入
LVN_ITEMCHANGED消息及处理函数
2.消息处理函数:
..................
NM_LISTVIEW* pNMLV = (NM_LISTVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
if((pNMLV->uOldState & INDEXTOSTATEIMAGEMASK(1)) /* old state : unchecked */
&& (pNMLV->uNewState & INDEXTOSTATEIMAGEMASK(2)) /* new state : checked */
)
{
TRACE("Item %d is checked\n", pNMLV->iItem);
ChangeImgage(pNMLV->iItem);
}
else if((pNMLV->uOldState & INDEXTOSTATEIMAGEMASK(2)) /* old state : checked */
&& (pNMLV->uNewState & INDEXTOSTATEIMAGEMASK(1)) /* new state : unchecked */
)
{
TRACE("Item %d is unchecked\n", pNMLV->iItem);
ChangeImgage(pNMLV->iItem);
}
else
{
TRACE("Item %d does't change the check-status\n", pNMLV->iItem);
}
.................
3...ChangeImgage...
void CWatchServersDlg::ChangeImgage(int iItem)
{
if( iItem != -1)
{
LVITEM lv_item;
memset(&lv_item,0,sizeof(LVITEM));
lv_item.iItem = iItem;
m_list.GetItem(&lv_item);
lv_item.mask = LVIF_IMAGE;
if(m_list.GetCheck(iItem))
{
//勾住时显示图标
lv_item.iImage = 1;
}
else
{
//没勾住时不显示图标
lv_item.iImage = -1;
}
m_list.SetItem(&lv_item);
m_list.Update(iItem); //及时更新状态
}
}
posted on 2008-04-27 15:04
冰风谷 阅读(318)
评论(0) 编辑 收藏 引用