代码拉取完成,页面将自动刷新
// ProgressCtrlEx.cpp : ʵļ
//
#include "stdafx.h"
#include ".\progressctrlex.h"
namespace UIExtended
{
// CProgressCtrlEx
IMPLEMENT_DYNAMIC(CProgressCtrlEx, CProgressCtrl)
CProgressCtrlEx::CProgressCtrlEx()
{
m_nPos = 0;
m_nStepSize = 1;
m_nMax = 100;
m_nMin = 0;
m_bShowText = TRUE;
m_strText.Empty();
m_colFore = ::GetSysColor(COLOR_HIGHLIGHT);
m_colBk = ::GetSysColor(COLOR_WINDOW);
m_colTextFore = ::GetSysColor(COLOR_HIGHLIGHT);
m_colTextBk = ::GetSysColor(COLOR_WINDOW);
m_Style = 1;
m_nBarWidth = -1;
}
CProgressCtrlEx::~CProgressCtrlEx()
{
}
BEGIN_MESSAGE_MAP(CProgressCtrlEx, CProgressCtrl)
ON_WM_ERASEBKGND()
ON_WM_PAINT()
ON_WM_SIZE()
END_MESSAGE_MAP()
// CProgressCtrlEx Ϣ
BOOL CProgressCtrlEx::OnEraseBkgnd(CDC* pDC)
{
return TRUE;
}
void CProgressCtrlEx::OnPaint()
{
if (m_nMin >= m_nMax)
return;
CRect LeftRect, RightRect, ClientRect;
GetClientRect(ClientRect);
double Fraction = (double)(m_nPos - m_nMin) / ((double)(m_nMax - m_nMin));
CPaintDC PaintDC(this); // device context for painting
CMemDC dc(&PaintDC);
//CPaintDC dc(this); // device context for painting (if not double buffering)
LeftRect = RightRect = ClientRect;
LeftRect.right = LeftRect.left + (int)((LeftRect.right - LeftRect.left)*Fraction);
dc.FillSolidRect(LeftRect, m_colFore);
RightRect.left = LeftRect.right;
dc.FillSolidRect(RightRect, m_colBk);
dc.SelectObject(m_pFont);
if (m_bShowText)
{
CString str;
if (m_strText.GetLength())
str = m_strText;
else
{
if(m_Style == 1)
{
str.Format("%d%%", (int)(Fraction*100.0));
}
if(m_Style == 2)
{
str.Format("%3.2f%%",Fraction * 100.0);
}
if(m_Style == 3)
{
str.Format("%d/%d",(int)(m_nPos - m_nMin),(int)(m_nMax - m_nMin));
}
if(m_Style == 4)
{
str.Format("%d/%d (%3.1f%%)",(int)(m_nPos - m_nMin),(int)(m_nMax - m_nMin),Fraction * 100.0);
}
}
dc.SetBkMode(TRANSPARENT);
CRgn rgn;
rgn.CreateRectRgn(LeftRect.left, LeftRect.top, LeftRect.right, LeftRect.bottom);
dc.SelectClipRgn(&rgn);
dc.SetTextColor(m_colTextBk);
dc.DrawText(str, ClientRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
rgn.DeleteObject();
rgn.CreateRectRgn(RightRect.left, RightRect.top, RightRect.right, RightRect.bottom);
dc.SelectClipRgn(&rgn);
dc.SetTextColor(m_colTextFore);
dc.DrawText(str, ClientRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
}
void CProgressCtrlEx::OnSize(UINT nType, int cx, int cy)
{
CProgressCtrl::OnSize(nType, cx, cy);
m_nBarWidth = -1;
}
void CProgressCtrlEx::SetForeColour(COLORREF col)
{
m_colFore = col;
}
void CProgressCtrlEx::SetBkColour(COLORREF col)
{
m_colBk = col;
}
void CProgressCtrlEx::SetTextForeColour(COLORREF col)
{
m_colTextFore = col;
}
void CProgressCtrlEx::SetTextBkColour(COLORREF col)
{
m_colTextBk = col;
}
COLORREF CProgressCtrlEx::GetForeColour()
{
return m_colFore;
}
COLORREF CProgressCtrlEx::GetBkColour()
{
return m_colBk;
}
COLORREF CProgressCtrlEx::GetTextForeColour()
{
return m_colTextFore;
}
COLORREF CProgressCtrlEx::GetTextBkColour()
{
return m_colTextBk;
}
void CProgressCtrlEx::SetShowText(BOOL bShow)
{
if (::IsWindow(m_hWnd) && m_bShowText != bShow)
Invalidate();
m_bShowText = bShow;
}
void CProgressCtrlEx::SetRange(int nLower, int nUpper)
{
m_nMax = nUpper;
m_nMin = nLower;
}
int CProgressCtrlEx::SetPos(int nPos)
{
if (!::IsWindow(m_hWnd))
return -1;
int nOldPos = m_nPos;
m_nPos = nPos;
CRect rect;
GetClientRect(rect);
double Fraction = (double)(m_nPos - m_nMin) / ((double)(m_nMax - m_nMin));
int nBarWidth = (int) (Fraction * rect.Width());
if (nBarWidth != m_nBarWidth)
{
m_nBarWidth = nBarWidth;
RedrawWindow();
}
return nOldPos;
}
int CProgressCtrlEx::StepIt()
{
return SetPos(m_nPos + m_nStepSize);
}
int CProgressCtrlEx::OffsetPos(int nPos)
{
return SetPos(m_nPos + nPos);
}
int CProgressCtrlEx::SetStep(int nStep)
{
int nOldStep = nStep;
m_nStepSize = nStep;
return nOldStep;
}
void CProgressCtrlEx::SetShowTextStyle(int Style)
{
m_Style = Style;
}
void CProgressCtrlEx::SetTextFont(CFont* pFont)
{
m_pFont = pFont;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。