CtreeCtrl节点展开关闭切换图标

实现代码:

HTREEITEM m_hLButtonDown;

void CViewTree::OnClkTree(NMHDR* pNMHDR, LRESULT* pResult)//CtreeCtrl单击事件
{
	CPoint pt;
	GetCursorPos(&pt);
	ScreenToClient(&pt);

	UINT uFlag = 0;
	m_hLButtonDown = HitTest(pt, &uFlag);

	if(m_hLButtonDown)
	{
		SelectItem(m_hLButtonDown);
		if (TVHT_ONITEMBUTTON & uFlag)//判断是否是按钮
		{
			CString szTietle = GetItemText(m_hLButtonDown);
			if (szTietle == "工程画面" || szTietle == "图片文件" || szTietle == "声音文件")
			{
				if (TVIS_EXPANDED & GetItemState(m_hLButtonDown, TVIS_EXPANDED))//打开状态
				{
					SetItemImage(m_hLButtonDown, 2, 2);//修改节点的图标
				}
				else
					SetItemImage(m_hLButtonDown, 1, 1);
			}
		}

	} 

	*pResult = 0;
}


你可能感兴趣的:(icon,CTreeCtrl,切换图标)