树型控件

今天开始到了树型控件。本人实在是陌生。查了资料算是吧控件做成功。帖点:

m_treectrl.SetItemHeight(20);
 TV_INSERTSTRUCT  treectrl;
 //TVS_HASBUTTONS treectrl;
 treectrl.hParent = TVI_ROOT; //hParent = 父项目句柄。如果该值为TVI_ROOT value或NULL,该项目插在树型视图根部。
                              //hInsertAfter = 应该插入在起后面项目句柄或下面值:
        //TVI_FIRST ==> 插在列表头部。
                          //TVI_LAST ==> 插在列表尾部。
                          //TVI_SORT ==> 按字母顺序插入。

 treectrl.hInsertAfter = TVI_LAST;
 treectrl.item.mask = TVIF_TEXT|TVIF_PARAM;
 m_TreeBootImage.Create ( IDB_BITMAP1,20,1,ILC_COLOR8);
 m_treectrl.SetImageList ( &m_TreeBootImage,TVSIL_NORMAL );
 m_treectrl.SetTextColor (RGB(255,0,0));
 treectrl.item.pszText = "迅雷";
 treectrl.item.lParam = 0;//lparam指向NMHDR结构体指针。有一些控件可能传递一个指向更大一点结构体指针。但该结构体必须保证它第一个成员变量是一个NMHDR型变量。这样,您在处理lParam变量时,至少可以得到一个NMHDR型变量。
 HTREEITEM htreeitem1 = m_treectrl.InsertItem(&treectrl);
 treectrl.hParent = htreeitem1;

 treectrl.item.pszText = "正在下载";
 

 treectrl.item.lParam = 1;
 m_treectrl.InsertItem(&treectrl);
 treectrl.item.pszText = "已经下载";
 treectrl.item.lParam = 2;
 m_treectrl.InsertItem(&treectrl);

 treectrl.hParent = TVI_ROOT;

 //treectrl.hInsertAfter = TVI_FIRST;
 treectrl.item.pszText = "狗狗影视排行";
 treectrl.item.lParam = 0;
 HTREEITEM htreeitem2 = m_treectrl.InsertItem(&treectrl);
 treectrl.hParent = htreeitem2;
 treectrl.item.pszText = "最新电影";
 treectrl.item.lParam = 1;
 m_treectrl.InsertItem(&treectrl);
 treectrl.item.pszText = "热门电影";
 treectrl.item.lParam = 2;
 m_treectrl.InsertItem(&treectrl);
 treectrl.item.pszText = "热门聚集";
 treectrl.item.lParam = 3;
 m_treectrl.InsertItem(&treectrl);
 treectrl.item.pszText = "热门动漫";
 treectrl.item.lParam = 4;
 m_treectrl.InsertItem(&treectrl);
 treectrl.item.pszText = "更多分类";
 treectrl.item.lParam = 5;
 m_treectrl.InsertItem(&treectrl);
 treectrl.hParent = TVI_ROOT;
 treectrl.item.pszText = "迅雷听听";
 treectrl.item.lParam = 0;
 HTREEITEM htreeitem3 = m_treectrl.InsertItem(&treectrl);
 m_treectrl.Expand(htreeitem1,TVE_COLLAPSE);
 m_treectrl.Expand(htreeitem2,TVE_EXPAND);
 

树型控件还是那回事,但是要美化了。在前面加图标。
 
 //-------------------------------//
 //m_TreeBootImage.Create(16, 16, ILC_COLOR32, 0, 16);
 //CBitmap bm;
 //bm.LoadBitmap(IDB_BITMAP2); //use bitmap
 //m_ImageList.Add(&bm, RGB(0, 0, 0));
 //m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON1)); //use icon
 //m_ctrlTree.SetImageList(&m_ImageList, TVSIL_NORMAL);
 //HTREEITEM hItem = m_ctrlTree.GetRootItem();
 //m_ctrlTree.InsertItem("RootItem", 0, 1, hItem);

这点是在网上找的, //  1. 先给m_ImageList绑定2个图标资源,
 // 2. 然后用SetImageList函数与tree空间挂钩,
 // 3. 然后添加树节点。InsertItem("RootItem", 0, 1, hItem)中,0表示添加第一个图标资源,1表示第二个图标资源。
 //-----------------------------//

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值