CListCtrl不创建组

时间:2017-03-30 12:59:09

标签: visual-c++ mfc clistctrl

我试图通过以下代码使用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);

但是所有内容都显示为未分组

ungrouped clistctrl

如何让小组按预期工作?

1 个答案:

答案 0 :(得分:0)

事实证明需要一个清单,我将其添加到stdafx.h

#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")

enter image description here