| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 809 人关注过本帖
标题:关于win32 下list控件的用法高手请进
只看楼主 加入收藏
lixingying
Rank: 2
等 级:论坛游民
帖 子:45
专家分:27
注 册:2010-8-3
结帖率:40%
收藏
已结贴  问题点数:20 回复次数:3 
关于win32 下list控件的用法高手请进
#include <windowsx.h>
#include"Hdingyi.h"
#include"Hfun.h"
#include<windows.h>
HWND hList;
int WINAPI WinMain(
                   HINSTANCE hInstance,  // handle to current instance
                   HINSTANCE hPrevInstance,  // handle to previous instance
                   LPSTR lpCmdLine,      // pointer to command line
                   int nCmdShow          // show state of window
                   )
{
    hwnd=CreateDialog(hInstance,MAKEINTRESOURCE(IDD_DIALOG),NULL,(DLGPROC )WindowProc);//主对话框
    ShowWindow(hwnd,SW_SHOWNORMAL);
    UpdateWindow(hwnd);
    SendMessage(hwnd, WM_SETICON, (WPARAM)TRUE, (LPARAM)LoadIcon(GetModuleHandle(NULL), (LPCTSTR)IDI_ICON1));//添加窗口小图标
      MSG msg;
    while(GetMessage(&msg,NULL,0,0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return 0;
}
LRESULT CALLBACK WindowProc(
                            HWND hwnd,      // handle to window
                            UINT uMsg,      // message identifier
                            WPARAM wParam,  // first message parameter
                            LPARAM lParam   // second message parameter
                            )
{
    switch(uMsg)
    {
     case WM_COMMAND:
        {
            int id=wParam;
            switch(id)
            {
            case ID_MENUCHAXUN:
                {
                    //HWND hwndLs=GetDlgItem(hwnd,IDC_LIST1);
                    //    char str[256]="编号  体重  年龄";
                    //    ListBox_AddString(hwndLs,str);
                    //ShowWindow(hwndcxz,SW_SHOWNORMAL);
                    //UpdateWindow(hwndcxz);
                    RECT rc;
                    GetClientRect(hwnd,&rc);
                    InitCommonControls();
                    hList = CreateWindowEx(LVS_SORTASCENDING , TEXT("SysListView32"), NULL, LVS_REPORT | WS_CHILD | WS_VISIBLE|LVS_SORTDESCENDING, 0, 0,
                        rc.right,rc.bottom, hwnd, NULL, GetModuleHandle(NULL), NULL);
                    ShowWindow(hList,SW_SHOWNORMAL);
                    
                    //GetModuleHandle(NULL)//是获取当前应用程序的句柄
                //    ListView_SetExtendedListViewStyle(hList,LVS_REPORT|LVS_EX_HEADERDRAGDROP|LVS_EX_FLATSB|LVM_SETITEM );//设置扩展风格并画出网格线
                    ListView_SetExtendedListViewStyle(hList,LVS_REPORT );//设置扩展风格并画出网格线
               
                    LV_COLUMN lvc;
                    
                    lvc.mask = LVCF_TEXT | LVCF_WIDTH;
                    lvc.pszText = "编号";
                    lvc.cx = 120;
                    SendMessage(hList, LVM_INSERTCOLUMN, 0, (long)&lvc);
                    lvc.pszText = "性别";
                    lvc.cx = 120;
                    SendMessage(hList, LVM_INSERTCOLUMN, 1, (long)&lvc);
                    lvc.pszText = "年龄";
                    lvc.cx = 150;
                    SendMessage(hList, LVM_INSERTCOLUMN, 2, (long)&lvc);
                    lvc.pszText = "出生日期";
                    lvc.cx = 150;
                    SendMessage(hList, LVM_INSERTCOLUMN, 3, (long)&lvc);
                    lvc.pszText = "体重";
                    lvc.cx = 60;
                    SendMessage(hList, LVM_INSERTCOLUMN, 4, (long)&lvc);
                    /*SendMessage(hList, LVM_SETTEXTCOLOR, 0, RGB(255, 255, 0));
                    SendMessage(hList, LVM_SETBKCOLOR, 0, RGB(0, 100, 0));
                     SendMessage(hList, LVM_SETTEXTBKCOLOR, 0, RGB(0, 0, 0));*/ //设置编辑框颜色
                   //这里是给表格控件添加数据但是总是添加不上
                    char str[20];
                    wsprintf(str,"01001");
                    LVITEMA lvi;
                    memset(&lvi,0,sizeof(lvi));
                    lvi.iItem=1;
                    lvi.iSubItem=1;//这里调试结果不正常
图片附件: 游客没有浏览图片的权限,请 登录注册

                     lvi.pszText=str;
                    SendMessage(hList,  LVM_SETITEM, 0, (long)&lvi);
                    SendMessage(hList, LVM_SETTEXTCOLOR, 0, RGB(255, 255, 0));

                    }
              }
        break;
     case WM_CLOSE:
        DestroyWindow(hwnd);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return 0;
    }
    return 0;
}
搜索更多相关主题的帖子: previous command current include window 
2013-07-08 01:16
yuccn
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:何方
等 级:版主
威 望:167
帖 子:6815
专家分:42393
注 册:2010-12-16
收藏
得分:10 
如果是mfc 请免谈! 呵呵


笑而不语

我行我乐
公众号:逻辑客栈
我的博客:
https://blog.yuccn. net
2013-07-08 08:13
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9025
专家分:54030
注 册:2011-1-18
收藏
得分:10 
以下是引用yuccn在2013-7-8 08:13:48的发言:

如果是mfc 请免谈! 呵呵


笑而不语

^_^ 确实
2013-07-08 08:24
lixingying
Rank: 2
等 级:论坛游民
帖 子:45
专家分:27
注 册:2010-8-3
收藏
得分:0 
有什么好笑的
2013-07-08 10:28
快速回复:关于win32 下list控件的用法高手请进
数据加载中...
 
   



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

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