// Assign the image lists to the list view control. ListView_SetImageList(hWndLView, himlSmall, LVSIL_SMALL); // Get the Root Folder if(SUCCEEDED(pIGWAccount->get_RootFolder(&pDIGWFolder))) { if(pDIGWFolder && SUCCEEDED(pDIGWFolder->QueryInterface(IID_IGWFolder, (void**)&pIGWFolder))) { pDIGWFolder->Release(); InsertSubFolders(pIGWFolder, hTreeItem); // Need to add the Trash folder seperatly since it is // not contained under the root folder pIGWAccount->get_Trash(&pDIGWTrash); if(pDIGWTrash && SUCCEEDED(pDIGWTrash->QueryInterface(IID_IGWTrash, (void**)&pIGWTrash))) { pDIGWTrash->Release(); pIGWTrash->get_Name(&bstrTrashName); hTreeItem = TreeView_GetRoot(hWndTView); tvis.hParent = hTreeItem; tvis.item.mask = TVIF_TEXT | TVIF_PARAM; tvis.item.pszText = FROM_OLE_STRING(bstrTrashName); SysFreeString(bstrTrashName); TreeView_InsertItem(hWndTView, &tvis); } } } // Exand the tree from root level TreeView_Expand(hWndTView, hTreeItem, TVM_EXPAND); }
common control 中有一个Treeview控件,就是一个树形控件,没不要自己去实现,直接用就行了。它是SDK的一部分。 包含commctrl.h在连接时加入comctl32.lib就行了, 建创一个TreeView控件上面有位兄弟己经说了,MSDN上也有例子,你可以看看: Tree View Controls 这篇文章讲得很详细。
CreateTreeViewIN: hWnd - Handle to parent windowNOTE: Create the tree and list view
controls for the main window
-----------------------------------------------*/
void CreateViews(HWND hWnd)
{
DIGWFolder* pDIGWFolder;
DIGWTrash* pDIGWTrash;
IGWFolder* pIGWFolder;
HTREEITEM hTreeItem = NULL;
TV_INSERTSTRUCT tvis;
HICON hiconItem;
HIMAGELIST himlSmall;
BSTR bstrTrashName; InitCommonControls(); // Create TreeView Control
hWndTView = CreateWindowEx(WS_EX_CLIENTEDGE, WC_TREEVIEW, "TreeView",
WS_VISIBLE | WS_CHILD | TVS_HASLINES | TVS_DISABLEDRAGDROP | TVS_HASBUTTONS,
1, 10, 155, 244, hWnd, (HMENU)IDC_TREEVIEW, ghInst, NULL); // Create ListView Control
hWndLView = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, "ListView",
WS_VISIBLE | WS_CHILD | LVS_REPORT,
160, 10, 434, 244, hWnd, (HMENU)IDC_LISTVIEW, ghInst, NULL); InitLViewColumns();
himlSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON),
GetSystemMetrics(SM_CYSMICON), TRUE, 2, 2);
hiconItem = LoadIcon(ghInst, MAKEINTRESOURCE(IDI_OPENED));
ImageList_AddIcon(himlSmall, hiconItem);
DeleteObject(hiconItem); hiconItem = LoadIcon(ghInst, MAKEINTRESOURCE(IDI_CLOSED));
ImageList_AddIcon(himlSmall, hiconItem);
DeleteObject(hiconItem);
// Assign the image lists to the list view control.
ListView_SetImageList(hWndLView, himlSmall, LVSIL_SMALL);
// Get the Root Folder
if(SUCCEEDED(pIGWAccount->get_RootFolder(&pDIGWFolder))) {
if(pDIGWFolder && SUCCEEDED(pDIGWFolder->QueryInterface(IID_IGWFolder, (void**)&pIGWFolder))) {
pDIGWFolder->Release();
InsertSubFolders(pIGWFolder, hTreeItem);
// Need to add the Trash folder seperatly since it is
// not contained under the root folder pIGWAccount->get_Trash(&pDIGWTrash); if(pDIGWTrash && SUCCEEDED(pDIGWTrash->QueryInterface(IID_IGWTrash, (void**)&pIGWTrash))) {
pDIGWTrash->Release(); pIGWTrash->get_Name(&bstrTrashName); hTreeItem = TreeView_GetRoot(hWndTView); tvis.hParent = hTreeItem;
tvis.item.mask = TVIF_TEXT | TVIF_PARAM;
tvis.item.pszText = FROM_OLE_STRING(bstrTrashName); SysFreeString(bstrTrashName); TreeView_InsertItem(hWndTView, &tvis);
}
}
} // Exand the tree from root level
TreeView_Expand(hWndTView, hTreeItem, TVM_EXPAND);
}
包含commctrl.h在连接时加入comctl32.lib就行了,
建创一个TreeView控件上面有位兄弟己经说了,MSDN上也有例子,你可以看看:
Tree View Controls
这篇文章讲得很详细。
创建后可向它发送消息来操纵它,可通过wm_notify消息得到它的能知消息.