博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
学习windows编程 day4 之 盯裆猫
阅读量:5083 次
发布时间:2019-06-13

本文共 9013 字,大约阅读时间需要 30 分钟。

写着写着就困了....

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

#include 
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 = 0; wndclass.cbWndExtra = 0; 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 0; } hwnd = CreateWindow( szClassName, TEXT("MyFirstPractice"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 600, 600, NULL, NULL, hInstance, NULL ); ShowWindow(hwnd, nShowCmd); 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; RECT rect; static int cxClient, cyClient; static HPEN hPen,hOldPen; static HBRUSH hBrush, hOldBrush; POINT apt[4]; 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(192,192,192)); hOldPen=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); //还原画笔 SelectObject(hdc, hOldPen);//2.绘制头部(直径240)蓝色 hBrush = CreateSolidBrush(RGB(0, 159, 232)); hOldBrush = SelectObject(hdc,hBrush); Ellipse(hdc, cxClient / 2 - 120, cyClient / 2 - 200, cxClient/2 + 120, cyClient/2 + 40); SelectObject(hdc, hOldBrush);//3.画脸(和头内切直径200)白色 //hBrush = (HBRUSH)GetStockObject(WHITE_BRUSH); //默认是白色,已经替换回来了 Ellipse(hdc, cxClient / 2 - 100, cyClient / 2 - 160, cxClient / 2 + 100, cyClient / 2 + 40);//4.画眼睛(长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);//5.画眼珠 hBrush = (HBRUSH)GetStockObject(BLACK_BRUSH); hOldBrush = SelectObject(hdc, hBrush); 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, hOldBrush);//6.加上眼白 hOldBrush = 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);//7.加上鼻子 hBrush = CreateSolidBrush(RGB(255, 0, 0)); hOldBrush=SelectObject(hdc, hBrush); Ellipse(hdc, cxClient / 2 - 10, cyClient / 2 - 135, cxClient / 2 + 10, cyClient / 2 - 115); SelectObject(hdc, hOldBrush);//8.加上鼻子到嘴上的线 MoveToEx(hdc, cxClient / 2, cyClient / 2 - 115,NULL); LineTo(hdc, cxClient / 2, cyClient/2 - 30);//9.画上嘴巴 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);//10.画上胡须 //左 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);//11.画身体,矩形蓝色 hBrush = CreateSolidBrush(RGB(0, 159, 232)); hOldBrush = SelectObject(hdc, hBrush); Rectangle(hdc, cxClient / 2 - 90, cyClient / 2, cxClient / 2 + 90, cyClient / 2 + 150); SelectObject(hdc, hOldBrush);//12.画肚子 Ellipse(hdc, cxClient / 2 - 70, cyClient / 2 - 20, cxClient / 2 + 70, cyClient / 2 + 120); //覆盖多余长度 hPen = CreatePen(PS_SOLID, 2, RGB(255, 255, 255)); hOldPen = SelectObject(hdc, hPen); Arc(hdc, cxClient / 2 - 70, cyClient / 2 - 20, cxClient / 2 + 70, cyClient / 2 + 120, cxClient / 2 + 70, cyClient / 2, cxClient / 2 - 70, cyClient / 2); SelectObject(hdc, hOldPen);//13.项圈 hBrush = CreateSolidBrush(RGB(255, 0, 0)); hOldBrush = SelectObject(hdc, hBrush); RoundRect(hdc, cxClient / 2 - 95, cyClient / 2 - 5, cxClient / 2 + 95, cyClient / 2 + 10, 20, 10); SelectObject(hdc, hOldBrush);//14.铃铛 hBrush = CreateSolidBrush(RGB(255, 255, 0)); hOldBrush = SelectObject(hdc, hBrush); Ellipse(hdc, cxClient / 2 - 15, cyClient / 2, cxClient / 2 + 15, cyClient / 2+30); //15.铃铛上的线 RoundRect(hdc, cxClient / 2 - 15, cyClient / 2 + 10, cxClient / 2 + 15, cyClient / 2 + 15, 2, 2); SelectObject(hdc, hOldBrush);//16.铃铛孔和线 hBrush = CreateSolidBrush(RGB(255, 0, 0)); hOldBrush = SelectObject(hdc, hBrush); 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);//17.口袋 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);//18.画腿(用扇形挡住) 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 = SelectObject(hdc, hPen); MoveToEx(hdc, cxClient / 2 - 20, cyClient / 2 + 150, NULL); LineTo(hdc, cxClient / 2 + 20, cyClient / 2 + 150); SelectObject(hdc, hOldPen);//19.画脚 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);//20两个手 hBrush = CreateSolidBrush(RGB(0, 159, 232)); hOldBrush = SelectObject(hdc, hBrush); 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); hBrush = CreateSolidBrush(RGB(0, 159, 232)); hOldBrush = SelectObject(hdc, hBrush); 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 = 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); break; case WM_DESTROY: //销毁创建的画笔对象 DeleteObject(hPen); PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, message, wParam, lParam);}

 

转载于:https://www.cnblogs.com/ssyfj/p/8510985.html

你可能感兴趣的文章
getElement的几中属性介绍
查看>>
HTML列表,表格与媒体元素
查看>>
设计器 和后台代码的转换 快捷键
查看>>
STL容器之vector
查看>>
数据中心虚拟化技术
查看>>
复习文件操作
查看>>
SQL Server 使用作业设置定时任务之一(转载)
查看>>
第二阶段冲刺-01
查看>>
BZOJ1045 HAOI2008 糖果传递
查看>>
JavaScript 克隆数组
查看>>
eggs
查看>>
oracle 报错ORA-12514: TNS:listener does not currently know of service requested in connec
查看>>
python3 生成器与迭代器
查看>>
java编写提升性能的代码
查看>>
list 容器 排序函数.xml
查看>>
《Genesis-3D开源游戏引擎完整实例教程-跑酷游戏篇03:暂停游戏》
查看>>
CPU,寄存器,一缓二缓.... RAM ROM 外部存储器等简介
查看>>
windows下编译FreeSwitch
查看>>
git .gitignore 文件不起作用
查看>>
Alan Turing的纪录片观后感
查看>>