首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

请教对话框不用树控件//不能显示树结构吗?一个继承的CTreeView类

2012-11-18 
请问对话框不用树控件//不能显示树结构吗?一个继承的CTreeView类如大人所见~[解决办法]给个SDK的例子:HWND

请问对话框不用树控件//不能显示树结构吗?一个继承的CTreeView类
如大人所见~

[解决办法]
给个SDK的例子:
HWND CreateTreeView (HWND hWndParent)
{
RECT rcl; // A rectangle for setting the size of the window.
HBITMAP hBmp; // The handle to a bitmap.
HIMAGELIST hIml; // The handle to the image list.

// Get the size and position of the parent window.
GetClientRect(hWndParent, &rcl);
// Create 2 trees 
hTree1 = CreateWindowEx(0L,WC_TREEVIEW,"Tree1",
WS_VISIBLE | WS_CHILD | WS_DLGFRAME | WS_CAPTION | TVS_HASLINES |
TVS_HASBUTTONS | TVS_LINESATROOT,
0, 0,
(rcl.right - rcl.left)/2, (rcl.bottom - rcl.top),
hWndParent,
(HMENU) ID_TREEVIEW1,
hInst,
NULL);
//
hTree2 = CreateWindowEx(0L,WC_TREEVIEW,"Tree2",
WS_VISIBLE | WS_CHILD | WS_DLGFRAME | WS_CAPTION | TVS_HASLINES |
TVS_HASBUTTONS | TVS_LINESATROOT,
(rcl.right - rcl.left)/2, 0,
(rcl.right - rcl.left)/2, (rcl.bottom - rcl.top),
hWndParent,
(HMENU) ID_TREEVIEW2,
hInst,
NULL );
// First, create the image list we will need.
hIml = ImageList_Create(BITMAP_WIDTH, BITMAP_HEIGHT,ILC_COLOR4,NUM_BITMAPS,1);
// Load the bitmaps and add them to the image lists.
hBmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP1));
ImageList_Add(hIml, hBmp, NULL);

hBmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP2));
ImageList_Add(hIml, hBmp, NULL);

hBmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP3));
ImageList_Add(hIml, hBmp, NULL);

hBmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP4));
ImageList_Add(hIml, hBmp, NULL);
// Associate the image list with the tree.
TreeView_SetImageList(hTree1, hIml, TVSIL_NORMAL);
TreeView_SetImageList(hTree2, hIml, TVSIL_NORMAL);
//
return (hTree1);
}
//
关键是:
hTree1 = CreateWindowEx(0L,WC_TREEVIEW,"Tree1",
WS_VISIBLE | WS_CHILD | WS_DLGFRAME | WS_CAPTION | TVS_HASLINES |
TVS_HASBUTTONS | TVS_LINESATROOT,
0, 0,
(rcl.right - rcl.left)/2, (rcl.bottom - rcl.top),
hWndParent,
(HMENU) ID_TREEVIEW1,
hInst,
NULL);

就是Create时要给定位置。(以后还可以MoveWindow)
不过MFC对话框一般用CTreeCtrl就行了,为什么要用CTreeView (他就是多了个 Title)
在资源中拖一个不是容易些

热点排行