我在SDI程序的CTreeView对象中加入的树节点怎么没有图标,不知道在什么地方还要设置?

czdragon 2003-08-20 05:52:19
我检查了程序,图标引入,等都很正常啊!
void CDrivetreeView::OnInitialUpdate()
{
CTreeView::OnInitialUpdate();


// TODO: You may populate your TreeView with items by directly accessing
// its tree control through a call to GetTreeCtrl().

CImageList m_ImageList;

CTreeCtrl &tc = GetTreeCtrl();
m_ImageList.Create(16,16,0,8,8);
HICON hIcon[1];
hIcon[0]=AfxGetApp()->LoadIcon(IDI_CLOSE);
m_ImageList.Add(hIcon[0]);
tc.SetImageList(&m_ImageList,TVSIL_NORMAL);
HTREEITEM hItem;
hItem=tc.InsertItem(_T("OL"),TVI_ROOT,TVI_SORT);
if (hItem)
{
tc.InsertItem("J. S. Bach", 0, 0, hItem);
tc.InsertItem("W. A. Mozart", 0, 0, hItem);
tc.InsertItem("F. Chopin", 0, 0, hItem);
}
// expand
tc.Expand(hItem, TVE_EXPAND);
}
...全文
161 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
huanglaoxie1 2003-08-29
  • 打赏
  • 举报
回复
图标的大小与定义的不一致也不行的
cwming 2003-08-22
  • 打赏
  • 举报
回复
在OnInitialUpdate()加入这代码试试

void CZdataproView::OnInitialUpdate()
{

CTreeCtrl& cThisTree = GetTreeCtrl();//用cThisTree指针控制树的操作
cThisTree.DeleteAllItems();
// load bitmaps for drive types & desktop - ten images
CBitmap bitmap;
m_imagelist = new CImageList();
// 16x16 pixels, 8 of them
m_imagelist->Create(16, 16, TRUE, 8, 4);//制定图标大小
// the 8 images have conseq resource numbers
// see resource.h
for( int i = IDB_PARENTOPEN; i <= IDB_PARENT; i++)
{
bitmap.LoadBitmap( i );
m_imagelist->Add( &bitmap, (COLORREF)0xFFFFFF);
bitmap.DeleteObject();
}
cThisTree.SetImageList( m_imagelist, TVSIL_NORMAL );//设定在树框架中显示图标的方式
fillemptytree();

this->m_isInitialized = TRUE;

// TODO: You may populate your TreeView with items by directly accessing
// its tree control through a call to GetTreeCtrl().
}
hz张三 2003-08-22
  • 打赏
  • 举报
回复
哈,保存图标的CImageList要作为view的成员变量。
czdragon 2003-08-20
  • 打赏
  • 举报
回复
我照着你抄的还是不行,而且cThisTree.Expand( hDesktop1, TVE_EXPAND );并没展开
我是把它写在CDrivetreeView::OnInitialUpdate()中的!
cwming 2003-08-20
  • 打赏
  • 举报
回复
这里有我自己的一段代码,你自己看吧。特别注意:
strInsert.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;

void CZdataproView::fillemptytree()
{
// a thread (note progressive painting in Explorer).
CTreeCtrl& cThisTree = GetTreeCtrl();//用cThisTree指针控制树的操作

// form the one and only tree root - the desktop
TV_INSERTSTRUCT strInsert;
cThisTree.SetItemImage(0,IDB_PARENT,IDB_PARENTOPEN);

// must use a selectedimage even if same
strInsert.item.mask = TVIF_TEXT |
TVIF_IMAGE |
TVIF_SELECTEDIMAGE;

// a root item - so parent is NULL
strInsert.hParent = NULL;

// index of the image in the list
strInsert.item.iImage = 3;
strInsert.item.iSelectedImage =0;
strInsert.item.pszText = (LPSTR)"数据库系统管理";
HTREEITEM hDesktop = cThisTree.InsertItem(&strInsert);
strInsert.hParent=hDesktop;
// force to "Desktop" - the real Explorer uses the
// registry-based items (like "Computer")
strInsert.item.iImage = 1;
strInsert.item.iSelectedImage = 2;
strInsert.item.pszText = (LPSTR)"ITEM";
HTREEITEM hDesktop1 = cThisTree.InsertItem(&strInsert);
strInsert.item.pszText=(LPSTR)"ObjectDescription";
HTREEITEM hDesktop2=cThisTree.InsertItem(&strInsert);
strInsert.item.pszText = (LPSTR)"SeverDescription";
HTREEITEM hDesktop3 = cThisTree.InsertItem(&strInsert);
strInsert.item.pszText = (LPSTR)"DBDescription";
HTREEITEM hDesktop4 = cThisTree.InsertItem(&strInsert);



//expand the Desktop
cThisTree.Expand( hDesktop1, TVE_EXPAND );
}

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧