70,020
社区成员




#include <windows.h>
#include <commctrl.h>
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = 0;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = 0;
wcex.lpszClassName = "test_list";
wcex.hIconSm = 0;
if (!RegisterClassEx(&wcex))
return FALSE;
HWND hWnd = CreateWindow("test_list", "test_list", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
return FALSE;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int) msg.wParam;
}
BOOL OnCreate(HWND hWnd)
{
HWND hButton = CreateWindow("syslistview32", "", WS_VISIBLE|WS_CHILD|WS_BORDER|LVS_REPORT|LVS_SHOWSELALWAYS,180,180,200,200,hWnd, NULL,NULL, NULL);// 添加数据
LVCOLUMN colmn;
LVITEM item;
ZeroMemory(&item, sizeof(LV_ITEM));
ZeroMemory(&colmn, sizeof(LV_COLUMN));
colmn.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM; // 风格
SendMessage(hButton,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_GRIDLINES);
colmn.cx = 0x28;
colmn.pszText = "进程名"; // 文字
colmn.cx = 0x42; // 后面列
SendMessage(hButton, LVM_INSERTCOLUMN, 0, (LPARAM)&colmn);
colmn.pszText = "内存使用";
SendMessage(hButton, LVM_INSERTCOLUMN, 0, (LPARAM)&colmn);
colmn.pszText = "ID";
SendMessage(hButton, LVM_INSERTCOLUMN, 0, (LPARAM)&colmn);
// 添加一些行项
item.mask = LVIF_TEXT; // 文字
item.cchTextMax = MAX_PATH; // 文字长度
item.iItem = 0;
item.iSubItem = 0;
item.pszText = "中国";
SendMessage(hButton, LVM_INSERTITEM, 0, (LPARAM)&item);
item.pszText = "日本";
SendMessage(hButton, LVM_INSERTITEM, 0, (LPARAM)&item);
item.pszText = "德国";
SendMessage(hButton, LVM_INSERTITEM, 0, (LPARAM)&item);
item.pszText = "俄国";
SendMessage(hButton, LVM_INSERTITEM, 0, (LPARAM)&item);
item.pszText = "美国";
SendMessage(hButton, LVM_INSERTITEM, 0, (LPARAM)&item);
item.pszText = "英国";
SendMessage(hButton, LVM_INSERTITEM, 0, (LPARAM)&item);
item.pszText = "法国";
SendMessage(hButton, LVM_INSERTITEM, 0, (LPARAM)&item);
//
// 把第三行第三列改成"aaa"
//
item.iSubItem = 2;
item.pszText = "aaa";
SendMessage(hButton, LVM_SETITEMTEXT, 2, (LPARAM)&item);
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_CREATE :
return OnCreate(hWnd);
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}