CSkinProgress
状态栏中的位图进度条,
- SkinProgress_src_102.zip - 35 KB
- SkinProgressTest_exe_102.zip - 32 KB
- SkinProgressTest_exe_src_102.zip - 116 KB
引言
最初是基于 Chris Maunder 在 CProgressBar 上的工作开发的。这个 CSkinProgress 类旨在用于需要进行一些计算的任何地方。它具有以下特点:
- 位图进度条(默认,来自资源 - 只需少量代码修改 - 或来自外部源)
- 进度条自动调整大小
- 文本自动调整大小
- 进度条平移
- 可选的完成状态消息(百分比或计时)
- 以及更多...
所有功能都可以在运行时更改
- 根据您的心情或需求实时切换不同的位图(正常模式,警报条等)
- 更改文本以显示正在计算的进程的不同状态
- 如果提供更高的精度,则通过重新采样更改进度条的范围
- 以及更多...
现在是功能解释...
特点
1. 模式
CSkinProgress
允许在状态栏或对话框中创建进度条。这取决于您将使用的构造函数以及您将提供给 CSkinProgress
的参数。
状态栏
CSkinProgress ( LPCTSTR i_poStrMessage, int i_nUpper = 100, int i_nProgress = cSPT_PERCENT, int i_nPane = 0, int i_nSize = 200, CBitmap* i_poBitmap = NULL #ifdef dCSP_SLIDERBAR_METHOD ,BOOL i_bReverse = false #endif // dCSP_SLIDERBAR_METHOD );
使用此构造函数,您可以创建带有文本、完成状态、选择窗格、位图以及进度条是否从末尾显示的进度条。
对话框
#ifdef dCSP_DIALOG_PROGRESS CSkinProgress ( CWnd* i_poWndProgress, int i_nUpper = 100, CBitmap* i_poBitmap = NULL, #ifdef dCSP_SLIDERBAR_METHOD BOOL i_bReverse = false, #endif // dCSP_SLIDERBAR_METHOD CWnd* i_poWndMessage = NULL, LPCTSTR i_poStrMessage = NULL, int i_nProgress = cSPT_NONE ); #endif // dCSP_DIALOG_PROGRESS
如果激活了 dCSP_SLIDERBAR_METHOD
定义,您可以使用此构造函数在任何带有父级(重要)的 CWnd
对象中创建对话框中的进度条。您无需提供窗格号,但需要提供一个用于创建进度条的 CWnd
锚点,以及另一个用于显示文本的 CWnd
。
2. 大小调整
您可以为进度条提供一个大小。此大小仅在进度条位于状态栏且在窗格0中时使用,从而与文本共享。您可以选择3种文本共享模式
正数大小
如果给定大小为正,则进度条的大小为 FIXED
。因此,如果空间不足,文本将换行。
零大小
如果给定大小为零,则进度条的大小适合文本留下的剩余空间。因此,如果空间不足,文本永远不会换行。这只可能在完成消息占用太多空间时发生。
负数大小
如果给定大小为负,则进度条的大小适合文本留下的剩余空间(如果空间不足),否则使用给定大小。
3. 文本
您可以提供任何您想要的文本(注意:不要太长 - 最多128个字符)。
4. 窗格
您可以在状态栏中创建任意数量的窗格,只需遵循以下规则即可...
在字符串表中的 ID_INDICATORS
部分添加一个ID,否则文本将出现在窗格中。文本越长,窗格的宽度就越重要!
现在将此用户窗格ID添加到“MainFrm.cpp”文件开头的“indicators”数组中。第一个条目是窗格0。
然后,选择您将用于显示进度条的窗格号。例如,用户窗格是文本所在的窗格0
您甚至可以使用系统窗格,例如NUM-LOCK指示器所在的窗格3
5. 完成消息
您可以要求 CSkinProgress
在文本末尾添加一条消息,以提供当前的完成状态。进度条提供图形信息,但有时获得更多信息很有用。一个 enum
列表具有递增的值,每个值都有不同的含义。以下是不同类型的消息:
cSPT_NONE
:不添加任何消息,速度很快。cSPT_PERCENT
:添加一个简单的文本百分比完成报告,比NONE慢一点cSPT_TIMED
:添加一个功能齐全的消息,提供开始日期/时间、当前完成百分比、剩余百分比、剩余时间以及预计结束日期/时间 - 相当慢cSPT_AUTOSIZE
:根据窗格0中的剩余空间自动选择PERCENT和TIMED之间最佳消息 - 最慢。NEGATIVE
:取消括号(新功能)
您现在可以通过提供负数进度条来删除括号,就像您可以通过为窗格0中的进度条提供负数大小来阻止文本换行一样!
6. 位图
您可以选择默认的嵌入式位图(与 IDB_BMP_AQUA
相同)或使用资源位图(需要更改编译条件并修改 CSkinProgress::SetBitmap(...)
中的代码)
您还可以向 CSkinProgress
提供位图
7. 反向显示
未选中时,进度条从左侧(或垂直进度条的顶部)开始。
出于某些原因,您可以选择从进度条的末尾显示它。这对于对话框中的垂直条特别有用,它从底部开始,就像温度计一样。
代码
构造函数
状态栏
CSkinProgress::CSkinProgress ( // Default constructor )
使用“Work in progress”和下面给出的默认构造函数值,在状态栏中创建一个默认进度条。
CSkinProgress::CSkinProgress ( // Default constructor with parameters for status bar usage LPCTSTR i_poStrMessage, // Text to display int i_nUpper, // = 100 : Default range from 0 to // i_nUpper int i_nProgress, // = cSPT_PERCENT : Message type to add to the // text int i_nPane, // = 0 : Pane number in which // display the progress bar int i_nSize, // = 200 : Size of the progress bar if // in pane 0 CBitmap* i_poBitmap // = NULL : Pointer to a user bitmap #ifdef dCSP_SLIDERBAR_METHOD ,BOOL i_bReverse // = false : Reverse display of the // progress bar #endif // dCSP_SLIDERBAR_METHOD )
警告:此构造函数自原始版本 1.00/1.12dev 以来已更改!
最简单的状态栏构造函数是
CSkinProgress::CSkinProgress ( // Default constructor with parameters for status bar usage LPCTSTR i_poStrMessage, // Text to display )
对话框
#ifdef dCSP_DIALOG_PROGRESS CSkinProgress::CSkinProgress ( // Default constructor with parameters for dialog usage CWnd* i_poWndProgress, // Pointer to the anchor CWnd to use for the // progress bar int i_nUpper, // = 100, : Default range from 0 to // i_nUpper CBitmap* i_poBitmap, // = NULL : Pointer to a user bitmap #ifdef dCSP_SLIDERBAR_METHOD BOOL i_bReverse, // = false, : Reverse display of the // progress bar #endif // dCSP_SLIDERBAR_METHOD CWnd* i_poWndMessage, // = NULL, : Pointer to the anchor CWnd // to use for the text pane LPCTSTR i_poStrMessage, // = NULL : Text to display, int i_nProgress // = cSPT_NONE : Message type to add to the // text ) #endif // dCSP_DIALOG_PROGRESS
要使用对话框构造函数,请确保已设置 `dCSP_DIALOG_PROGRESS` 定义。您可以绕过文本窗格声明,因为我已将 `i_bReverse` 参数放在函数参数列表的中间。请注意您的编码,您也可以自行使用 `dCSP_SLIDERBAR_METHOD` 定义,以便为您的代码提供条件编译功能。
最简单的状态栏构造函数是
CSkinProgress::CSkinProgress ( // Default constructor with parameters for status bar usage CWnd* i_poWndProgress, // Pointer to the anchor CWnd to use for the // progress bar )
析构函数
CSkinProgress::~CSkinProgress ( // Destructor )
位图处理
BOOL CSkinProgress::SetBitmap ( // Change of progress bar image CBitmap* i_poBitmap // = NULL : Pointer to an existing bitmap #ifndef dCSP_TIMED_REDRAW ,BOOL i_bDisplay // = true : Display the changes #endif // dCSP_TIMED_REDRAW )
以下两个附加函数由 CSkinProgress::SetBitmap(...)
使用,以便复制/转换 TRUE/COLOR 位图图片(尚不支持映射颜色位图)。它们可以用于您自己的目的
BOOL CSkinProgress::CopyBitmap ( // Copy a bitmap CBitmap* o_poBitmap, // Pointer to an EXISTING but NOT INITIALIZED // bitmap CBitmap* i_poBitmap // Pointer to the source bitmap )
BOOL CSkinProgress::ConvBitmap ( // Convert a bitmap to a specified device context CBitmap* o_poBitmap, // Pointer to an EXISTING but NOT INITIALIZED // bitmap CBitmap* i_poBitmap, // Pointer to the source bitmap CDC* i_poDC // = NULL : Pointer to the DC to use for the // conversion, if NULL use the current DC )
进度接口
BOOL CSkinProgress::SetRange ( // Set the new range int i_nLower, // Minimum limit int i_nUpper, // Maximum limit int i_nStep, // = 1 : Step increment BOOL i_bResamble // = false : Resample the current position // from the new Lower and Upper values #ifndef dCSP_TIMED_REDRAW ,BOOL i_bDisplay // = true : Display the changes #endif // dCSP_TIMED_REDRAW )
int CSkinProgress::SetPos ( // Set <M_NRIGHT> value int i_nPos // Set a new current position #ifndef dCSP_TIMED_REDRAW ,BOOL i_bDisplay // = true : Display the changes #endif // dCSP_TIMED_REDRAW )
int CSkinProgress::OffsetPos ( // Forward of <NOFFSET> value int i_nOffset // Add the offset to the current position // (can be negative) #ifndef dCSP_TIMED_REDRAW ,BOOL i_bDisplay // = true : Display the changes #endif // dCSP_TIMED_REDRAW )
int CSkinProgress::SetStep ( // Set <M_NSTEP> value int i_nStep // Set the step increment )
int CSkinProgress::StepIt ( // Forward of <M_NSTEP> value #ifndef dCSP_TIMED_REDRAW BOOL i_bDisplay // = true : Display the changes #endif // dCSP_TIMED_REDRAW )
扩展进度接口
BOOL CSkinProgress::SetSize ( // Set size of the progress bar in pane 0 int i_nSize // Set the size of the progress bar #ifndef dCSP_TIMED_REDRAW ,BOOL i_bDisplay // = true : Display the changes #endif // dCSP_TIMED_REDRAW )
int CSkinProgress::GetSize ( // Get width or height of the progress bar in pixel, mostly used in // CSkinSlider )
int CSkinProgress::GetPos ( // Get <M_NRIGHT> value BOOL i_bPercent // = false )
int CSkinProgress::GetStep ( // Get <M_NSTEP> value )
int CSkinProgress::GetLower ( // Get <M_NLOWER> value )
int CSkinProgress::GetUpper ( // Get <M_NUPPER> value )
#ifdef dCSP_SLIDERBAR_METHOD int CSkinProgress::SetStart ( // Set <M_NLEFT> value int i_nStart // Set a new start position #ifndef dCSP_TIMED_REDRAW ,BOOL i_bDisplay // = true : Display the changes #endif // dCSP_TIMED_REDRAW ) #endif // dCSP_SLIDERBAR_METHOD
#ifdef dCSP_SLIDERBAR_METHOD int CSkinProgress::GetStart ( // Get <M_NLEFT> value BOOL i_bPercent // = false ) #endif // dCSP_SLIDERBAR_METHOD
void CSkinProgress::Reset ( // Reset the progress bar #ifndef dCSP_TIMED_REDRAW BOOL i_bDisplay // = true : Display the changes #endif // dCSP_TIMED_REDRAW )
文本接口
BOOL CSkinProgress::SetText ( // Set the new text LPCTSTR i_poStrMessage // New text to display #ifndef dCSP_TIMED_REDRAW ,BOOL i_bDisplay // = true : Display the changes #endif // dCSP_TIMED_REDRAW )
BOOL CSkinProgress::SetProgress ( // Set <M_NPROGRESSTEXT> value int i_nProgress // Set progress text #ifndef dCSP_TIMED_REDRAW ,BOOL i_bDisplay // = true : Display the changes #endif // dCSP_TIMED_REDRAW )
int CSkinProgress::GetProgress ( // Get <M_NPROGRESSTEXT> value )
更新进程
BOOL CSkinProgress::RefreshPanes ( // Resize the text pane and the progress bar )
编译源代码
通过条件编译管理 CSkinProgress
功能!以下是每个编译定义的解释:
dCSP_DIALOG_PROGRESS
:激活在对话框中使用CSkinProgress
dCSP_TIMED_REDRAW
:当设置/取消注释时,不在每个事件时重绘/刷新文本/进度条,而是每秒只刷新50次(足以保证准确性)。在某些循环中,CSkinProgress::StepIt()
每秒可以轻松调用超过50次!
dCSP_VERTICAL_BAR
:激活完整的垂直条计算。不用于状态栏,但可以在设置dCSP_DIALOG_PROGRESS
时使用
dCSP_SLIDERBAR_METHOD
:将进度条转换为完整的滑块条。允许条反向显示,因此如果要使用CSkinProgress
的“反向”功能,请取消注释此定义
特定的定义用于非常实验性的目的,请谨慎使用它们
dCSP_RESOURCE_BITMAP:
使用资源位图作为默认位图。资源位图的当前 ID 名称是IDB_AQUABAR
,但您可以通过修改CSkinProgress::SetBitmap(...)
中的资源位图名称来更改此名称
dCSP_CREATE_BITMAP_FILE:
在CSkinProgress::SetBitmap(...)
结束时,在 C 盘根目录创建源文件!用于更改默认嵌入式位图:创建一个CSkinProgress
并提供用户位图,您将获得转换后的位图到源文件中!
dCSP_DISPLAY_STRETCH:
显示用于创建图像列表的拉伸图片。除了文档或验证CSkinProgress::SetBitmap(...)
函数之外,此功能几乎没有用处
进度条位图
现在,为了完成对 CSkinProgress
图形引擎的简短介绍,我们来概述一下用于创建进度条图片的方法。一个位图被提供给 CSkinProgress::SetBitmap(...)
...
此位图分为9个部分...
从左到右,以下是含义和关联的 ID 定义
cSPB_START
:进度条背景的开始
cSPB_BEFORE
:条形图开始前的元素,可以是高光
cSPB_LEFT
:条形的左侧部分,其开头
cSPB_CENTER
:进度条的中心部分,可解释为抓取结
cSPB_BAR
:条形主体
cSPB_RIGHT
:条形的右侧部分,其末尾
cSPB_AFTER
:条形末尾后的元素,可以是阴影
cSPB_BACKGROUND
:进度条背景
cSPB_END
:进度条背景的结束
要创建您自己的位图皮肤,请制作任何具有如上所述9个部分的位图。位图的高度并不重要(顺便说一句不要太大 - 当然不超过32像素),宽度应为9的倍数(重要),因此:宽度 % 9 = 0!看看奖励/隐藏位图,了解 CSkinProgress
如何让您制作有趣的东西 ;)
关键元素的相对位置是根据进度条的范围及其当前位置计算的。然后,一旦将这些值作为百分比获取,就计算这些关键元素的绝对位置。现在只需按照定义的顺序将它们放置在进度条图像上,以便某些元素可以隐藏其他元素,就像在 Paint Shop Pro 中的图层一样。
蓝色列是元素的精确位置。
红色列是基于元素宽度的基准列。
这三个/四个字母是 `CSkinProgress::OnPaint()` 函数中注释的关键,方便您轻松找到它们...
版本历史
修订版 1.02:2003 年 7 月 12 日 14:01:53 (Kochise)
基准:CSkinProgress 1.32dev- 提取文件:无错误
解析文件:无错误
差异引擎:无错误
修改.public.constructor:CSkinProgress
触碰.protected.function:CreateCommon
修改.protected.function:ProgressInStatusBar
修改.protected.function:ProgressInDialog
修改.public.function:SetRange
触碰.public.function:SetPos
修改.public.function:GetPos
触碰.public.function:SetStart
修改.public.function:GetStart
修改.public.function:Reset
添加.public.function:SetProgress
添加.public.function:GetProgress
修改.public.function:RefreshPanes
触碰.protected.function:CompactText
修改.protected.function:GetTimed
修改.protected.function:UpdateProgress
修改.protected.function:OnPaint
编译项目文件:无错误
打包文件:无错误
修订版 1.01:2003 年 7 月 6 日 22:08:37 (Kochise)
基准:CSkinProgress 1.28 Devel- 提取文件:无错误
解析文件:无错误
差异引擎:无错误
修改.public.constructor:CSkinProgress
添加.public.constructor:CSkinProgress
修改.public.function:SetBitmap
修改.public.function:ConvBitmap
修改.public.function:SetRange
修改.public.function:SetPos
修改.public.function:OffsetPos
修改.public.function:StepIt
修改.public.function:SetSize
添加.public.function:GetSize
添加.public.function:GetPos
添加.public.function:GetStep
添加.public.function:GetLower
添加.public.function:GetUpper
添加.public.function:SetStart
添加.public.function:GetStart
添加.public.function:Reset
修改.public.function:SetText
变异.function:protected.ResizeTextPane->public.RefreshPanes
修改.public.function:RefreshPanes
变异.function:public.Clear->protected.Clear
添加.protected.function:GetTargetRect
变异.protected.function:Create->CreateCommon
修改.protected.function:CreateCommon
添加.protected.function:ProgressInStatusBar
添加.protected.function:ProgressInDialog
修改.protected.function:CompactText
添加.protected.function:UpdateProgress
修改.protected.function:OnPaint
编译项目文件:无错误
打包文件:无错误
修订版 1.00:2003 年 5 月 25 日 13:25:12 (Kochise)
第一个存档版本并发布到 CodeProject。基准:CSkinProgress 1.12 Devel
- 添加.public.constructor:CSkinProgress
添加.public.constructor:CSkinProgress
添加.public.function:SetRange
添加.public.function:SetText
添加.public.function:SetSize
添加.public.function:SetBitmap
添加.public.function:CopyBitmap
添加.public.function:ConvBitmap
添加.public.function:SetPos
添加.public.function:OffsetPos
添加.public.function:SetStep
添加.public.function:StepIt
添加.public.function:Clear
添加.public.destructor:~CSkinProgress
添加.protected.function:Create
添加.protected.function:GetStatusBar
添加.protected.function:ResizeTextPane
添加.protected.function:CompactText
添加.protected.function:GetTimed
添加.protected.function:OnEraseBkgnd
添加.protected.function:OnPaint
添加.protected.function:OnSizing
添加.protected.function:OnSize
添加.protected.function:OnTimer
编译项目文件:无错误
打包文件:无错误