C++ win32 列表视图列
C++ win32 ListView columns
我的代码有问题。首先,此代码的本质是使用 win32 创建一个包含一些列的列表视图。
问题是当我尝试向我的 ListView 添加列并尝试显示它时,它不会向我显示列。这是我的代码,感谢您的任何帮助。
HWND function::CreateListView (HWND hwndParent)
{
INITCOMMONCONTROLSEX icex; // Structure for control initialization.
icex.dwICC = ICC_LISTVIEW_CLASSES;
InitCommonControlsEx(&icex);
RECT rcClient;
// The parent window's client area.
GetClientRect (hwndParent, &rcClient);
HWND hWndListView = CreateWindow(WC_LISTVIEW, "ViewList",WS_BORDER| WS_CHILD | LVS_REPORT | LVS_EDITLABELS,500,300,300,300,hwndParent,NULL,hInst,NULL);
return (hWndListView);
}
VOID function::SetView(HWND hWndListView, DWORD dwView)
{
// Retrieve the current window style.
DWORD dwStyle = GetWindowLong(hWndListView, GWL_STYLE);
// Set the window style only if the view bits changed.
if ((dwStyle & LVS_TYPEMASK) != dwView)
{
SetWindowLong(hWndListView,
GWL_STYLE,
(dwStyle & ~LVS_TYPEMASK) | dwView);
} // Logical OR'ing of dwView with the result of
}
BOOL InitListViewColumns(HWND hWndListView)
{
char szText[256] ="test"; // Temporary buffer.
LVCOLUMN lvc;
int iCol;
// Initialize the LVCOLUMN structure.
// The mask specifies that the format, width, text,
// and subitem members of the structure are valid.
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM|LVS_REPORT;
// Add the columns.
for (iCol = 0; iCol < C_COLUMNS; iCol++)
{
lvc.iSubItem = iCol;
lvc.pszText = "LOL";
lvc.cx = 100; // Width of column in pixels.
if ( iCol < 2 )
lvc.fmt = LVCFMT_LEFT; // Left-aligned column.
else
lvc.fmt = LVCFMT_RIGHT; // Right-aligned column.
// Load the names of the column headings from the string resources.
LoadString(hInst,iCol,szText, sizeof(szText)/sizeof(szText[0]));
// Insert the columns into the list view.
if (ListView_InsertColumn(hWndListView, iCol, &lvc) == -1)
return FALSE;
}
return TRUE;
}
在调用CreateWindow
创建列表视图时,您忘记指定WS_VISIBLE
样式。列表视图和列在那里,只是不可见。
您传递给LoadString
的缓冲区永远不会使用,因为您从未设置lvc.pszText = szText
因此所有列都命名为"LOL"。
:我的答案适用于使用注释中的修复程序编辑后的代码。LVS_REPORT仍然不是一个有效的 LVCF_* 标志,但由于它具有与 LVCF_FMT 相同的值,因此在此特定代码中没有害处,但仍应删除,因为代码在技术上不正确。
相关文章:
- 如何维护资源管理器项目视图中当前可见的项目列表
- 列表视图更改选择颜色
- Qt - QVector 和模型视图 - 从列表视图获取自定义类的最佳方法是什么?
- 列表视图项的替代颜色
- 如何将 QString 的 QList 分配给列表视图?
- 如何修复列表视图中的错误?,封装控件时无法选择任何项
- 如何在 c++ 中从列表视图中获取值
- Qml 列表视图在重置模型时保留视图
- 创建列表视图后无法更改列表视图中的列宽
- 如何在调整列表视图大小时将标题宽度设置为等于其列表视图控件宽度
- 如何更改列表视图的边框颜色
- Qt:将 c++ 中的列表连接到 QML 中的列表视图
- 如何绑定到列表视图的 OnItemSelectionChanged
- 列表视图最初不显示数据
- 从C++访问列表视图委托的文本
- LVM_GETNEXTITEM在列表视图中找不到项目
- UWP 列表视图占用的高度超过可用高度
- 如何在移动列表视图中添加滚动条?并且用户只能垂直滚动特定区域
- C++ win32 列表视图列
- QML 列表视图和密钥导航 - 处理单个密钥事件