/* ************************************
* HWND CreateTreeView(HWND hwndParent, LPSTR szWindowName)
* 功能	创建一个Tree View控件,并调用InitTreeViewItems增加若干个节点
* 参数	hwndParent,父窗口句柄
*			szWindowName,窗口标题
* 返回值	创建的窗口句柄
**************************************/
HWND CreateTreeView(HWND hwndParent, LPSTR szWindowName)
{
	HWND hwndTV;
	// 创建Tree View
	hwndTV = CreateWindowEx(0,
		WC_TREEVIEW,		//	Tree View控制窗口类
		szWindowName,	// 窗口的标题
		// 窗口样式 :可见,子窗口,可改变大小,具体窗口标题
		WS_VISIBLE | WS_CHILD | WS_SIZEBOX |  WS_TILED |
		// 附加Tree View样式
		TVS_HASBUTTONS |TVS_LINESATROOT , 
		// 默认大小和位置,后面使用SetWindows函数设置
		CW_USEDEFAULT,	
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		hwndParent,		// 父窗口句柄
		(HMENU)NULL,	// 没有菜单
		hinst,		// 应用程序实例
		NULL);		// 没有图标

	// 初始化 Image List 和节点,
	if (!InitTreeViewImageLists(hwndTV) ||
		!InitTreeViewItems(hwndTV))
	{
		DestroyWindow(hwndTV);
		return NULL;
	}
	return hwndTV;
}
Esempio n. 2
0
/*
 * CreateTreeView - creates a tree view control.
 * Returns the handle to the new control if successful, or NULL otherwise.
 * hwndParent - handle to the control's parent window.
 */
HWND CreateTreeView(HWND hwndParent, LPWSTR pHostName, UINT id)
{
    RECT rcClient;
    HWND hwndTV;
    WCHAR TreeView[] = {'T','r','e','e',' ','V','i','e','w',0};

    /* Get the dimensions of the parent window's client area, and create the tree view control.  */
    GetClientRect(hwndParent, &rcClient);
    hwndTV = CreateWindowExW(WS_EX_CLIENTEDGE, WC_TREEVIEWW, TreeView,
                            WS_VISIBLE | WS_CHILD | WS_TABSTOP | TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT | TVS_EDITLABELS,
                            0, 0, rcClient.right, rcClient.bottom,
                            hwndParent, ULongToHandle(id), hInst, NULL);
    SendMessageW(hwndTV, TVM_SETUNICODEFORMAT, TRUE, 0);
    /* Initialize the image list, and add items to the control.  */
    if (!InitTreeViewImageLists(hwndTV) || !InitTreeViewItems(hwndTV, pHostName)) {
        DestroyWindow(hwndTV);
        return NULL;
    }
    return hwndTV;
}