资源简介
MFC带百分比的进度条,使用GDI+实现,代码比较简单。做个参考。里面gdi对象没有释放。使用时请自行deleteobject和releaseDC
代码片段和文件信息
// CircleProgress.cpp : 实现文件
//
#include “stdafx.h“
#include “MFCApplication1.h“
#include “CircleProgress.h“
#include
#define PI 3.1415926535897932384626433832795028
// CCircleProgress
IMPLEMENT_DYNAMIC(CCircleProgress CStatic)
CCircleProgress::CCircleProgress()
{
GdiplusStartupInput gdiplusStartupInput;
//初始化GDI+
GdiplusStartup(&gdiplusToken &gdiplusStartupInput NULL);
m_colors = NULL;
m_percent = 0;
m_penWidth = 0;
m_centerPoint = 0;
m_elementCount = 0;
m_insideRadius = 0;
m_outsideRadius = 0;
m_rect = 0;
m_offSet = 0;
m_strPercent = L“0%“;
}
CCircleProgress::~CCircleProgress()
{
GdiplusShutdown(gdiplusToken);
}
BEGIN_MESSAGE_MAP(CCircleProgress CStatic)
ON_WM_PAINT()
ON_WM_TIMER()
END_MESSAGE_MAP()
// CCircleProgress 消息处理程序
void CCircleProgress::OnPaint()
{
CPaintDC dc(this); // device context for painting
CDC memdc;
memdc.CreateCompatibleDC(NULL);
CBitmap memBitmap;
memBitmap.CreateCompatibleBitmap(&dc m_rect.Width() m_rect.Height());
memdc.Selectobject(memBitmap);
memdc.FillSolidRect(CRect(00m_rect.Width()m_rect.Height()) RGB(240 240 240));
Graphics graphics(memdc);
graphics.SetSmoothingMode(SmoothingModeDefault); //描边时消除锯齿
byte byIncrement = (byte)(255 / 12);
byte iPercent = 255;
double angle = (double)360 / m_elementCount;
Pen initPen(Darken(GetPixel(dc 1 1) 255) m_penWidth);
initPen.SetStartCap(LineCapRound); //设置线帽样式
initPen.SetEndCap(LineCapRound);
for (int iCounter = 0; iCounter < m_elementCount; iCounter++)
{
Point startP endP;
startP.X = m_centerPoint.x + m_insideRadius * (float)cos((PI*(1 + iCounter)*angle) / 180);
startP.Y = m_centerPoint.y + m_insideRadius * (float)sin((PI*(1 + iCounter)*angle) / 180);
endP.X = m_centerPoint.x + m_outsideRadius * (float)cos((PI*(1 + iCounter)*angle) / 180);
endP.Y = m_centerPoint.y + m_outsideRadius * (float)sin((PI*(1 + iCounter)*angle) / 180);
graphics.DrawLine(&initPen startP endP);
}
for (int iCounter = 0; iCounter < m_elementCount; iCounter++)
{
Point startP endP;
startP.X = m_centerPoint.x + m_insideRadius * (float)cos((PI*(1 + iCounter)*angle) / 180);
startP.Y = m_centerPoint.y + m_insideRadius * (float)sin((PI*(1 + iCounter)*angle) / 180);
endP.X = m_centerPoint.x + m_outsideRadius * (float)cos((PI*(1 + iCounter)*angle) / 180);
endP.Y = m_centerPoint.y + m_outsideRadius * (float)sin((PI*(1 + iCounter)*angle) / 180);
int index = (iCounter + m_offSet) % m_elementCount;
Pen pen(m_colors[index] m_penWidth);
pen.SetStartCap(LineCapRound); //设置线帽样式
pen.SetEndCap(LineCapRound);
graphics.DrawLine(&pen startP endP);
}
//画百分比
Gdiplus::FontFamily fontFamily(L“宋体“);
Gdiplus::Font font(&fontFamily20FontstyleRegularUnitPixel);
StringFormat stringformat;
stringformat.SetAlignment(StringAlignmentCenter);
stringformat.SetLineAlignment(StringAlignmentCenter);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-09-19 15:58 MFCApplication1\
文件 5201 2017-09-19 15:57 MFCApplication1\CircleProgress.cpp
文件 896 2017-09-19 15:52 MFCApplication1\CircleProgress.h
文件 108716 2017-09-19 15:55 MFCApplication1\MFCApplication1.aps
文件 2491 2017-09-19 09:21 MFCApplication1\MFCApplication1.cpp
文件 497 2017-09-19 09:21 MFCApplication1\MFCApplication1.h
文件 10812 2017-09-19 15:55 MFCApplication1\MFCApplication1.rc
文件 6305 2017-09-19 10:36 MFCApplication1\MFCApplication1.vcxproj
文件 2305 2017-09-19 10:36 MFCApplication1\MFCApplication1.vcxproj.filters
文件 3711 2017-09-19 15:55 MFCApplication1\MFCApplication1Dlg.cpp
文件 771 2017-09-19 15:55 MFCApplication1\MFCApplication1Dlg.h
文件 4188 2017-09-19 09:21 MFCApplication1\ReadMe.txt
目录 0 2017-09-19 09:21 MFCApplication1\res\
文件 67777 2013-07-22 01:18 MFCApplication1\res\MFCApplication1.ico
文件 686 2017-09-19 09:21 MFCApplication1\res\MFCApplication1.rc2
文件 1524 2017-09-19 15:54 MFCApplication1\resource.h
文件 148 2017-09-19 09:21 MFCApplication1\stdafx.cpp
文件 1578 2017-09-19 09:21 MFCApplication1\stdafx.h
文件 234 2017-09-19 09:21 MFCApplication1\targetver.h
文件 991 2017-09-19 09:21 MFCApplication1.sln
评论
共有 条评论