/* ************************************ * HWND CreateListView (HWND hwndParent, LPSTR szWindowName) * 功能 创建 List View * 参数 hwndParent,父窗口 * szWindowName,窗口标题 * 返回值 窗口句柄 **************************************/ HWND CreateListView (HWND hwndParent, LPSTR szWindowName) { HWND hWndListView; // 创建List View hWndListView = CreateWindow ( WC_LISTVIEW, // List View窗口类 // 窗口标题,由于未指定 WS_TILED ,这是一个无标题的窗口 szWindowName, // 窗口样式,可视,子窗口,以及List View样式 WS_VISIBLE | WS_CHILD | LVS_REPORT | LVS_EDITLABELS, // 位置和大小,创建完成后使用SetWindows设置 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwndParent, // 父窗口 NULL, hinst, NULL); // 无菜单,无图标 if (hWndListView == NULL) { return NULL; } // 初始化Image List、初始化列、加入一些项 if(InitListViewImageLists(hWndListView) && InitListViewColumns(hWndListView) && AddListViewItems(hWndListView)) { return hWndListView; } DestroyWindow(hWndListView); return FALSE; }
HWND CreateListView(HWND hwndParent, HMENU id) { RECT rcClient; HWND hwndLV; /* Get the dimensions of the parent window's client area, and create the list view control. */ GetClientRect(hwndParent, &rcClient); hwndLV = CreateWindowExW(WS_EX_CLIENTEDGE, WC_LISTVIEW, L"List View", WS_VISIBLE | WS_CHILD | WS_TABSTOP | LVS_REPORT | LVS_EDITLABELS | LVS_SHOWSELALWAYS, 0, 0, rcClient.right, rcClient.bottom, hwndParent, id, hInst, NULL); if (!hwndLV) return NULL; /* Initialize the image list, and add items to the control. */ if (!CreateListColumns(hwndLV)) goto fail; if (!InitListViewImageLists(hwndLV)) goto fail; return hwndLV; fail: DestroyWindow(hwndLV); return NULL; }