目录
树形视图(TreeView)
使用场景
消息处理
示例代码
case WM_INITDIALOG: { // 初始环境 INITCOMMONCONTROLSEX initComm = { 0 }; initComm.dwSize = sizeof(INITCOMMONCONTROLSEX); initComm.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&initComm); // 初始控件 HWND hTree = GetDlgItem(hwnd, IDC_TREE2); // 插入根节点 TVINSERTSTRUCT tvi = { 0 }; tvi.hParent = TVI_ROOT; tvi.hInsertAfter = TVI_LAST; tvi.item.mask = TVIF_TEXT; tvi.item.pszText = (LPWSTR)TEXT("计算机"); HTREEITEM hRoot = TreeView_InsertItem(hTree, &tvi); // 插入子节点 tvi.hParent = hRoot; tvi.item.pszText = (LPWSTR)TEXT("本地磁盘(C)"); HTREEITEM hC = TreeView_InsertItem(hTree, &tvi); tvi.hParent = hC; tvi.item.pszText = (LPWSTR)TEXT("Windows"); TreeView_InsertItem(hTree, &tvi); tvi.hParent = hRoot; tvi.item.pszText = (LPWSTR)TEXT("本地磁盘(D)"); HTREEITEM hD = TreeView_InsertItem(hTree, &tvi); tvi.hParent = hD; tvi.item.pszText = (LPWSTR)TEXT("Debug"); TreeView_InsertItem(hTree, &tvi); return TRUE; }