学习windows编程 day4 之 盯裆猫

时间:2022-02-27 10:05:14

写着写着就困了....

看这些测量数据就算了,是对各种函数的练习

#include <windows.h>

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
//声明全局数据:类名
static TCHAR szClassName[] = TEXT("MyWindows");
HWND hwnd;
MSG msg; //注册窗口类
WNDCLASS wndclass; wndclass.hInstance = hInstance;
wndclass.lpszClassName = szClassName;
wndclass.cbClsExtra = ;
wndclass.cbWndExtra = ;
wndclass.lpfnWndProc = WndProc;
wndclass.lpszMenuName = NULL;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.style = CS_HREDRAW; if (!RegisterClass(&wndclass))
{
MessageBox(NULL, TEXT("this program must run in Windows NT!"), szClassName, MB_ICONERROR);
return ;
} hwnd = CreateWindow(
szClassName,
TEXT("MyFirstPractice"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
,
,
NULL,
NULL,
hInstance,
NULL
); ShowWindow(hwnd, nShowCmd);
UpdateWindow(hwnd); while (GetMessage(&msg, NULL, , ))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
} return msg.wParam;
} LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
static int cxClient, cyClient;
static HPEN hPen,hOldPen;
static HBRUSH hBrush, hOldBrush; POINT apt[];
switch (message)
{
case WM_SIZE:
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam);
break;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rect);
//1.先绘制两条虚线
//设置画笔
hPen = CreatePen(PS_DOT, 0.1, RGB(,,));
hOldPen=SelectObject(hdc, hPen);
//开始绘制
MoveToEx(hdc, cxClient / , , NULL);
LineTo(hdc, cxClient / , cyClient); MoveToEx(hdc, , cyClient/, NULL);
LineTo(hdc, cxClient, cyClient/);
//还原画笔
SelectObject(hdc, hOldPen); //2.绘制头部(直径240)蓝色
hBrush = CreateSolidBrush(RGB(, , ));
hOldBrush = SelectObject(hdc,hBrush);
Ellipse(hdc, cxClient / - , cyClient / - , cxClient/ + , cyClient/ + );
SelectObject(hdc, hOldBrush); //3.画脸(和头内切直径200)白色
//hBrush = (HBRUSH)GetStockObject(WHITE_BRUSH);
//默认是白色,已经替换回来了
Ellipse(hdc, cxClient / - , cyClient / - , cxClient / + , cyClient / + ); //4.画眼睛(长60,宽50)
Ellipse(hdc, cxClient / - , cyClient / - , cxClient / , cyClient / - );
Ellipse(hdc, cxClient / + , cyClient / - , cxClient / , cyClient / - ); //5.画眼珠
hBrush = (HBRUSH)GetStockObject(BLACK_BRUSH);
hOldBrush = SelectObject(hdc, hBrush); Ellipse(hdc, cxClient / - , cyClient / - , cxClient / - , cyClient / - );
Ellipse(hdc, cxClient / + , cyClient / - , cxClient / + , cyClient / - ); SelectObject(hdc, hOldBrush);
//6.加上眼白
hOldBrush = SelectObject(hdc, GetStockObject(WHITE_BRUSH));
Ellipse(hdc, cxClient / - , cyClient / - , cxClient / - , cyClient / - );
Ellipse(hdc, cxClient / + , cyClient / - , cxClient / + , cyClient / - ); SelectObject(hdc, hOldBrush);
//7.加上鼻子
hBrush = CreateSolidBrush(RGB(, , ));
hOldBrush=SelectObject(hdc, hBrush);
Ellipse(hdc, cxClient / - , cyClient / - , cxClient / + , cyClient / - );
SelectObject(hdc, hOldBrush); //8.加上鼻子到嘴上的线
MoveToEx(hdc, cxClient / , cyClient / - ,NULL);
LineTo(hdc, cxClient / , cyClient/ - ); //9.画上嘴巴
Arc(hdc, cxClient / - , cyClient / - , cxClient / + , cyClient/ - ,
cxClient / - , cyClient / - , cxClient / + , cyClient / - ); //10.画上胡须
//左
MoveToEx(hdc, cxClient / - , cyClient / - , NULL);
LineTo(hdc, cxClient / - , cyClient / - );
MoveToEx(hdc, cxClient / - , cyClient / - , NULL);
LineTo(hdc, cxClient / -, cyClient / -);
MoveToEx(hdc, cxClient / - , cyClient / - , NULL);
LineTo(hdc, cxClient / - , cyClient / - );
//右
MoveToEx(hdc, cxClient / + , cyClient / - , NULL);
LineTo(hdc, cxClient / + , cyClient / - );
MoveToEx(hdc, cxClient / + , cyClient / - , NULL);
LineTo(hdc, cxClient / + , cyClient / - );
MoveToEx(hdc, cxClient / + , cyClient / - , NULL);
LineTo(hdc, cxClient / + , cyClient / - ); //11.画身体,矩形蓝色
hBrush = CreateSolidBrush(RGB(, , ));
hOldBrush = SelectObject(hdc, hBrush);
Rectangle(hdc, cxClient / - , cyClient / , cxClient / + , cyClient / + );
SelectObject(hdc, hOldBrush); //12.画肚子
Ellipse(hdc, cxClient / - , cyClient / - , cxClient / + , cyClient / + );
//覆盖多余长度
hPen = CreatePen(PS_SOLID, , RGB(, , ));
hOldPen = SelectObject(hdc, hPen);
Arc(hdc, cxClient / - , cyClient / - , cxClient / + , cyClient / + , cxClient / + , cyClient / , cxClient / - , cyClient / );
SelectObject(hdc, hOldPen);
//13.项圈
hBrush = CreateSolidBrush(RGB(, , ));
hOldBrush = SelectObject(hdc, hBrush);
RoundRect(hdc, cxClient / - , cyClient / - , cxClient / + , cyClient / + , , );
SelectObject(hdc, hOldBrush);
//14.铃铛
hBrush = CreateSolidBrush(RGB(, , ));
hOldBrush = SelectObject(hdc, hBrush);
Ellipse(hdc, cxClient / - , cyClient / , cxClient / + , cyClient / +); //15.铃铛上的线
RoundRect(hdc, cxClient / - , cyClient / + , cxClient / + , cyClient / + , , );
SelectObject(hdc, hOldBrush);
//16.铃铛孔和线
hBrush = CreateSolidBrush(RGB(, , ));
hOldBrush = SelectObject(hdc, hBrush);
Ellipse(hdc, cxClient / - , cyClient / + , cxClient / + , cyClient / + );
MoveToEx(hdc, cxClient / , cyClient / + , NULL);
LineTo(hdc, cxClient / , cyClient / + );
SelectObject(hdc, hOldBrush);
//17.口袋
Pie(hdc, cxClient / - , cyClient / , cxClient / + , cyClient / + , cxClient / - , cyClient / + , cxClient / + , cyClient / + ); //18.画腿(用扇形挡住)
Pie(hdc, cxClient / - , cyClient / + , cxClient / + , cyClient / + , cxClient / + , cyClient / + , cxClient / - , cyClient / + );
hPen = CreatePen(PS_SOLID, , RGB(, , ));
hOldPen = SelectObject(hdc, hPen);
MoveToEx(hdc, cxClient / - , cyClient / + , NULL);
LineTo(hdc, cxClient / + , cyClient / + );
SelectObject(hdc, hOldPen); //19.画脚
Ellipse(hdc, cxClient / - , cyClient / + , cxClient / - , cyClient / + );
Ellipse(hdc, cxClient / + , cyClient / + , cxClient / + , cyClient / + ); //20两个手
hBrush = CreateSolidBrush(RGB(, , ));
hOldBrush = SelectObject(hdc, hBrush);
apt[].x = cxClient / - ;
apt[].y = cyClient / + ;
apt[].x = cxClient / - ;
apt[].y = cyClient / + ;
apt[].x = cxClient / - ;
apt[].y = cyClient / + ;
apt[].x = cxClient / - ;
apt[].y = cyClient / + ;
Polygon(hdc, apt, );
SelectObject(hdc, hOldBrush);
Ellipse(hdc, cxClient / - , cyClient / + , cxClient / - , cyClient / + ); hBrush = CreateSolidBrush(RGB(, , ));
hOldBrush = SelectObject(hdc, hBrush);
apt[].x = cxClient / + ;
apt[].y = cyClient / + ;
apt[].x = cxClient / + ;
apt[].y = cyClient / + ;
apt[].x = cxClient / + ;
apt[].y = cyClient / + ;
apt[].x = cxClient / + ;
apt[].y = cyClient / + ;
Polygon(hdc, apt, );
SelectObject(hdc, hOldBrush);
Ellipse(hdc, cxClient / + , cyClient / + , cxClient / + , cyClient / + ); //画线覆盖多余线条
hPen = CreatePen(PS_SOLID, , RGB(,,));
hOldPen = SelectObject(hdc, hPen); MoveToEx(hdc, cxClient / -, cyClient / +, NULL);
LineTo(hdc, cxClient / - , cyClient / + ); MoveToEx(hdc, cxClient / + , cyClient / + , NULL);
LineTo(hdc, cxClient / + , cyClient / + ); SelectObject(hdc, hOldPen); EndPaint(hwnd, &ps);
break;
case WM_DESTROY:
//销毁创建的画笔对象
DeleteObject(hPen);
PostQuitMessage();
return ;
} return DefWindowProc(hwnd, message, wParam, lParam);
}