| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2731 人关注过本帖
标题:SDK LISTVIEW 分组问题??
只看楼主 加入收藏
wzxiaodu
Rank: 1
等 级:新手上路
帖 子:32
专家分:2
注 册:2017-8-11
结帖率:50%
收藏
已结贴  问题点数:10 回复次数:11 
SDK LISTVIEW 分组问题??
https://blog.


程序代码:
typedef struct LVGROUP {  
  UINT   cbSize;  
  UINT   mask;  
  LPWSTR pszHeader;  
  int    cchHeader;  
  LPWSTR pszFooter;  
  int    cchFooter;  
  int    iGroupId;  
  UINT   stateMask;  
  UINT   state;  
  UINT   uAlign;  
#if _WIN32_WINNT >= 0x0600  
  LPWSTR pszSubtitle;  
  UINT   cchSubtitle;  
  LPWSTR pszTask;  
  UINT   cchTask;  
  LPWSTR pszDescriptionTop;  
  UINT   cchDescriptionTop;  
  LPWSTR pszDescriptionBottom;  
  UINT   cchDescriptionBottom;  
  int    iTitleImage;  
  int    iExtendedImage;  
  int    iFirstItem;  
  UINT   cItems;  
  LPWSTR pszSubsetTitle;  
  UINT   cchSubsetTitle;  
#endif   
} LVGROUP, *PLVGROUP;  


LVGF_HEADER LVGF_GROUPID



上面结构 分组常数定义,在commctrl.h里怎么都找不到???
搜索更多相关主题的帖子: SDK LISTVIEW 分组 int 结构 
2018-06-24 17:18
wzxiaodu
Rank: 1
等 级:新手上路
帖 子:32
专家分:2
注 册:2017-8-11
收藏
得分:0 
程序代码:
#include <windows.h>
#include <commctrl.h>

下面四行我加到commctrl.h里了
//#ifdef _WIN32_WINNT
//#undef _WIN32_WINNT
//#endif
//#define _WIN32_WINNT 0x0600

typedef struct LVGROUP {  
  UINT   cbSize;  
  UINT   mask;  
  LPWSTR pszHeader;  
  int    cchHeader;  
  LPWSTR pszFooter;  
  int    cchFooter;  
  int    iGroupId;  
  UINT   stateMask;  
  UINT   state;  
  UINT   uAlign;  
#if _WIN32_WINNT >= 0x0600  
  LPWSTR pszSubtitle;  
  UINT   cchSubtitle;  
  LPWSTR pszTask;  
  UINT   cchTask;  
  LPWSTR pszDescriptionTop;  
  UINT   cchDescriptionTop;  
  LPWSTR pszDescriptionBottom;  
  UINT   cchDescriptionBottom;  
  int    iTitleImage;  
  int    iExtendedImage;  
  int    iFirstItem;  
  UINT   cItems;  
  LPWSTR pszSubsetTitle;  
  UINT   cchSubsetTitle;  
#endif   
} LVGROUP, *PLVGROUP;

#define LVGROUP_V5_SIZE CCSIZEOF_STRUCT(LVGROUP, uAlign)

#define LVGF_HEADER  0x00000001
#define LVGF_GROUPID 0x00000010

HWND listview1;
LVCOLUMN list1; 
LVITEM item1; 
                 
void centerWindows(HWND hwnd)
{
    int scrWidth,scrHeight;
    RECT rect;
    scrWidth=GetSystemMetrics(SM_CXSCREEN);
    scrHeight=GetSystemMetrics(SM_CYSCREEN);
    GetWindowRect(hwnd,&rect);
    SetWindowPos(hwnd,HWND_TOP,(scrWidth-rect.right+rect.left)/2,(scrHeight-rect.bottom+rect.top)/2,rect.right-rect.left,rect.bottom-rect.top,SWP_SHOWWINDOW);
}

/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
TCHAR szClassName[] = TEXT("WindowsApp");

int WINAPI
WinMain (HINSTANCE hThisInstance,
         HINSTANCE hPrevInstance,
         LPSTR lpszArgument,
         int nFunsterStil)

{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL; //MAKEINTRESOURCE (IDC_TEST1);
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default color as the background of the window */
    wincl.hbrBackground = (HBRUSH)(COLOR_WINDOW);

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           TEXT("SDK_LISTVIEW_GROUP"),         /* Title Text */
         //  WS_OVERLAPPEDWINDOW, /* default window */
           WS_OVERLAPPED|WS_SYSMENU|WS_MINIMIZEBOX,//|WS_THICKFRAME, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,                               /* where the window ends up on the screen */
           800,       /* The programs width */
           500,                     /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );
//SetWindowLong(hwnd, GWL_STYLE, WS_OVERLAPPED | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);  
    /* Make the window visible on the screen */
    centerWindows(hwnd);
    ShowWindow (hwnd, nFunsterStil);
    UpdateWindow(hwnd);
    
    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }
    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}


/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK
WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    INITCOMMONCONTROLSEX icex; // Ensure that the common control DLL is loaded.
    
    switch (message)        /* handle the messages */
    {
    //构建窗体时
        case WM_CREATE:
        
            icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
            icex.dwICC  = ICC_LISTVIEW_CLASSES;
            InitCommonControlsEx(&icex);

            //创建listview 
            listview1 = CreateWindowEx(WS_EX_STATICEDGE, 
                        WC_LISTVIEW,
                        NULL, WS_BORDER|WS_CHILD|WS_VISIBLE|LVS_REPORT|LVS_SINGLESEL|LVS_NOSORTHEADER|LVS_SHOWSELALWAYS, 
                        5, 5, 780, 460, 
                        hwnd, NULL, NULL, NULL);  
            ListView_SetExtendedListViewStyle(listview1, LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);//设置listview扩展风格
            ListView_EnableGroupView(listview1, TRUE);//启用分组支持  

            LVGROUP group1;  
            group1.cbSize = LVGROUP_V5_SIZE;  
            group1.mask = LVGF_HEADER | LVGF_GROUPID;  
            group1.pszHeader = (LPWSTR)("组1");  
            group1.iGroupId = 0;  
            ListView_InsertGroup(listview1, -1, &group1);  
              
            group1.pszHeader = (LPWSTR)("组2 - Hello World");  
            group1.iGroupId = 1;  
            ListView_InsertGroup(listview1, -1, &group1);  
              
            //内存清零  
            RtlZeroMemory(&list1, sizeof(LVCOLUMN));  
            RtlZeroMemory(&item1, sizeof(LVITEM));  
              
            //创建列  
            list1.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT;//掩码  
            list1.fmt = LVCFMT_LEFT;//左对齐  
            list1.cx = 100;//列宽  
            list1.pszText = TEXT("列1");  
            ListView_InsertColumn(listview1, 0, &list1);//创建列  
            list1.pszText = TEXT("list2");  
            list1.cx = 200;  
            ListView_InsertColumn(listview1, 1, &list1);
            list1.pszText = TEXT("hello world");  
            ListView_InsertColumn(listview1, 2, &list1);
            list1.pszText = TEXT("happy");  
            ListView_InsertColumn(listview1, 3, &list1);
              
            //创建项目  
            item1.mask = LVIF_TEXT | LVIF_GROUPID;  
            item1.pszText = TEXT("项目");  
            item1.iItem = 0;//项目号  
            item1.iGroupId = 0;  
            ListView_InsertItem(listview1, &item1);  
            item1.iItem = 1;  
            ListView_InsertItem(listview1, &item1); 
            item1.pszText = TEXT("item 3");  
            item1.iItem = 2;  
            ListView_InsertItem(listview1, &item1);  
            item1.pszText = TEXT("第四个");  
            item1.iItem = 3;  
            ListView_InsertItem(listview1, &item1); 
              
            item1.iGroupId = 1;  
            item1.pszText = TEXT("我在组2内");  
            item1.iItem = 4;   
            ListView_InsertItem(listview1, &item1); 
            item1.pszText = TEXT("item 5");  
            item1.iItem = 2;  
            ListView_InsertItem(listview1, &item1); 
              
            //创建子项目  
            item1.mask = LVIF_TEXT;  
            item1.iItem = 1;  
            item1.iSubItem = 1; 
            item1.pszText = TEXT("子项目");  
            ListView_SetItem(listview1, &item1); 
            item1.iItem = 1;  
            item1.iSubItem = 2;  
            item1.pszText = TEXT("子项目");  
            ListView_SetItem(listview1, &item1); 
            item1.iItem = 1;  
            item1.iSubItem = 3;  
            item1.pszText = TEXT("子项目");  
            ListView_SetItem(listview1, &item1); 

            break;
        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}


图片附件: 游客没有浏览图片的权限,请 登录注册


程序能运行,但不分组!!??

[此贴子已经被作者于2018-6-25 00:43编辑过]

2018-06-25 00:21
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9025
专家分:54030
注 册:2011-1-18
收藏
得分:5 
下面四行我加到commctrl.h里了
//#ifdef _WIN32_WINNT
//#undef _WIN32_WINNT
//#endif
//#define _WIN32_WINNT 0x0600
以及
(LPWSTR)("组1")
(LPWSTR)("组2 - Hello World")
这叫什么? 掩耳盗铃,还是 指鹿为马

看看 ListView_InsertGroup 的说明 https://docs.
里面有一句 To use ListView_InsertGroup, specify Comctl32.dll version 6 in the manifest. For more information on manifests, see Enabling Visual Styles.
即你要加上
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.' "\
"version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")

2018-06-27 09:39
wzxiaodu
Rank: 1
等 级:新手上路
帖 子:32
专家分:2
注 册:2017-8-11
收藏
得分:0 
回复 3楼 rjsp
首先谢谢!

我加上 #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.' "\"version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")

还是没分组!不知是什么原因?
下面是我的代码,麻烦大神看看!(贴不了那么长的代码,就放网盘里了。)
https://pan.baidu.com/s/1i-Bk56YAgEKgIkKgW9LRRA
2018-07-02 16:44
吹水佬
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:451
帖 子:10607
专家分:43186
注 册:2014-5-20
收藏
得分:5 
控件的使用,搜一下 LISTVIEW SDK 的资料看看
2018-07-02 17:03
wzxiaodu
Rank: 1
等 级:新手上路
帖 子:32
专家分:2
注 册:2017-8-11
收藏
得分:0 
回复 5楼 吹水佬
帮我看看代码,我是用c-free5下winGW编译的。。。。。
2018-07-02 18:46
wzxiaodu
Rank: 1
等 级:新手上路
帖 子:32
专家分:2
注 册:2017-8-11
收藏
得分:0 
winGW里的 commctrl.h 好像不全。。。。。。
2018-07-02 18:48
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9025
专家分:54030
注 册:2011-1-18
收藏
得分:0 
以下是引用wzxiaodu在2018-7-2 16:44:02的发言:

首先谢谢!
 
我加上 #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.' "\"version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
 
还是没分组!不知是什么原因?
下面是我的代码,麻烦大神看看!(贴不了那么长的代码,就放网盘里了。)

将我在3楼说的两点改掉就行了,但看你在4楼给出的代码,都没改呀。

LPCSTR a = "abc";
LPCWSTR b = L"abc";
LPCTSTR c = TEXT("abc");
不是你用强制转化就能变为正确对象的

#pragma comment(linker,"abc"\
   "def")
不等于 #pragma comment(linker,"abc"\"def")
等同于 #pragma comment(linker,"abcdef")
2018-07-03 08:58
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9025
专家分:54030
注 册:2011-1-18
收藏
得分:0 
补充一下你在3楼给出的代码,修改错误后的运行图
图片附件: 游客没有浏览图片的权限,请 登录注册

2018-07-03 09:01
wzxiaodu
Rank: 1
等 级:新手上路
帖 子:32
专家分:2
注 册:2017-8-11
收藏
得分:0 
回复 9楼 rjsp
老大,现在才来回复,不好意思。

你能不能把你的修改好的文件发给我。
还有,你是用什么编译的?是什么操作系统?
我是win7 x64系统,IE11,winGW编译!(不知道有没有关系)

谢谢!大神。。
2018-07-21 19:03
快速回复:SDK LISTVIEW 分组问题??
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.046901 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved