📄 colorprogress.cpp
字号:
// ColorProgress.cpp : implementation file
//
#include "stdafx.h"
#include "lottery.h"
#include "ColorProgress.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CColorProgress
CColorProgress::CColorProgress()
{
m_crStart=RGB(0,0,255);
m_crEnd=RGB(0,0,0);
m_pColorBuf=NULL;
}
CColorProgress::~CColorProgress()
{
if (m_pColorBuf) delete [] m_pColorBuf;
}
BEGIN_MESSAGE_MAP(CColorProgress, CProgressCtrl)
//{{AFX_MSG_MAP(CColorProgress)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CColorProgress message handlers
void CColorProgress::OnPaint()
{
if (m_pColorBuf)
{
CPaintDC mainDC(this); // device context for painting
CDC dc;
dc.CreateCompatibleDC(&mainDC);
CRect rect;
GetClientRect(&rect);
CBitmap bitmap,*pOldBitmap;
bitmap.CreateCompatibleBitmap(&mainDC,rect.Width(),rect.Height());
pOldBitmap=(CBitmap*)dc.SelectObject(&bitmap);
int nUpper,nLower;
GetRange(nLower,nUpper);
int nPos=GetPos();
int nChunks=nUpper-nLower+1;
int nWidth=rect.Width()/nChunks + 1;
CRect rect1;
rect1.top=0;
rect1.bottom=rect.bottom;
for (int i=0; i<nChunks; i++)
{
CBrush brush(m_pColorBuf[i]);
rect1.left=(i)*nWidth;
rect1.right=rect1.left+nWidth;
dc.FillRect(&rect1,&brush);
brush.DeleteObject();
}
mainDC.BitBlt(0,0,rect.Width(),rect.Height(),&dc,0,0,SRCCOPY);
dc.SelectObject(pOldBitmap);
bitmap.DeleteObject();
dc.DeleteDC();
}
}
void CColorProgress::Step()
{
RotateColorBuf();
Invalidate();
}
void CColorProgress::SetRange(short nLower,short nUpper)
{
if (nLower > nUpper)
{
int temp=nLower;
nLower=nUpper;
nUpper=temp;
}
CProgressCtrl::SetRange(nLower,nUpper);
int nChunks=nUpper-nLower+1;
if (m_pColorBuf) delete [] m_pColorBuf;
m_pColorBuf=new COLORREF[nChunks];
nChunks/=2;
for (int i=0; i<=nChunks; i++)
{
m_pColorBuf[i]=RGB((nChunks-i)*255/nChunks,(nChunks-i)*255/nChunks,255);
}
for (i=nChunks+1; i<=(nUpper-nLower); i++)
{
m_pColorBuf[i]=RGB((i-nChunks)*255/nChunks,(i-nChunks)*255/nChunks,255);
}
}
void CColorProgress::RotateColorBuf()
{
int nLower,nUpper,nChunks;
GetRange(nLower,nUpper);
nChunks=nUpper-nLower;
COLORREF temp=m_pColorBuf[nChunks];
memmove((void*)(&(m_pColorBuf[1])),(void*)(&(m_pColorBuf[0])),nChunks*sizeof(COLORREF));
m_pColorBuf[0]=temp;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -