MFC绘制哆啦A梦

OnPaint绘制代码

cpp 复制代码
		CPaintDC dc(this); // 用于绘画的设备上下文
		
		CRect rc;
		GetWindowRect(rc);
		int cxClient = rc.Width();
		int cyClient = rc.Height();
		// 辅助线
		HPEN hPen = CreatePen(PS_DOT, 1, RGB(192, 192, 192));
		HPEN hOldPen = (HPEN)SelectObject(dc, hPen);
		MoveToEx(dc, cxClient / 2, 0, NULL);
		LineTo(dc, cxClient / 2, cyClient);
		MoveToEx(dc, 0, cyClient / 2, NULL);
		LineTo(dc, cxClient, cyClient / 2);
		SelectObject(dc, hOldPen);

		// 头 直径240
		HBRUSH hBlueBrush = CreateSolidBrush(RGB(0, 159, 232));
		HBRUSH hOldBrush = (HBRUSH)SelectObject(dc, hBlueBrush);
		DrawEllipse(&dc, cxClient / 2 - 120, cyClient / 2 - 200, cxClient / 2 + 120, cyClient / 2 + 40,
			RGB(0, 0, 0), RGB(0, 159, 232));
		SelectObject(dc, hOldBrush);

		// 脸 直径200 
		DrawEllipse(&dc, cxClient / 2 - 100, cyClient / 2 - 160, cxClient / 2 + 100, cyClient / 2 + 40,
			RGB(0,0,0), RGB(255,255,255));

		//眼睛
		hOldBrush = DrawEyes(hOldBrush, dc, cxClient, cyClient);

		// 鼻子
		HBRUSH hRedBrush = CreateSolidBrush(RGB(255, 0, 0));
		hOldBrush = (HBRUSH)SelectObject(dc, hRedBrush);
		DrawEllipse(&dc, cxClient / 2 - 10, cyClient / 2 - 135, cxClient / 2 + 10, cyClient / 2 - 115,
			RGB(0, 0, 0), RGB(255, 0, 0));
		SelectObject(dc, hOldBrush);

		MoveToEx(dc, cxClient / 2, cyClient / 2 - 115, NULL);
		LineTo(dc, cxClient / 2, cyClient / 2 - 30);

		// 嘴巴
		Arc(dc, cxClient / 2 - 70, cyClient / 2 - 120, cxClient / 2 + 70, cyClient / 2 - 30,
			cxClient / 2 - 60, cyClient / 2 - 50, cxClient / 2 + 60, cyClient / 2 - 50);

		// 胡须  中上下
		DrawBeard(dc, cxClient, cyClient);


		// 身体
		hOldBrush = (HBRUSH)SelectObject(dc, hBlueBrush);
		Rectangle(dc, cxClient / 2 - 100, cyClient / 2 - 10, cxClient / 2 + 100, cyClient / 2 + 150);
		SelectObject(dc, hOldBrush);

		// 肚皮
		Ellipse(dc, cxClient / 2 - 70, cyClient / 2 - 20, cxClient / 2 + 70, cyClient / 2 + 120); // 圆
		hPen = CreatePen(PS_DOT, 1, RGB(255, 255, 255)); // 擦除肚皮上面嘴巴下面的圆弧
		hOldPen = (HPEN)SelectObject(dc, hPen);
		Arc(dc, 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(dc, hOldPen);

		// 围脖
		hOldBrush = (HBRUSH)SelectObject(dc, hRedBrush);
		RoundRect(dc, cxClient / 2 - 102, cyClient / 2 - 12, cxClient / 2 + 102, cyClient / 2 + 5, 20, 20);
		SelectObject(dc, hOldBrush);

		// 铃铛
		HBRUSH hYellowBrush = CreateSolidBrush(RGB(255, 255, 0));
		hOldBrush = (HBRUSH)SelectObject(dc, hYellowBrush);
		Ellipse(dc, cxClient / 2 - 12, cyClient / 2 - 4, cxClient / 2 + 12, cyClient / 2 + 20);
		RoundRect(dc, cxClient / 2 - 12, cyClient / 2 + 3, cxClient / 2 + 12, cyClient / 2 + 6, 20, 20);
		SelectObject(dc, hRedBrush);
		Ellipse(dc, cxClient / 2 - 5, cyClient / 2 + 8, cxClient / 2 + 5, cyClient / 2 + 18);
		SelectObject(dc, hOldBrush);

		// 裤腿
		Ellipse(dc, cxClient / 2 - 20, cyClient / 2 + 130, cxClient / 2 + 20, cyClient / 2 + 170); // 画圆
		hPen = CreatePen(PS_DOT, 1, RGB(255, 255, 255)); // 擦除肚皮下面嘴巴上面的圆弧
		hOldPen = (HPEN)SelectObject(dc, hPen);
		Arc(dc, cxClient / 2 - 20, cyClient / 2 + 130, cxClient / 2 + 20, cyClient / 2 + 170,
			cxClient / 2 - 20, cyClient / 2 + 150, cxClient / 2 + 20, cyClient / 2 + 150);
		SelectObject(dc, hOldPen);

		// 口袋
		Pie(dc, cxClient / 2 - 50, cyClient / 2, cxClient / 2 + 50, cyClient / 2 + 100,
			cxClient / 2 - 50, cyClient / 2 + 50, cxClient / 2 + 50, cyClient / 2 + 50);

		// 脚掌
		Ellipse(dc, cxClient / 2 - 110, cyClient / 2 + 135, cxClient / 2 - 10, cyClient / 2 + 165);
		Ellipse(dc, cxClient / 2 + 10, cyClient / 2 + 135, cxClient / 2 + 110, cyClient / 2 + 165);

		// 胳膊
		POINT apt[4];
		hOldBrush = (HBRUSH)SelectObject(dc, hBlueBrush);
		apt[0].x = cxClient / 2 - 100;
		apt[0].y = cyClient / 2;
		apt[1].x = cxClient / 2 - 150;
		apt[1].y = cyClient / 2 + 60;
		apt[2].x = cxClient / 2 - 140;
		apt[2].y = cyClient / 2 + 80;
		apt[3].x = cxClient / 2 - 100;
		apt[3].y = cyClient / 2 + 60;
		Polygon(dc, apt, 4);
		SelectObject(dc, hOldBrush);
		Ellipse(dc, cxClient / 2 - 168, cyClient / 2 + 60, cxClient / 2 - 138, cyClient / 2 + 90); // 左手掌

		hOldBrush = (HBRUSH)SelectObject(dc, hBlueBrush);
		apt[0].x = cxClient / 2 + 100;
		apt[0].y = cyClient / 2;
		apt[1].x = cxClient / 2 + 150;
		apt[1].y = cyClient / 2 + 60;
		apt[2].x = cxClient / 2 + 140;
		apt[2].y = cyClient / 2 + 80;
		apt[3].x = cxClient / 2 + 100;
		apt[3].y = cyClient / 2 + 60;
		Polygon(dc, apt, 4);
		SelectObject(dc, hOldBrush);
		Ellipse(dc, cxClient / 2 + 168, cyClient / 2 + 60, cxClient / 2 + 138, cyClient / 2 + 90); // 右手掌

// 		// 左手举着小风车
// 		MoveToEx(dc, cxClient / 2 - 160, cyClient / 2 + 62, NULL);
// 		LineTo(dc, cxClient / 2 - 160, cyClient / 2 - 40);
// 		DrawWindmill(dc, cxClient / 2 - 160, cyClient / 2 - 40);
// 
// 		// 右手举着小风车
// 		MoveToEx(dc, cxClient / 2 + 160, cyClient / 2 + 62, NULL);
// 		LineTo(dc, cxClient / 2 + 160, cyClient / 2 - 40);
// 		DrawWindmill(dc, cxClient / 2 + 160, cyClient / 2 - 40);
		// 左手举着五星红旗
		MoveToEx(dc, cxClient / 2 - 160, cyClient / 2 + 62, NULL);
		LineTo(dc, cxClient / 2 - 160, cyClient / 2 - 40);
		DrawFlagChina(dc, cxClient / 2 - 160+1, cyClient / 2 - 40);

		// 右手举着奥运五环旗
		MoveToEx(dc, cxClient / 2 + 160, cyClient / 2 + 62, NULL);
		LineTo(dc, cxClient / 2 + 160, cyClient / 2 - 40);
		DrawFlagOlympics(dc, cxClient / 2 + 160, cyClient / 2 - 40);

		// 去多余线,增强立体感
		hPen = CreatePen(PS_SOLID, 2, RGB(0, 159, 232));
		hOldPen = (HPEN)SelectObject(dc, hPen);
		MoveToEx(dc, cxClient / 2 - 100, cyClient / 2, NULL);
		LineTo(dc, cxClient / 2 - 100, cyClient / 2 + 50);

		MoveToEx(dc, cxClient / 2 + 100, cyClient / 2, NULL);
		LineTo(dc, cxClient / 2 + 100, cyClient / 2 + 50);
		SelectObject(dc, hOldPen);

		// 清理资源
		DeleteObject(hPen);
		DeleteObject(hBlueBrush);
		DeleteObject(hRedBrush);
		DeleteObject(hYellowBrush);

完整Visual Studio工程下载

点击前往下载

相关推荐
雨中rain6 分钟前
Linux -- 从抢票逻辑理解线程互斥
linux·运维·c++
ALISHENGYA1 小时前
全国青少年信息学奥林匹克竞赛(信奥赛)备考实战之分支结构(实战项目二)
数据结构·c++·算法
arong_xu1 小时前
现代C++锁介绍
c++·多线程·mutex
汤姆和杰瑞在瑞士吃糯米粑粑1 小时前
【C++学习篇】AVL树
开发语言·c++·学习
DARLING Zero two♡2 小时前
【优选算法】Pointer-Slice:双指针的算法切片(下)
java·数据结构·c++·算法·leetcode
CodeClimb2 小时前
【华为OD-E卷-木板 100分(python、java、c++、js、c)】
java·javascript·c++·python·华为od
奶香臭豆腐2 小时前
C++ —— 模板类具体化
开发语言·c++·学习
不想当程序猿_2 小时前
【蓝桥杯每日一题】分糖果——DFS
c++·算法·蓝桥杯·深度优先
cdut_suye3 小时前
Linux工具使用指南:从apt管理、gcc编译到makefile构建与gdb调试
java·linux·运维·服务器·c++·人工智能·python
波音彬要多做3 小时前
41 stack类与queue类
开发语言·数据结构·c++·学习·算法