CListCtrl 没有创建组
CListCtrl is not creating groups
我正在尝试通过以下代码使用 CListCtrl 进行分组:
LVGROUP lg = { 0 };
lg.cbSize = sizeof(lg);
lg.state = LVGS_NORMAL | LVGS_COLLAPSIBLE;
lg.mask = LVGF_GROUPID | LVGF_HEADER | LVGF_STATE | LVGF_ALIGN | LVGF_STATE | LVGF_DESCRIPTIONTOP | LVGF_DESCRIPTIONBOTTOM | LVGF_FOOTER | LVGF_TASK | LVGF_SUBTITLE | LVGF_SUBSET;
lg.uAlign = LVGA_HEADER_LEFT | LVGA_FOOTER_RIGHT;
LVITEM item = { 0 };
item.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_GROUPID;
item.iSubItem = 0;
item.state = 0;
item.stateMask = LVIS_SELECTED;
CString s;
lg.iGroupId = 0;
s = L"Office";
lg.pszHeader = s.GetBuffer();
lg.cchHeader = s.GetLength();
pListCtrl->InsertGroup(lg.iGroupId, &lg);
item.iGroupId = 0;
s = "Pen";
item.pszText = s.GetBuffer();
item.cchTextMax = s.GetLength();
pListCtrl->InsertItem(&item);
s = "Pencil";
item.pszText = s.GetBuffer();
item.cchTextMax = s.GetLength();
pListCtrl->InsertItem(&item);
lg.iGroupId = 1;
s = L"Workshop";
lg.pszHeader = s.GetBuffer();
lg.cchHeader = s.GetLength();
pListCtrl->InsertGroup(lg.iGroupId, &lg);
item.iGroupId = 1;
s = "Hammer";
item.pszText = s.GetBuffer();
item.cchTextMax = s.GetLength();
pListCtrl->InsertItem(&item);
s = "Drill";
item.pszText = s.GetBuffer();
item.cchTextMax = s.GetLength();
pListCtrl->InsertItem(&item);
s = "Saw";
item.pszText = s.GetBuffer();
item.cchTextMax = s.GetLength();
pListCtrl->InsertItem(&item);
但所有内容都未分组显示
我怎样才能使小组正常工作?
原来是需要manifest,我加到stdafx.h
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
我正在尝试通过以下代码使用 CListCtrl 进行分组:
LVGROUP lg = { 0 };
lg.cbSize = sizeof(lg);
lg.state = LVGS_NORMAL | LVGS_COLLAPSIBLE;
lg.mask = LVGF_GROUPID | LVGF_HEADER | LVGF_STATE | LVGF_ALIGN | LVGF_STATE | LVGF_DESCRIPTIONTOP | LVGF_DESCRIPTIONBOTTOM | LVGF_FOOTER | LVGF_TASK | LVGF_SUBTITLE | LVGF_SUBSET;
lg.uAlign = LVGA_HEADER_LEFT | LVGA_FOOTER_RIGHT;
LVITEM item = { 0 };
item.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_GROUPID;
item.iSubItem = 0;
item.state = 0;
item.stateMask = LVIS_SELECTED;
CString s;
lg.iGroupId = 0;
s = L"Office";
lg.pszHeader = s.GetBuffer();
lg.cchHeader = s.GetLength();
pListCtrl->InsertGroup(lg.iGroupId, &lg);
item.iGroupId = 0;
s = "Pen";
item.pszText = s.GetBuffer();
item.cchTextMax = s.GetLength();
pListCtrl->InsertItem(&item);
s = "Pencil";
item.pszText = s.GetBuffer();
item.cchTextMax = s.GetLength();
pListCtrl->InsertItem(&item);
lg.iGroupId = 1;
s = L"Workshop";
lg.pszHeader = s.GetBuffer();
lg.cchHeader = s.GetLength();
pListCtrl->InsertGroup(lg.iGroupId, &lg);
item.iGroupId = 1;
s = "Hammer";
item.pszText = s.GetBuffer();
item.cchTextMax = s.GetLength();
pListCtrl->InsertItem(&item);
s = "Drill";
item.pszText = s.GetBuffer();
item.cchTextMax = s.GetLength();
pListCtrl->InsertItem(&item);
s = "Saw";
item.pszText = s.GetBuffer();
item.cchTextMax = s.GetLength();
pListCtrl->InsertItem(&item);
但所有内容都未分组显示
我怎样才能使小组正常工作?
原来是需要manifest,我加到stdafx.h
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")