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工程下载

点击前往下载

相关推荐
林开落L22 分钟前
前缀和算法习题篇(上)
c++·算法·leetcode
Prejudices35 分钟前
C++如何调用Python脚本
开发语言·c++·python
单音GG38 分钟前
推荐一个基于协程的C++(lua)游戏服务器
服务器·c++·游戏·lua
qing_0406031 小时前
C++——多态
开发语言·c++·多态
孙同学_1 小时前
【C++】—掌握STL vector 类:“Vector简介:动态数组的高效应用”
开发语言·c++
charlie1145141911 小时前
Qt Event事件系统小探2
c++·qt·拖放·事件系统
iiiiiankor1 小时前
C/C++内存管理 | new的机制 | 重载自己的operator new
java·c语言·c++
小辛学西嘎嘎1 小时前
C/C++精品项目之图床共享云存储(3):网络缓冲区类和main
c语言·开发语言·c++
c语言鹌鹑蛋2 小时前
C++初阶 --- 类和对象(1)
开发语言·c++
Jack黄从零学c++2 小时前
opencv(c++)图像的灰度转换
c++·人工智能·opencv