#include<windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT("MyAppWindows");
HWND hwnd = NULL;
MSG msg;
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = szAppName;
if (!RegisterClass(&wc))
{
MessageBox(NULL, TEXT("Need Windows NT!!!!"), TEXT("Error"), MB_OK);
}
hwnd = CreateWindow(szAppName, TEXT("我的窗口"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
HDC hdc;
PAINTSTRUCT ps;
//客户区宽和高
static int cxClient, cyClient;
//自定义画笔句柄和画刷句柄
HPEN hPen, hOldPen;
HBRUSH hBlueBrush, hRedBrush,hYelloBrush, hOldBrush;
//点
POINT apt[128];
switch (message)
{
case WM_SIZE:
cxClient = LOWORD(lparam);
cyClient = HIWORD(lparam);
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
//绘制辅助线:
hPen = CreatePen(PS_DOT, 1, RGB(0,0,0));
hOldPen = (HPEN)SelectObject(hdc, hPen);
MoveToEx(hdc, cxClient / 2, 0, NULL);
LineTo(hdc, cxClient/2, cyClient);
MoveToEx(hdc, 0,cyClient/2 , NULL);
LineTo(hdc, cxClient, cyClient/2);
DeleteObject(SelectObject(hdc, hOldPen));
//头(直径240)
hBlueBrush = CreateSolidBrush(RGB(0, 159, 232));
hOldBrush = (HBRUSH)SelectObject(hdc, hBlueBrush);
Ellipse(hdc, cxClient / 2 - 120, cyClient / 2 - 200, cxClient/2 + 120, cyClient / 2 + 40);
SelectObject(hdc, hOldBrush);
//脸(直径200)
Ellipse(hdc, cxClient / 2 - 100, cyClient / 2 - 160, cxClient / 2 + 100, cyClient / 2 + 40);
//鸡蛋(长60宽50)
Ellipse(hdc, cxClient / 2 - 50, cyClient / 2 - 180, cxClient / 2, cyClient / 2 - 120);
Ellipse(hdc, cxClient / 2 + 50, cyClient / 2 - 180, cxClient / 2, cyClient / 2 - 120);
hOldBrush = (HBRUSH)SelectObject(hdc, GetStockObject(BLACK_BRUSH));
Ellipse(hdc, cxClient / 2 - 20, cyClient / 2 - 160, cxClient / 2 - 5, cyClient / 2 - 140);
Ellipse(hdc, cxClient / 2 + 20, cyClient / 2 - 160, cxClient / 2 + 5, cyClient / 2 - 140);
SelectObject(hdc, GetStockObject(WHITE_BRUSH));
Ellipse(hdc, cxClient / 2 - 15, cyClient / 2 - 155, cxClient / 2 - 10, cyClient / 2 - 145);
Ellipse(hdc, cxClient / 2 + 15, cyClient / 2 - 155, cxClient / 2 + 10, cyClient / 2 - 145);
SelectObject(hdc, hOldBrush);
//鼻子
hRedBrush = CreateSolidBrush(RGB(255, 0, 0));
hOldBrush = (HBRUSH)SelectObject(hdc, hRedBrush);
Ellipse(hdc, cxClient / 2 - 10, cyClient / 2 - 135, cxClient / 2 + 10, cyClient / 2 - 115);
MoveToEx(hdc, cxClient / 2, cyClient / 2 - 115,NULL);
LineTo(hdc, cxClient / 2, cyClient / 2 - 30);
SelectObject(hdc, hOldBrush);
//嘴巴
Arc(hdc, cxClient / 2 - 70, cyClient / 2 - 120, cxClient / 2 + 70, cyClient / 2 - 30, cxClient / 2 - 60, cyClient / 2 - 50, cxClient / 2 + 60, cyClient / 2 - 50);
//胡须
MoveToEx(hdc, cxClient / 2 - 70 , cyClient / 2 - 115, NULL);
LineTo(hdc, cxClient / 2 - 20, cyClient / 2 - 100);
MoveToEx(hdc, cxClient / 2 - 80, cyClient / 2 - 85,NULL);
LineTo(hdc, cxClient / 2 - 20, cyClient / 2 - 85);
MoveToEx(hdc, cxClient / 2 - 70, cyClient / 2 - 55, NULL);
LineTo(hdc, cxClient / 2 - 20, cyClient / 2 - 70);
MoveToEx(hdc, cxClient / 2 + 70, cyClient / 2 - 115, NULL);
LineTo(hdc, cxClient / 2 + 20, cyClient / 2 - 100);
MoveToEx(hdc, cxClient / 2 + 80, cyClient / 2 - 85, NULL);
LineTo(hdc, cxClient / 2 + 20, cyClient / 2 - 85);
MoveToEx(hdc, cxClient / 2 + 70, cyClient / 2 - 55, NULL);
LineTo(hdc, cxClient / 2 + 20, cyClient / 2 - 70);
//身体
hOldBrush = (HBRUSH)SelectObject(hdc, hBlueBrush);
Rectangle(hdc, cxClient / 2 - 90, cyClient / 2, cxClient / 2 + 90, cyClient / 2 + 150);
SelectObject(hdc, hOldBrush);
//肚子
Ellipse(hdc, cxClient / 2 - 70, cyClient / 2 - 20, cxClient / 2 + 70, cyClient / 2 + 120);
hPen = CreatePen(PS_SOLID, 2, RGB(255, 255, 255));
hOldPen = (HPEN)SelectObject(hdc, hPen);
Arc(hdc, cxClient / 2 - 70, cyClient / 2 - 20, cxClient / 2 + 70, cyClient / 2 + 120, cxClient / 2 + 60, cyClient / 2 - 10, cxClient / 2 - 60, cyClient / 2 - 10);
SelectObject(hdc, hOldPen);
//项圈
hOldBrush = (HBRUSH)SelectObject(hdc, hRedBrush);
RoundRect(hdc, cxClient / 2 - 95, cyClient / 2 - 5, cxClient / 2 + 95, cyClient / 2 + 10, 20, 10);
SelectObject(hdc, hOldBrush);
//铃铛
hYelloBrush = CreateSolidBrush(RGB(255, 255, 0));
hOldBrush = (HBRUSH)SelectObject(hdc, hYelloBrush);
Ellipse(hdc, cxClient / 2 - 15, cyClient / 2, cxClient / 2 + 15, cyClient / 2 + 30);
RoundRect(hdc, cxClient / 2 - 15, cyClient / 2 + 10, cxClient / 2 + 15, cyClient / 2 + 15, 10, 10);
SelectObject(hdc, hRedBrush);
Ellipse(hdc, cxClient / 2 - 4, cyClient / 2 + 18, cxClient / 2 + 4, cyClient / 2 + 26);
MoveToEx(hdc, cxClient / 2, cyClient / 2 + 26,NULL);
LineTo(hdc, cxClient / 2, cyClient / 2 + 30);
SelectObject(hdc, hOldBrush);
//口袋
Pie(hdc, cxClient / 2 - 50, cyClient / 2, cxClient / 2 + 50, cyClient / 2 + 100, cxClient / 2 - 50, cyClient / 2 + 50, cxClient / 2 + 50, cyClient / 2 + 50);
//裤裆
Pie(hdc, cxClient / 2 - 20, cyClient / 2 + 130, cxClient / 2 + 20, cyClient / 2 + 170, cxClient / 2 + 20, cyClient / 2 + 150, cxClient / 2 - 20, cyClient / 2 + 150);
hPen = CreatePen(PS_SOLID, 2, RGB(255, 255, 255));
hOldPen = (HPEN)SelectObject(hdc, hPen);
MoveToEx(hdc, cxClient / 2 - 20, cyClient / 2 + 150, NULL);
LineTo(hdc, cxClient / 2 + 20, cyClient / 2 + 150);
SelectObject(hdc, hOldPen);
//脚
Ellipse(hdc, cxClient / 2 - 110, cyClient / 2 + 130, cxClient / 2 - 10, cyClient / 2 + 170);
Ellipse(hdc, cxClient / 2 + 110, cyClient / 2 + 130, cxClient / 2 + 10, cyClient / 2 + 170);
//手
hOldBrush = (HBRUSH)SelectObject(hdc, hBlueBrush);
apt[0].x = cxClient / 2 - 90;
apt[0].y = cyClient / 2 + 10;
apt[1].x = cxClient / 2 - 130;
apt[1].y = cyClient / 2 + 50;
apt[2].x = cxClient / 2 - 110;
apt[2].y = cyClient / 2 + 70;
apt[3].x = cxClient / 2 - 90;
apt[3].y = cyClient / 2 + 60;
Polygon(hdc, apt, 4);
SelectObject(hdc, hOldBrush);
Ellipse(hdc, cxClient / 2 - 150, cyClient / 2 + 46, cxClient / 2 - 110, cyClient / 2 + 86);
hOldBrush = (HBRUSH)SelectObject(hdc, hBlueBrush);
apt[0].x = cxClient / 2 + 90;
apt[0].y = cyClient / 2 + 10;
apt[1].x = cxClient / 2 + 130;
apt[1].y = cyClient / 2 + 50;
apt[2].x = cxClient / 2 + 110;
apt[2].y = cyClient / 2 + 70;
apt[3].x = cxClient / 2 + 90;
apt[3].y = cyClient / 2 + 60;
Polygon(hdc, apt, 4);
SelectObject(hdc, hOldBrush);
Ellipse(hdc, cxClient / 2 + 150, cyClient / 2 + 46, cxClient / 2 + 110, cyClient / 2 + 86);
//胳膊两侧划线,增加立体感
hPen = CreatePen(PS_SOLID, 2, RGB(0, 159, 232));
hOldPen = (HPEN)SelectObject(hdc, hPen);
MoveToEx(hdc, cxClient / 2 - 90, cyClient / 2 + 10, NULL);
LineTo(hdc, cxClient / 2 - 90, cyClient / 2 + 50);
MoveToEx(hdc, cxClient / 2 + 90, cyClient / 2 + 10, NULL);
LineTo(hdc, cxClient / 2 + 90, cyClient / 2 + 50);
SelectObject(hdc, hOldPen);
EndPaint(hwnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wparam, lparam);
}