Treeview control (加入图标)运用

来源:互联网 发布:mac远程桌面在哪里 编辑:程序博客网 时间:2024/04/29 21:34
case WM_INITDIALOG:// 创建TreeView控件INITCOMMONCONTROLSEX icc = {sizeof(icc), ICC_TREEVIEW_CLASSES};if(InitCommonControlsEx(&icc)){HWND hTreeView = CreateWindow(_T("SysTreeView32"),_T("TreeView"),WS_CHILD | WS_VISIBLE | WS_BORDER | TVS_FULLROWSELECT | TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT,5, 5, 250, 700, hDlg, (HMENU)0x11,hInstX,NULL);TVINSERTSTRUCT ti = {0};HTREEITEM hParent,Parent;HIMAGELIST himl;   //加入图标himl=ImageList_Create(16,16,ILC_COLOR32,1,12);ImageList_Add(himl,LoadBitmap(hInstX,MAKEINTRESOURCE(IDB_TREE)),NULL);SendMessage(hTreeView,TVM_SETIMAGELIST,TVSIL_NORMAL,(LPARAM)himl);ti.item.mask=TVIF_TEXT|TCIF_IMAGE|TVIF_SELECTEDIMAGE;ti.item.iImage=4;ti.item.iSelectedImage=4;ti.item.pszText=_T("127.0.0.1: C0400");ti.hParent=NULL;ti.hInsertAfter=TVI_ROOT;Parent=hParent=(HTREEITEM)SendMessage(hTreeView,TVM_INSERTITEM,0,(LPARAM)&ti);ti.hParent=hParent;ti.hInsertAfter=TVI_LAST;//TVI_LAST表示节点添加在最后ti.item.iImage=5;ti.item.iSelectedImage=5;ti.item.pszText=_T("Slot0");hParent=(HTREEITEM)SendMessage(hTreeView,TVM_INSERTITEM,0,(LPARAM)&ti);ti.hParent=hParent;ti.hInsertAfter=TVI_LAST;//TVI_LAST表示节点添加在最后ti.item.iImage=3;ti.item.iSelectedImage=3;ti.item.pszText="port0";SendMessage(hTreeView,TVM_INSERTITEM,0,(LPARAM)&ti);ti.hParent=hParent;ti.hInsertAfter=TVI_LAST;//TVI_LAST表示节点添加在最后ti.item.iImage=3;ti.item.iSelectedImage=3;ti.item.pszText="port1";SendMessage(hTreeView,TVM_INSERTITEM,0,(LPARAM)&ti);ti.hParent=hParent;ti.hInsertAfter=TVI_LAST;//TVI_LAST表示节点添加在最后ti.item.iImage=3;ti.item.iSelectedImage=3;ti.item.pszText="port2";SendMessage(hTreeView,TVM_INSERTITEM,0,(LPARAM)&ti);ti.hParent=hParent;ti.hInsertAfter=TVI_LAST;//TVI_LAST表示节点添加在最后ti.item.iImage=3;ti.item.iSelectedImage=3;ti.item.pszText="port3";SendMessage(hTreeView,TVM_INSERTITEM,0,(LPARAM)&ti);ti.hParent=Parent;ti.hInsertAfter=TVI_LAST;//TVI_LAST表示节点添加在最后ti.item.iImage=5;ti.item.iSelectedImage=5;ti.item.pszText=_T("Slot1");hParent=(HTREEITEM)SendMessage(hTreeView,TVM_INSERTITEM,0,(LPARAM)&ti);ti.hParent=hParent;ti.hInsertAfter=TVI_LAST;//TVI_LAST表示节点添加在最后ti.item.iImage=3;ti.item.iSelectedImage=3;ti.item.pszText="port0";SendMessage(hTreeView,TVM_INSERTITEM,0,(LPARAM)&ti);ti.hParent=hParent;ti.hInsertAfter=TVI_LAST;//TVI_LAST表示节点添加在最后ti.item.iImage=3;ti.item.iSelectedImage=3;ti.item.pszText="port1";SendMessage(hTreeView,TVM_INSERTITEM,0,(LPARAM)&ti);ti.hParent=hParent;ti.hInsertAfter=TVI_LAST;//TVI_LAST表示节点添加在最后ti.item.iImage=3;ti.item.iSelectedImage=3;ti.item.pszText="port2";SendMessage(hTreeView,TVM_INSERTITEM,0,(LPARAM)&ti);ti.hParent=hParent;ti.hInsertAfter=TVI_LAST;//TVI_LAST表示节点添加在最后ti.item.iImage=3;ti.item.iSelectedImage=3;ti.item.pszText="port3";SendMessage(hTreeView,TVM_INSERTITEM,0,(LPARAM)&ti);

 结果如下:


 

原创粉丝点击