我目前正在学习适用于 C++ 的 Windows API,并且正在尝试创建一个 ListView 控件。我编辑了 MSDN 文档中的源代码,但我卡住了,因为我的窗口中实际上没有显示任何 ListView 。当我创建不同的控件时,它们的显示没有问题。我使用这个函数来创建 ListView。
HWND CreateListView(HWND hwndParent)
{
INITCOMMONCONTROLSEX icex;
icex.dwICC = ICC_LISTVIEW_CLASSES;
icex.dwSize = sizeof(icex);
if(InitCommonControlsEx(&icex) == FALSE) MessageBox(NULL,L"Initiation of common controls failed",L"Fail", MB_OK);
RECT rcClient;
GetClientRect(hwndParent, &rcClient);
HWND hWndListView = CreateWindow(WC_LISTVIEW,
L"",
WS_CHILD | LVS_REPORT | LVS_EDITLABELS,
0, 0,
rcClient.right - rcClient.left,
rcClient.bottom - rcClient.top,
hwndParent,
(HMENU)IDM_DATABAZA_LIST,
hInst,
NULL);
return (hWndListView);
}
ListView 创建没有问题,但它没有显示在窗口中。这里可能是什么问题?
最佳答案
添加 WS_VISIBLE
标志:
HWND hWndListView = CreateWindow(WC_LISTVIEW, L"",
WS_VISIBLE|WS_CHILD|LVS_REPORT|LVS_EDITLABELS,...)
或使用 ShowWindow(hWndListView, SW_SHOW)
或 SetWindowPos(hWndListView,...,SWP_NOZORDER|SWP_SHOWWINDOW);
并添加错误检查
if (!hWndListView)
{
OutputDebugStringW(L"error\n");
return NULL;
}
关于c++ - Windows C++ API ListView 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37460277/