![]() |
Desktop Development »
Miscellaneous »
General
Intermediate
A class to combine Slider Control and Progress Bar windowsBy Cem KARACAAn article on how to combine Slider Controls and Progress bar into one class using custom draw. |
VC6, VC7, VC7.1Win2K, WinXP, Win2003, MFC, Dev
|
|
Advanced Search |
|
|
|
||||||||||||||||

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 preventing unbuffered scenes to be viewed/listened.
CSliderCtrl has the following features:
CSliderCtrl and CProgressCtrl classes,
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 functions is given below:
void Recursion(int val) { // computing stuff val ++; if(val<=255)Recursion(val); return; }
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:

The exported functions are:
// 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);
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.
Simply add the class to your workspace and define the slider control variable as:
// Pro Slider handle CProSliderCtrl m_ProSlider;
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 applications at your own risk.
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 7 Jan 2004 Editor: Smitha Vijayan |
Copyright 2004 by Cem KARACA Everything else Copyright © CodeProject, 1999-2009 Web11 | Advertise on the Code Project |