1.如何在TreeList中加图标?
[问题提出]
请问treeview控件和treectrl控件的用法有何不同呢?向如何imagelist控件中加图象呀?
[解决方法]
1)
HICON hicon[8];
m_imageList.Create(16,16,0,8,8);
hicon[0]=AfxGetApp()->LoadIcon(IDI_ICON0);
hicon[1]=AfxGetApp()->LoadIcon(IDI_ICON1);
hicon[2]=AfxGetApp()->LoadIcon(IDI_ICON2);
hicon[3]=AfxGetApp()->LoadIcon(IDI_ICON3);
hicon[4]=AfxGetApp()->LoadIcon(IDI_ICON4);
hicon[5]=AfxGetApp()->LoadIcon(IDI_ICON5);
hicon[6]=AfxGetApp()->LoadIcon(IDI_ICON6);
hicon[7]=AfxGetApp()->LoadIcon(IDI_ICON7);
for(int n=0;n<8;n++)
m_imageList.Add(hicon[n]);
CTreeCtrl *pTree=(CTreeCtrl *)GetDlgItem(IDC_TREE);
pTree->SetImageList(&m_imageList,TVSIL_NORMAL);
2)
CImageList cil1;
cil1.Create(32,32,TRUE,2,2);
cil1.Add(pApp->LoadIcon(IDI_DAO1));
cil1.Add(pApp->LoadIcon(IDI_DAO2));
cil1.Add(pApp->LoadIcon(IDI_DAO3));
cil1.Add(pApp->LoadIcon(IDI_DAO4));
cil1.Add(pApp->LoadIcon(IDI_DAO5));
cil1.Add(pApp->LoadIcon(IDI_DAO6));
cil1.Add(pApp->LoadIcon(IDI_DAO7));
cil1.Add(pApp->LoadIcon(IDI_DAO8));
cil1.Add(pApp->LoadIcon(IDI_DAO9));
//设置图象列表
m_list.SetImageList(&cil1,LVSIL_NORMAL);
2.如何选择CTreeCtrl中的节点文本进行编辑?
在向CTreeCtrl中加入一项后,有什么方法可以编辑该节点的文本呢?
首先设置你的CcompTreeCtrl具有TVS_EDITLABELS属性.在设计时用控件属性来设置在运行时用GetStyle()/SetStyle()成员函数来设置.然后请看下述代码:
HTREEITEM CCompTreeCtrl::AddSet()
{
static int setCnt =3D 1;
HTREEITEM hItem;
CString csSet;
//create text for new note: New Set 1, New Set 2 ...
csSet.Format( _T( "New Set %d" ), setCnt++ );
hItem =3D InsertItem( csSet, IMG_CLOSEDFOLDER, IMG_CLOSEDFOLDER );
if( hItem !=3D NULL )
EditLabel( hItem );
return hItem;
}