Visual C++ 10.0Win10Visual Studio .NET 2002Visual C++ 7.1Visual Studio 6Visual C++ 7.0Visual Studio 2013Visual C++ 6.0MFC中级开发Visual StudioWindowsC++
合并滑块控件和进度条窗口的类






4.89/5 (29投票s)
关于如何使用自定义绘制将滑块控件和进度条合并到一个类的文章
引言
本文描述了 CProSliderCtrl
类的实现,该类使用 CSliderCtrl
类的自定义绘制功能将滑块控件和进度条组合在一个窗口中。
这种控件特别适用于流媒体多媒体应用程序,因为它需要的窗口空间更少,并且其冻结功能也有助于防止查看/收听未缓冲的场景。
版本
- 1.0 2004 年首次发布
- 1.1 更新了项目以使用最新的 Visual Studio 2017
特点
CSliderCtrl
具有以下特性
- 标准
CSliderCtrl
和CProgressCtrl
类的所有基本功能 - 自定义绘制边框、滑块、通道和进度条
- 边框可以显示或隐藏
- 可以根据需要更改颜色
- 可以禁用(冻结)滑块
- 无闪烁进度条
背景
自定义绘制系统大量使用递归函数来绘制窗口对象,并使用负指数随机数以获得更好的颜色(稍后将对此进行描述)。
递归函数会多次调用自身,直到控制机制停止递归。这种函数的原型如下所示
void Recursion(int val)
{
// computing stuff
val ++;
if(val<=255)Recursion(val);
return;
}
这是计算给定颜色的较浅版本的最简单方法,并且还可以为对象提供 3D 外观。您可以通过注释给定源代码中函数内的递归行来检查差异。
由于此递归绘图函数每次调用自身时都会使颜色变浅,因此给出较深的颜色值将产生颜色更好的 3D 对象。 为了生成在此递归函数中使用的深色,实现了一个负指数随机数 (nexp) 生成器。 下图给出了 Matlab 中输入 255 的函数仿真
如何使用 CProSliderCtrl 类
导出的函数有
// Gets the current lower and upper limits, or range, of the progress bar
// control.
void _GetRange(int& nLower, int& nUpper);
// Sets the upper and lower limits of the progress bar control's range and
// redraws the bar to reflect the new ranges.
void _SetRange(short nLower, short nUpper);
// Sets the upper and lower limits of the progress bar control's range and
// redraws the bar to reflect the new ranges.
void _SetRange32(int nLower, int nUpper);
// Sets the background color for the progress bar.
COLORREF _SetBkColor(COLORREF clrNew);
// Sets the thumb color
COLORREF _SetThumbColor(COLORREF clrNew);
// Sets the channel color
COLORREF _SetChColor(COLORREF clrNew);
// Gets the current position of the progress bar.
int _GetPos(void);
// Advances the current position of a progress bar control by a specified
// increment and redraws the bar to reflect the new position.
int _OffsetPos(int nPos);
// Sets the current position for a progress bar control and redraws the
// bar to reflect the new position.
int _SetPos(int nPos);
// Specifies the step increment for a progress bar control.
int _SetStep(int nStep);
// Advances the current position for a progress bar control by the step
// increment and redraws the bar to reflect the new position.
int _StepIt(void);
// De/Freezes the slider and returns the prev. state
BOOL Freeze(void);
// Enables/Disables borders
HRESULT _EnableBorders(BOOL bEnable=TRUE);
// Test if the borders are enabled or not
BOOL _IsEnabled(void);
CProSliderCtrl 类
此类使用函数 OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
来处理自定义绘制任务。 当系统发送 TBCD_CHANNEL
消息时,该类将进度条绘制到滑块通道的区域。
如何在应用程序中使用 CProSliderCtrl 类
只需将该类添加到您的工作区并将滑块控件变量定义为
// Pro Slider handle
CProSliderCtrl m_ProSlider;
并使用上面列出的函数来控制进度条,以“_
”开头的函数与进度条控件有关。
使用条款
此代码可以免费用于任何类型的应用程序,风险自负。