65.9K
CodeProject 正在变化。 阅读更多。
Home

CCylinderProgressControlST v1.0

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.97/5 (25投票s)

2003年7月2日

3分钟阅读

viewsIcon

161497

downloadIcon

8400

一个 GDI+ 圆柱体进度控件

Sample Image

SoftechSoftware 主页
SoftechSoftware 电子邮件

摘要

您需要安装 GDI+ 才能使用此控件。

CCylinderProgressControlST 是一个从 MFC CProgressCtrl 类派生的类。该控件是作为将现有 C# 控件转换为具有相同功能的 C++ 新控件的练习而创建的。转换相当简单。您可以在此处找到原始控件。CCylinderProgressControlST 的代码比原始代码更健壮。

CCylinderProgressControlST 功能

  • 易于使用
  • 标准 CProgressCtrl 方法
  • 支持负数范围
  • 支持垂直进度控件
  • 包含完整的源代码!
  • 在现有应用程序中实现成本为零

如何将 CCylinderProgressControlST 集成到您的应用程序中

在你的项目中包含以下文件

  • CylinderProgressControlST.h
  • CylinderProgressControlST.cpp
使用对话框编辑器创建一个进度控件,例如,名为 IDC_PROGRESS

然后为此控件创建一个成员变量
CCylinderProgressControlST m_prgControl;

现在将进度控件附加到 CCylinderProgressControlST。对于基于对话框的应用程序,在您的 OnInitDialog

// Call the base-class method

CDialog::OnInitDialog();

// Create the IDC_PROGRESS progress control

m_prgControl.SubclassDlgItem(IDC_PROGRESS, this);

或者在您的 DoDataExchange

// Call the base method

CDialog::DoDataExchange(pDX);

// Create the IDC_PROGRESS progress control

DDX_Control(pDX, IDC_PROGRESS, m_prgControl);

您的进度控件现在是 CCylinderProgressControlST

类方法

SetRange

设置进度条控件范围的上限和下限,并重绘进度条以反映新范围。

// Parameters:

//     [IN]   shLower

//            Specifies the lower limit of the range (default is zero).

//     [IN]   shUpper

//            Specifies the upper limit of the range (default is 100).

//

void SetRange(short shLower, short shUpper)

SetRange32

设置进度条控件范围的上限和下限,并重绘进度条以反映新范围。

// Parameters:

//     [IN]   nLower

//            Specifies the lower limit of the range (default is zero).

//     [IN]   nUpper

//            Specifies the upper limit of the range (default is 100).

//

void SetRange32(int nLower, int nUpper)

SetStep

指定进度条控件的步进增量。
步进增量是调用 StepIt 增加进度条当前位置的量。

// Parameters:

//     [IN]   nStep

//            New step increment.

//

// Return value:

//     The previous step increment.

//

int SetStep(int nStep)

SetPos

将进度条控件的当前位置设置为 nPos 指定的值,并重绘进度条以反映新位置。进度条控件的位置不是屏幕上的物理位置,而是介于 SetRange 中指示的上限和下限之间。

// Parameters:

//     [IN]   nPos

//            New position of the progress bar control.

//

// Return value:

//     The previous position of the progress bar control.

//

int SetPos(int nPos)

StepIt

将进度条控件的当前位置向前移动步进增量,并重绘进度条以反映新位置。
步进增量由 SetStep 方法设置。

// Return value:

//     The previous position of the progress bar control.

//

int StepIt()

SetColors

设置控件的颜色。

// Parameters:

//     [IN]   cFullColor

//            A GDI+ Color object indicating the color of the currently 

//            displayed bar.

//     [IN]   cEmptyColor

//            A GDI+ Color object indicating the color of the control's 

//            portion currently left empty.

//     [IN]   cOutlineColor

//            A GDI+ Color object indicating the color used to outline the 

//            control.

//     [IN]   cTextColor

//            A GDI+ Color object indicating the color of the displayed text.

//     [IN]   cBkColor

//            A GDI+ Color object indicating the background color of the 

//            control.

//     [IN]   bRepaint

//            If TRUE the control will be repainted.

//

void SetColors(Color cFullColor, Color cEmptyColor, Color cOutlineColor, 
               Color cTextColor, Color cBkColor, BOOL bRepaint = TRUE)

SetFullColor

设置当前显示的进度条的颜色。

// Parameters:

//     [IN]   cColor

//            A GDI+ Color object indicating the color of the currently 

//            displayed bar.

//     [IN]   bRepaint

//            If TRUE the control will be repainted.

//

void SetFullColor(Color cColor, BOOL bRepaint = TRUE)

SetEmptyColor

设置控件当前未填充部分的颜色。

// Parameters:

//     [IN]   cColor

//            A GDI+ Color object indicating the color of the control's 

//            portion currently left empty.

//     [IN]   bRepaint

//            If TRUE the control will be repainted.

//

void SetEmptyColor(Color cColor, BOOL bRepaint = TRUE)

SetOutlineColor

设置用于勾勒控件的颜色。

// Parameters:

//     [IN]   cColor

//            A GDI+ Color object indicating the color used to outline the 

//            control.

//     [IN]   bRepaint

//            If TRUE the control will be repainted.

//

void SetOutlineColor(Color cColor, BOOL bRepaint = TRUE)

SetTextColor

设置要显示的文本颜色。

// Parameters:

//     [IN]   cColor

//            A GDI+ Color object indicating the color of the displayed text.

//     [IN]   bRepaint

//            If TRUE the control will be repainted.

//

void SetTextColor(Color cColor, BOOL bRepaint = TRUE)

SetBkColor

设置控件的背景颜色。

// Parameters:

//     [IN]   cColor

//            A GDI+ Color object indicating the background color of the 

//            control.

//     [IN]   bRepaint

//            If TRUE the control will be repainted.

//

void SetBkColor(Color cColor, BOOL bRepaint = TRUE)

SetShowText

设置是否在控件上显示文本。

// Parameters:

//     [IN]   bShowText

//            TRUE if text must be displayed on the control.

//     [IN]   bRepaint

//            If TRUE the control will be repainted.

//

void SetShowText(BOOL bShowText, BOOL bRepaint = TRUE)

SetShowOutline

设置是否勾勒控件。

// Parameters:

//     [IN]   bShowOutline

//            TRUE if the control must be outlined.

//     [IN]   bRepaint

//            If TRUE the control will be repainted.

//

void SetShowOutline(BOOL bShowOutline, BOOL bRepaint = TRUE)

SetAlpha

设置绘制控件时使用的颜色的 alpha 分量。

// Parameters:

//     [IN]   byAlpha

//            A BYTE value indicating the alpha component.

//     [IN]   bRepaint

//            If TRUE the control will be repainted.

//

void SetAlpha(BYTE byAlpha, BOOL bRepaint = TRUE)

GetAlpha

返回绘制控件时使用的颜色的 alpha 分量。

// Return value:

//     A BYTE indicating the alpha component.

//

BYTE GetAlpha()

SetTooltipText

设置控件工具提示中要显示的文本。

// Parameters:

//     [IN]   nId

//            ID number of the string resource containing the text to show.

//     [IN]   bActivate

//            If TRUE the tooltip will be created active.

//

void SetTooltipText(int nId, BOOL bActivate = TRUE)

SetTooltipText

设置控件工具提示中要显示的文本。

// Parameters:

//     [IN]   lpszText

//            Pointer to a null-terminated string containing the text to show.

//     [IN]   bActivate

//            If TRUE the tooltip will be created active.

//

void SetTooltipText(LPCTSTR lpszText, BOOL bActivate = TRUE)

ActivateTooltip

启用或禁用控件工具提示。

// Parameters:

//     [IN]   bActivate

//            If TRUE the tooltip will be activated.

//

void ActivateTooltip(BOOL bActivate = TRUE)

DrawTransparent

启用透明模式。注意:此操作不可逆。DrawTransparent 应在控件创建后立即调用。除非您确实需要(拥有位图背景),否则请勿使用透明控件,因为每个透明控件都会在内存中复制其背景。这可能会导致不必要的内存使用和执行过载。

// Parameters:

//     [IN]   bRepaint

//            If TRUE the control will be repainted.

//

DWORD DrawTransparent(BOOL bRepaint = FALSE)

OnDrawBackground

每次需要重绘控件背景时都会调用此函数。如果控件处于透明模式,则不会调用此函数。这是一个虚拟函数,可以在 CCylinderProgressCtrlST 派生类中重写。

// Parameters:

//     [IN]   pGfx

//            Pointer to a GDI+ Graphics object that indicates the graphic 

//            context.

//     [IN]   rpCtrl

//            Pointer to a GDI+ Rect object that indicates the bounds of the

//            area to be painted.

//

// Return value:

//     CYLINDERPROGRESSCTRLST_OK

//        Function executed successfully.

//

virtual DWORD OnDrawBackground(Graphics* pGfx, Rect* rpCtrl)

OnDrawText

每次重绘进度条时都会调用此函数。这是一个虚拟函数,允许派生类进行自定义绘制。默认实现显示当前进度条的百分比。

// Parameters:

//     [IN]   pGfx

//            Pointer to a GDI+ Graphics object that indicates the graphic 

//            context.

//     [IN]   nPercentage

//            Current percentage of the progress bar.

//     [IN]   rpCtrl

//            Pointer to a GDI+ Rect object that indicates the dimensions of 

//            the entire control.

//     [IN]   rpEmpty

//            Pointer to a GDI+ Rect object that indicates the dimensions of 

//            the control's

//            portion currently left empty.

//     [IN]   rpFull

//            Pointer to a GDI+ Rect object that indicates the dimensions of 

//            the currently displayed bar.

//     [IN]   bHorizontal

//            TRUE if the progress is horizontal, otherwise FALSE.

//

// Return value:

//     CYLINDERPROGRESSCTRLST_OK

//        Function executed successfully.

//

virtual DWORD OnDrawText(Graphics* pGfx, int nPercentage, Rect* rpCtrl, 
//                       Rect* rpEmpty, Rect* rpFull, BOOL bHorizontal)

GetVersionI

以短数值形式返回类版本。

// Return value:

//     Class version. Divide by 10 to get actual version.

//

static short GetVersionI()

GetVersionC

以字符串值的形式返回类版本。

// Return value:

//     Pointer to a null-terminated string containig the class version.

//

static LPCTSTR GetVersionC()

历史

  • v1.0 (2003 年 6 月 27 日)
    首次发布

免责声明

本软件及附带文件按“原样”分发,不附带任何明示或暗示的保证。对于可能造成的任何损害甚至功能问题,概不负责。用户必须承担使用本软件的全部风险。

© . All rights reserved.