LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc; //设备环境句柄
PAINTSTRUCT ps; //存储绘图环境的相关信息
static HPEN hPen; //定义一个画笔句柄,定义为静态变量
switch (message)
{
case WM_CREATE: //创建宽度为2个像素的红色点线画笔,保存句柄到 hPen 变量
hPen = CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
break;
case WM_PAINT: //窗口绘制消息
hdc = BeginPaint(hwnd, &ps); //开始绘图并返回环境句柄
//选入画笔到设备环境
SelectObject(hdc, hPen);
//绘制三角形
MoveToEx(hdc, 150, 150, NULL);
LineTo(hdc, 200, 60);
LineTo(hdc, 250, 150);
LineTo(hdc, 150, 150);
EndPaint(hwnd, &ps); //结束绘图并释放环境句柄
return 0;
case WM_DESTROY: //窗口销毁消息
//处理 WM_DESTROY 消息时删除之前创建的一切GDI对象
DeleteObject(hPen);
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
---------------------
原文地址:https://www.cnblogs.com/ly570/p/11304706.html