CListCtrl is not creating groups

拜拜、爱过 提交于 2019-12-12 02:25:58

问题


I am trying to make groupings using a CListCtrl trough the following code:

        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);

but everything is shown ungrouped

How can I make the groups work as they should?


回答1:


It turns out there is the need of a manifest, which I added to stdafx.h

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



来源:https://stackoverflow.com/questions/43118614/clistctrl-is-not-creating-groups

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!