This article describes the implementation of
CProSliderCtrl class, which uses custom draw functionality of
CSliderCtrl class to combine Slider Control and Progress bar in one window.
This kind of a control is especially required for streaming multimedia applications, because of its less window space requirements and its freezing capability also helps in preventing unbuffered scenes to be viewed/listened.
- 1.0 First release in 2004
- 1.1 Updated the project to work with recent Visual Studio 2017
CSliderCtrl has the following features:
- All the basic features of the standard
- Custom draw borders, thumb, channel and progress bar
- Borders could be shown or hidden
- The colors could be changed on demand
- The slider thumb could be disabled (frozen)
- Flicker free progress bar
The custom draw system heavily uses recursive functions to draw the windows' objects and uses negative exponential random numbers in order to get better colors (will be described later).
A recursive function calls itself for many times, until a control mechanism stops recursion. The prototype of this kind of function is given below:
void Recursion(int val)
This is the easiest way to calculate a given color's lighter versions and also gives 3D look to the objects. You may examine the differences by commenting the recursion line inside the function in the given source code.
Since this recursive drawing function lightens the colors every time it calls itself, giving darker color values will result in better colored 3D objects. In order to generate dark colors to use in this recursive function, a negative exponential random number (nexp) generator is implemented. The simulation of the function in Matlab for the input 255 is given in the figure below:
How to Use CProSliderCtrl Class
The exported functions are:
void _GetRange(int& nLower, int& nUpper);
void _SetRange(short nLower, short nUpper);
void _SetRange32(int nLower, int nUpper);
COLORREF _SetBkColor(COLORREF clrNew);
COLORREF _SetThumbColor(COLORREF clrNew);
COLORREF _SetChColor(COLORREF clrNew);
int _OffsetPos(int nPos);
int _SetPos(int nPos);
int _SetStep(int nStep);
HRESULT _EnableBorders(BOOL bEnable=TRUE);
This class uses the function
OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult) to handle the custom drawing tasks. When the system sends
TBCD_CHANNEL message, the class draws the progress bar to the area of the slider channel.
How to Use CProSliderCtrl Class in Your Applications
Simply add the class to your workspace and define the slider control variable as:
and use the functions listed above to control progress bar, the functions starting with a "
_" are related to progress bar controls.
This code is free to use in any kind of application at your own risk.