64,685
社区成员
发帖
与我相关
我的任务
分享
// win32.cpp : Defines the entry point for the application.
//
//#include "stdafx.h"
#include <windowsx.h>
#include <tchar.h>
#include <CommCtrl.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HINSTANCE hInst = NULL;
HWND hList = NULL;
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
MSG msg;
WNDCLASSEX wcex;
hInst = hInstance;
ZeroMemory(&wcex, sizeof(wcex));
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszClassName = TEXT("Win32");
RegisterClassEx(&wcex);
HWND hWnd = CreateWindow(
TEXT("Win32"),
TEXT("Win32"),
WS_OVERLAPPEDWINDOW,
500,
300,
500,
300,
NULL,
NULL,
hInstance,
NULL);
if (!hWnd)
return FALSE;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
SetTimer(hWnd, 1, 10, NULL);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int) msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_CREATE :
{
hList = CreateWindow(
TEXT("SysListView32"),
TEXT("ListView"),
WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT,
0,
0,
500,
300,
hWnd,
NULL,
hInst,
NULL);
if (hList)
{
LVCOLUMN info;
info.mask = LVCF_TEXT | LVCF_WIDTH;
info.pszText = TEXT("Column0");
info.cx = 100;
ListView_InsertColumn(hList, 0, &info);
info.mask = LVCF_TEXT | LVCF_WIDTH;
info.pszText = TEXT("Column1");
info.cx = 100;
ListView_InsertColumn(hList, 1, &info);
info.mask = LVCF_TEXT | LVCF_WIDTH;
info.pszText = TEXT("Column2");
info.cx = 100;
ListView_InsertColumn(hList, 2, &info);
info.mask = LVCF_TEXT | LVCF_WIDTH;
info.pszText = TEXT("Column3");
info.cx = 200;
ListView_InsertColumn(hList, 3, &info);
for (int i = 0; i < 4; ++i)
{
LVITEM item;
ZeroMemory(&item, sizeof(item));
item.mask = LVIF_TEXT;
item.cchTextMax = sizeof(TEXT("item"));
item.pszText = TEXT("item");
item.iItem = i;
ListView_InsertItem(hList, &item);
for (int j = 0; j < 4; ++j)
{
TCHAR text[32];
_stprintf(text, TEXT("item-%d-%d"), i, j);
ListView_SetItemText(hList, i, j, text);
}
}
}
}
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;
}