Description
This article describes a CStatic
derived Progress bar that allows "busy" times with no defined end to be indicated with more than just an hourglass cursor.
Adding the code to your project
The CKCBusyProgress control can be subclassed within a dialog by following these steps:
- Insert the .h and .cpp files into your project
- Add a static control to your dialog resource
- Add a member variable for the static control (eg
m_ctlBProgress
)
- Change the variable declaration from :
CStatic m_ctlBProgress;
to: CKCBusyProgress m_ctlBProgress;
- et voila! You have the control embedded!
Public Functions
void SetNumSteps(int nNumSteps)
Sets the number of visible blocks in the control
int GetNumSteps()
Gets the number of visible blocks in the control
void SetCurPos(int nCurPos)
Sets the current position of the marker
int GetCurPos()
Gets the current position of the marker
void SetInterBlockPadding(int nPadding)
Sets the number of pixels between each block
int GetInterBlockPadding()
Gets the number of pixels between each block
void SetSpeed(int nSpeed)
Sets the speed (in milliseconds) of visual updates when the control is in BPC_MODE_BUSY mode
int GetSpeed()
Gets the speed (in milliseconds) of visual updates when the control isin BPC_MODE_BUSY mode
bool IsRunning()
Indicates whether the control is currently indicating a busy state (The control must be in BPC_MODE_BUSY mode)
void SetMode(int nMode = BPC_MODE_BUSY)
Sets the mode of the control
Valid parameters are:
BPC_MODE_BUSY |
0x00000001 |
Puts the control into the BusyProgress mode (no range needed) |
BPC_MODE_PROGRESS |
0x00000002 |
Puts the control into the ProgressBar mode (can set a range - default is 0 .. 100) |
int GetMode()
Gets the current mode of the control
void SetRange(int nLower, int nUpper)
Sets the lower and upper bounds of the control for when it is in BPC_MODE_PROGRESS mode
void GetRange(int& nLower, int& nUpper)
Gets the lower and upper bounds of the control
void Recalc()
Request the control to recalculate its internal visual aspects and ratios
void Reset()
Call this to reset the control to the state it was when it was first created
void Start()
Request the control to start its "busy" mode. This will only work if the control's mode is BPC_MODE_BUSY
void End()
Request the control to end its "busy" mode. This will only work if the control's mode is BPC_MODE_BUSY and the Start() function was called prior to this
void StepIt()
Call this function to manually "step" the control marker. This function works in both modes. When called in BPC_MODE_BUSY mode, the function will automatically cause the marker to change direction once it has reached either left or right control edge
COLORREF GetColBkg()
Gets the colour of the background
void SetColBkg(COLORREF col)
Sets the colour of the background
Remember to call UseSysColBkg(false)
if you do not want changes in the system dialog colour to affect the control's background
COLORREF GetColBlockFace()
Gets the fill colour of the face of normal blocks
void SetColBlockFace(COLORREF col)
Sets the fill colour of the face of normal blocks
COLORREF GetColBlockEdge()
Gets the pen colour of the border of each normal block
void SetColBlockEdge(COLORREF col)
Sets the pen colour of the border of each normal block
COLORREF GetColBlockFaceHi()
Gets the fill colour of the face of highlighted blocks
void SetColBlockFaceHi(COLORREF col)
Sets the fill colour of the face of highlighted blocks
COLORREF GetColBlockEdgeHi()
Gets the pen colour of the border of each highlighted block
void SetColBlockEdgeHi(COLORREF col)
Sets the pen colour of the border of each highlighted block
void UseSysColBkg(bool bUse = true)
Indicates to the control whether its background is being drawn using the COLOR_3DFACE system colour or not. If bUse = true, the control will respond to WM_SYSCOLORCHANGE messages and update itself according to changes in system colours
void SetBusyType(int nType = BPC_BUSY_PINGPONG)
Indicates the type of motion employed when the control is running in BPC_MODE_BUSY mode. The 3 options are: BPC_BUSY_PINGPONG, BPC_BUSY_LTR, BPC_BUSY_RTL
int GetBusyType()
Gets the current type of motion that the control is using when in BPC_MODE_BUSY mode.
void SetBusyFill(int nFill = BPC_BUSYFILL_BLOCK)
Indicates the type of fill method used when the control is running in BPC_MODE_BUSY mode. The options are : BPC_BUSYFILL_BLOCK
and BPC_BUSYFILL_SMOOTH
int GetBusyFill()
Gets the type of fill method used when the control is running in BPC_MODE_BUSY mode.
void SetGranularity(int nGranularity = 5)
Sets the level of granularity used when in BPC_MODE_BUSY mode and using the BPC_BUSYFILL_SMOOTH fill option. The higher the granularity, the smoother the fill will appear, but it will also take longer to get from one side of the control to the other
int GetGranularity()
Gets the level of granularity used when in BPC_MODE_BUSY mode and using BPC_BUSYFILL_SMOOTH fill option.
Overridable Functions
virtual void DrawBackground(CDC& dc, CRect& rect)
Override this function if you want different background drawing logic. The CRect rect parameter contains the dimensions of the control's client area
virtual void DrawBlock(CDC& dc, CRect& rect)
Override this function if you want to change the drawing logic of a standard block in the control
The CRect rect parameter contains the dimensions of the block being drawn
virtual void DrawHiliteBlock(CDC& dc, CRect& rect)
Override this function if you want to change the drawing logic of a highlighted block in the control
The CRect rect parameter contains the dimensions of the block being drawn
virtual void DrawPartialBlock(CDC& dc, CRect& rect)
Override this function if you want to change the drawing logic of a partially highlighted block in the control
The CRect rect parameter contains the dimensions of the block being drawn
... and the control responds to messages ...
The following messages are defined for interaction with the control via the
SendMessage()
or
PostMessage()
functions:
Message |
WPARAM |
LPARAM |
Corresponding function |
BPM_SETNUMSTEPS |
Number of Steps (int) |
N/A |
SetNumSteps(int nNumSteps) |
BPM_SETCURPOS |
Current Marker Position(int) |
N/A |
SetCurPos(int nCurPos) |
BPM_SETIBPAD |
Interblock padding in pixels (int) |
N/A |
SetInterBlockPadding(int nPadding) |
BPM_SETSPEED |
Speed of busy mode in milliseconds (int) |
N/A |
SetSpeed(int nSpeed) |
BPM_SETRANGE |
Lower range of the progress bar (int) |
Upper range of the progress bar (int) |
SetRange(int& nLower, int& nUpper) |
BPM_SETMODE |
Mode of the control (int) |
N/A |
SetMode(int nMode) |
BPM_STARTBUSY |
N/A |
N/A |
Start() |
BPM_ENDBUSY |
N/A |
N/A |
End() |
BPM_STEPIT |
N/A |
N/A |
StepIt() |
BPM_SETBUSYTYPE |
Busy Mode Type (int) |
N/A |
SetBusyType(int nType) |
BPM_SETBUSYFILL |
Fill Type (int) |
N/A |
SetBusyFill(int nFill) |
BPM_SETGRANULARITY |
Granularity (int) |
N/A |
SetGranularity(int nGran) |
BPM_SETCOLBKG |
Colour (COLORREF) |
N/A |
SetColBkg(COLORREF col) |
BPM_SETCOLBFACE |
Colour (COLORREF) |
N/A |
SetColBlockFace(COLORREF col) |
BPM_SETCOLBEDGE |
Colour (COLORREF) |
N/A |
SetColBlockEdge(COLORREF col) |
BPM_SETCOLBFACEHI |
Colour (COLORREF) |
N/A |
SetColBlockFaceHi(COLORREF col) |
BPM_SETCOLBEDGEHI |
Colour (COLORREF) |
N/A |
SetColBlockEdgeHi(COLORREF col) |
BPM_RECALC |
N/A |
N/A |
Recalc() |
BPM_RESET |
N/A |
N/A |
Reset() |
BPM_USESYSCOL |
Flag (0 = false, non zero = true) |
N/A |
UseSysCol() |
Known issues / To do List
Must implement an orientation flag to indicate horizontal or vertical display
Contemplating adding a tooltip to indicate "percentage" complete when the control is in BPC_MODE_PROGRESS mode
Conclusion
If you want an alternative to the stock standard Windows CProgressCtrl control, give this one a spin. Let me know if you like it ;)
History
Version |
Release Date |
Change Log |
0.3 |
2003-05-05 |
Added BPM_XXXXX messages for the outstanding "SetXXX()" functions. The message list above has been updated
Fixed an acute threading bug (thanks to luedi for this one) |
0.21 |
2003-04-30 |
Fixed the threading bug which occurred when you rapidly called Start() in succession. Thanks to Mark Richards for letting me know |
0.20 |
2003-04-22 |
Added support for WM_SYSCOLORCHANGE message
Added flag for whether background colour was a system colour (true by default)
Changed all ON_MESSAGE() handlers to return an LRESULT (compatibility issue with VC7)
Added "Busy Type" flag to support different motion while in busy mode. Supported modes are: BPC_BUSY_PINGPONG , BPC_BUSY_LTR and BPC_BUSY_RTL
Added "Busy Fill" flag to support different filling methods while in busy mode. Supported fill modes are: BPC_BUSYFILL_BLOCK and BPC_BUSYFILL_SMOOTH
Updated source and demo .zip files
Fixed small bug in percentage calculation of the progress bar. |
0.1 |
2003-04-21 |
First public release |