阶段知识整合(画笔,画刷,字体)
#include <Windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, UINT, LONG);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInst,
LPSTR lpszCmdLine,
int nCmdShow
)
{
//定义变量
MSG Msg;
HWND hwnd;
WNDCLASS wndclass;
char lpszClassName[] = "窗口";
char lpszTitle[] = "win";
//初始化窗体
wndclass.style = 0;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = NULL;
wndclass.cbWndExtra = NULL;
wndclass.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hInstance = hInstance;
wndclass.lpszClassName = lpszClassName;
wndclass.lpszMenuName = NULL;
//注册
if (!RegisterClass(&wndclass))
{
MessageBeep(0);
return FALSE;
}
hwnd = CreateWindow(
lpszClassName,
lpszTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
//显示和更新窗口
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
//消息循环
while (GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
//综合知识应用
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, UINT wParam, LONG lParam)
{
HDC hdc;
PAINTSTRUCT ps;
HPEN hpen;
HFONT hfont;
HBRUSH hbrush;
TEXTMETRIC tm;
SIZE size;
switch (message) {
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
hbrush = CreateSolidBrush(RGB(0, 255, 0));
SelectObject(hdc, hbrush);
hpen = CreatePen(PS_SOLID,3,RGB(0,255,0));
SelectObject(hdc, hpen);
MoveToEx(hdc, 123, 45,NULL);
LineTo(hdc, 123, 700);
Pie(hdc, 23, 34, 90, 87, 23, 65, 76, 4);
Rectangle(hdc, 0, 0, 200, 200);
hfont = (HFONT)GetStockObject(SYSTEM_FONT);
SelectObject(hdc, hfont);
SetBkColor(hdc, RGB(0, 23, 234));
SetTextColor(hdc, RGB(255, 0, 0));
TextOut(hdc, 0, 0, "冯是飞机交付定金", 10);
GetTextMetrics(hdc, &tm);
GetTextExtentPoint32(hdc, "fenglei", 8, &size);
TextOut(hdc,size.cx,0,"哈哈哈",6);
TextOut(hdc, 0, tm.tmHeight + tm.tmExternalLeading, "下一行是谁", 10);
DeleteObject(hfont);
DeleteObject(hpen);
DeleteObject(hbrush);
EndPaint(hwnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}