关于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;
}