MFC 用Gdiplus画曲线和直线

一、效果

MFC 用Gdiplus画曲线和直线_第1张图片

二、关键逻辑

	Gdiplus::Pen			m_pen;
	Gdiplus::Pen			m_penSolid;
	REAL dashVals[4] = {
		1, // 短划长为2
		3, // 间隔为2
		1, // 短划长为15
		3 }; // 间隔为2
	m_pen.SetDashPattern(dashVals, 4);

	m_penSolid.SetDashStyle(DashStyleDot);
	CPaintDC dc(this); // 用于绘制的设备上下文

	Gdiplus::Graphics graphics(dc.m_hDC);
	graphics.SetSmoothingMode(Gdiplus::SmoothingModeHighQuality);


	const int nPointX = 100;
	const int nPointY = 90;
	const int nWidth = 250;
	const int nHeight = 120;
	Rect rcTop(nPointX, nPointY, nWidth, nHeight);
	Rect rcBottom(nPointX, nPointY + 10, nWidth, nHeight);
	graphics.DrawArc(&m_pen, rcTop, 180, 180);
	graphics.DrawArc(&m_pen, rcBottom, 0, 180);

	const int nArrowWidth = 10;
	const int nArrowHeight = 7;

	Point ptDay(nPointX + nWidth / 2 + nArrowWidth / 2, rcTop.GetTop());
	Point ptDayX1(ptDay.X - nArrowWidth, ptDay.Y - nArrowHeight);
	Point ptDayX2(ptDay.X - nArrowWidth, ptDay.Y + nArrowHeight);
	graphics.DrawLine(&m_penSolid, ptDayX1, ptDay);
	graphics.DrawLine(&m_penSolid, ptDayX2, ptDay);

	Point ptNight(nPointX + nWidth / 2 + nArrowWidth / 2, rcBottom.GetBottom());
	Point ptNightX1(ptNight.X + nArrowWidth, ptNight.Y - nArrowHeight);
	Point ptNightX2(ptNight.X + nArrowWidth, ptNight.Y + nArrowHeight);
	graphics.DrawLine(&m_penSolid, ptNightX1, ptNight);
	graphics.DrawLine(&m_penSolid, ptNightX2, ptNight);

 

你可能感兴趣的:(MFC)