📄 macprogressctrl.cpp
字号:
// MacProgressCtrl.cpp : implementation file
//
// CMacProgressCtrl class, version 1.0
//
// Copyright (c) 1999 Paul M. Meidinger (pmmeidinger@yahoo.com)
//
// Feel free to modifiy and/or distribute this file, but
// do not remove this header.
//
// I would appreciate a notification of any bugs discovered or
// improvements that could be made.
//
// This file is provided "as is" with no expressed or implied warranty.
//
// History:
// PMM 12/21/1999 Initial implementation.
#include "stdafx.h"
#include "MacProgressCtrl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define IDT_INDETERMINATE 100
#define IND_BAND_WIDTH 20
// Funtion prototypes.
COLORREF LightenColor(const COLORREF crColor, BYTE byIncreaseVal);
COLORREF DarkenColor(const COLORREF crColor, BYTE byReduceVal);
//-------------------------------------------------------------------
//
COLORREF LightenColor(const COLORREF crColor, BYTE byIncreaseVal)
//
// Return Value: None.
//
// Parameters : crColor - References a COLORREF structure.
// byReduceVal - The amount to reduce the RGB values by.
//
// Remarks : Lightens a color by increasing the RGB values by the given number.
//
{
BYTE byRed = GetRValue(crColor);
BYTE byGreen = GetGValue(crColor);
BYTE byBlue = GetBValue(crColor);
if ((byRed + byIncreaseVal) <= 255)
byRed = BYTE(byRed + byIncreaseVal);
if ((byGreen + byIncreaseVal) <= 255)
byGreen = BYTE(byGreen + byIncreaseVal);
if ((byBlue + byIncreaseVal) <= 255)
byBlue = BYTE(byBlue + byIncreaseVal);
return RGB(byRed, byGreen, byBlue);
} // LightenColorref
//-------------------------------------------------------------------
//
COLORREF DarkenColor(const COLORREF crColor, BYTE byReduceVal)
//
// Return Value: None.
//
// Parameters : crColor - References a COLORREF structure.
// byReduceVal - The amount to reduce the RGB values by.
//
// Remarks : Darkens a color by reducing the RGB values by the given number.
//
{
BYTE byRed = GetRValue(crColor);
BYTE byGreen = GetGValue(crColor);
BYTE byBlue = GetBValue(crColor);
if (byRed >= byReduceVal)
byRed = BYTE(byRed - byReduceVal);
if (byGreen >= byReduceVal)
byGreen = BYTE(byGreen - byReduceVal);
if (byBlue >= byReduceVal)
byBlue = BYTE(byBlue - byReduceVal);
return RGB(byRed, byGreen, byBlue);
} // DarkenColorref
/////////////////////////////////////////////////////////////////////////////
// CMacProgressCtrl
//-------------------------------------------------------------------
//
CMacProgressCtrl::CMacProgressCtrl()
//
// Return Value: None.
//
// Parameters : None.
//
// Remarks : Standard constructor.
//
{
m_bIndeterminate = FALSE;
m_nIndOffset = 0;
m_crColor = ::GetSysColor(COLOR_HIGHLIGHT);
GetColors();
CreatePens();
} // CMacProgressCtrl
//-------------------------------------------------------------------
//
CMacProgressCtrl::~CMacProgressCtrl()
//
// Return Value: None.
//
// Parameters : None.
//
// Remarks : None.
//
{
DeletePens();
} // ~CMacProgressCtrl
//-------------------------------------------------------------------
//
void CMacProgressCtrl::DrawHorizontalBar(CDC *pDC, const CRect rect)
//
// Return Value: None.
//
// Parameters : pDC - Specifies the device context object.
// rect - Specifies the rectangle of the progess bar.
//
// Remarks : Draws a horizontal progress bar.
//
{
if (!rect.Width())
return;
int nLeft = rect.left;
int nTop = rect.top;
int nBottom = rect.bottom;
// Assume we're not drawing the indeterminate state.
CPen pOldPen;
pOldPen.Attach(pDC->SelectPen(m_penColorLight.m_hPen));
if (m_bIndeterminate)
{
// pOldPen = pDC->SelectPen(&m_penColor);
pOldPen.Attach(pDC->SelectPen(m_penColor.m_hPen));
int nNumBands = (rect.Width() / IND_BAND_WIDTH) + 2;
int nHeight = rect.Height() + 1;
int nAdjust = nLeft - IND_BAND_WIDTH + m_nIndOffset;
int nXpos = 0;
int nYpos1 = nTop + 1;
int nYpos2 = nBottom - 2;
for (int i = 0; i < nNumBands; i++)
{
nXpos = nAdjust + (i * IND_BAND_WIDTH);
pDC->SelectPen(m_penColorDarker.m_hPen);
pDC->MoveTo(nXpos + 1, nTop);
pDC->LineTo(nXpos + nHeight, nBottom);
pDC->SelectPen(m_penColorDark.m_hPen);
pDC->MoveTo(nXpos + 2, nTop);
pDC->LineTo(nXpos + nHeight + 1, nBottom);
pDC->MoveTo(nXpos + 10, nTop);
pDC->LineTo(nXpos + nHeight + 9, nBottom);
pDC->SelectPen(m_penColor.m_hPen);
pDC->MoveTo(nXpos + 3, nTop);
pDC->LineTo(nXpos + nHeight + 2, nBottom);
pDC->MoveTo(nXpos + 9, nTop);
pDC->LineTo(nXpos + nHeight + 8, nBottom);
pDC->SelectPen(m_penColorLight.m_hPen);
pDC->MoveTo(nXpos + 4, nTop);
pDC->LineTo(nXpos + nHeight + 3, nBottom);
pDC->MoveTo(nXpos + 8, nTop);
pDC->LineTo(nXpos + nHeight + 7, nBottom);
pDC->SelectPen(m_penColorLighter.m_hPen);
pDC->MoveTo(nXpos + 5, nTop);
pDC->LineTo(nXpos + nHeight + 4, nBottom);
pDC->MoveTo(nXpos + 7, nTop);
pDC->LineTo(nXpos + nHeight + 6, nBottom);
} // for the number of bands
} // if indeterminate
else
{
int nRight = rect.right;
pDC->MoveTo(nLeft + 2, nBottom - 4);
pDC->LineTo(nRight - 2, nBottom - 4);
pDC->MoveTo(nLeft + 2, nTop + 2);
pDC->LineTo(nRight - 2, nTop + 2);
pDC->SetPixel(nLeft + 1, nBottom - 3, m_crColorLight);
pDC->SetPixel(nLeft + 1, nTop + 1, m_crColorLight);
pDC->SelectPen(m_penColorLighter.m_hPen);
pDC->MoveTo(nLeft + 2, nBottom - 5);
pDC->LineTo(nRight - 3, nBottom - 5);
pDC->LineTo(nRight - 3, nTop + 3);
pDC->LineTo(nLeft + 1, nTop + 3);
pDC->SetPixel(nLeft + 1, nBottom - 4, m_crColorLighter);
pDC->SetPixel(nLeft + 1, nTop + 2, m_crColorLighter);
pDC->SelectPen(m_penColor.m_hPen);
pDC->MoveTo(nLeft, nBottom - 1);
pDC->LineTo(nLeft, nTop);
pDC->LineTo(nLeft + 2, nTop);
pDC->SetPixel(nLeft + 1, nBottom - 2, m_crColor);
pDC->MoveTo(nLeft + 2, nBottom - 3);
pDC->LineTo(nRight - 2, nBottom - 3);
pDC->MoveTo(nLeft + 2, nTop + 1);
pDC->LineTo(nRight - 1, nTop + 1);
pDC->SelectPen(m_penColorDark.m_hPen);
pDC->MoveTo(nLeft + 2, nBottom - 2);
pDC->LineTo(nRight - 2, nBottom - 2);
pDC->LineTo(nRight - 2, nTop + 1);
pDC->MoveTo(nLeft + 2, nTop);
pDC->LineTo(nRight, nTop);
pDC->SetPixel(nLeft + 1, nBottom - 1, m_crColorDark);
pDC->SelectPen(m_penColorDarker.m_hPen);
pDC->MoveTo(nLeft + 2, nBottom - 1);
pDC->LineTo(nRight - 1, nBottom - 1);
pDC->LineTo(nRight - 1, nTop);
pDC->SelectPen(m_penShadow.m_hPen);
pDC->MoveTo(nRight, nTop);
pDC->LineTo(nRight, nBottom);
pDC->SelectPen(m_penLiteShadow.m_hPen);
pDC->MoveTo(nRight + 1, nTop);
pDC->LineTo(nRight + 1, nBottom);
} // if not indeterminate
pDC->SelectPen(pOldPen.m_hPen);
} // DrawHorizontalBar
//-------------------------------------------------------------------
//
void CMacProgressCtrl::DrawVerticalBar(CDC *pDC, const CRect rect)
//
// Return Value: None.
//
// Parameters : pDC - Specifies the device context object.
// rect - Specifies the rectangle of the progess bar.
//
// Remarks : Draws a vertical progress bar.
//
{
int nHeight = rect.Height();
if (!nHeight)
return;
int nLeft = rect.left;
int nTop = rect.top;
int nRight = rect.right;
int nBottom = rect.bottom;
CPen pOldPen;
pOldPen.Attach(pDC->SelectPen(m_penColor.m_hPen));
if (m_bIndeterminate)
{
int nNumBands = (nHeight / IND_BAND_WIDTH) + 2;
int nHeight = rect.Width() + 1;
int nAdjust = nBottom - m_nIndOffset;
int nXpos1 = nLeft;
int nXpos2 = nRight + 1;
int nYpos = nTop + 1;
for (int i = 0; i < nNumBands; i++)
{
nYpos = nAdjust - (i * IND_BAND_WIDTH);
pDC->SelectPen(m_penColorDarker.m_hPen);
pDC->MoveTo(nXpos1, nYpos);
pDC->LineTo(nXpos2, nYpos + nHeight);
pDC->SelectPen(m_penColorDark.m_hPen);
pDC->MoveTo(nXpos1, nYpos + 1);
pDC->LineTo(nXpos2, nYpos + nHeight + 1);
pDC->MoveTo(nXpos1, nYpos + 9);
pDC->LineTo(nXpos2, nYpos + nHeight + 9);
pDC->SelectPen(m_penColor.m_hPen);
pDC->MoveTo(nXpos1, nYpos + 2);
pDC->LineTo(nXpos2, nYpos + nHeight + 2);
pDC->MoveTo(nXpos1, nYpos + 8);
pDC->LineTo(nXpos2, nYpos + nHeight + 8);
pDC->SelectPen(m_penColorLight.m_hPen);
pDC->MoveTo(nXpos1, nYpos + 3);
pDC->LineTo(nXpos2, nYpos + nHeight + 3);
pDC->MoveTo(nXpos1, nYpos + 7);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -