Progress control with Text
Download
Source Code and Example Project.
Latest Changes (Jeremy Davis)
26th May 1998
This is a simple CProgressCtrl derived class that allows text to be displayed on top of the progress bar in much the same way as many "Setup" programs display the progress of long operations.
The control is extremely simple and allows the same operations as a standard CProgressCtrl, as well as:
void SetShowText(BOOL bShow);
which determines whether or not the text for the control will be displayed during updates. To set the text to be displayed use the standard CWnd::SetWindowText. If you call SetShowText(TRUE) but do not specify any window text using CWnd::SetWindowText, then the percentage fraction of progress will be displayed as default.
To use the control, just include a CProgressCtrl in your app as per usual (either dynamically or by using a dialog template) and change the variable type from CProgressCtrl to CTextProgressCtrl. (Make sure you include TextProgressCtrl.h)
At present the progress is only displayed as a smooth bar. (This may be changed in the future versions.)
Acknowledgements
Thanks to Keith Rule for his CMemDC class.
Modifications
26 May 1998 : Jeremy
Davis added SetForeColour,
SetBkColour,
SetTextForeColour, SetTextBkColour, GetForeColour, GetBkColour, GetTextForeColour, GetTextBkColour.
| void SetForeColour(COLORREF col) | Sets the bar colour of the progress bar. |
| void SetBkColour(COLORREF col) | Sets the background colour of the progress bar. |
| void SetTextForeColour(COLORREF col) | Sets the colour of the text when the bar is not covering it. |
| void SetTextBkColour(COLORREF col) | Set the colour of the text when the bar is covering it. |
| COLORREF GetForeColour() | Returns the bar colour of the progress bar. |
| COLORREF GetBkColour() | Returns the background colour of the progress bar. |
| COLORREF GetTextForeColour() | Returns the colour the the text when the bar is not covering it. |
| COLORREF GetTextBkColour() | Returns the colour of the text when the bar is covering it. |
Last updated: 30 May 1998

Comments
interesting
Posted by Diana104 on 03/28/2011 10:05amYour article is very interesting thanks a lot but i'mn trying to implement your code in VS 2008 but i'm having the following error if you can help: error C2440: 'static_cast'B_: impossible de convertir de 'LRESULT (__thiscall CTextProgressCtrl::* )(UINT,LPCTSTR)' en 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)' thx in advance
ReplyError compiling in VC7
Posted by Legacy on 09/27/2002 12:00amOriginally posted by: FrAnK
When compiling the code in VC7 the following error occures:
D:\Projects\MinorApp\TextProgressCtrl.cpp(152) : error C2440: 'static_cast' : cannot convert from 'LRESULT (__cdecl *)(UINT,LPTSTR)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'
Even when changing to WPARAM and LPARAM the code will not compile!
It worked great with VC6!
Is there a setting in VC7 I should switch on (or off!) ?
FrAnK.
-
ReplyFor VC7
Posted by Gyuha on 05/14/2004 10:19pmTextProgressCtrl.h ================ afx_msg LRESULT OnSetText(WPARAM , LPARAM szText); afx_msg LRESULT OnGetText(WPARAM cchTextMax, LPARAM szText); TextProgressCtrl.cpp ======================== LRESULT CTextProgressCtrl::OnSetText(WPARAM, LPARAM szText) { LRESULT result = Default(); if ( (!szText && m_strText.GetLength()) || (szText && (m_strText != (LPCTSTR)szText)) ) { m_strText = (LPCTSTR)szText; Invalidate(); } return result; } LRESULT CTextProgressCtrl::OnGetText(WPARAM cchTextMax, LPARAM szText) { if (!_tcsncpy((LPTSTR)szText, m_strText, (UINT)cchTextMax)) return 0; else return min(cchTextMax, (UINT)m_strText.GetLength()); } ............. Good Luck...ReplySmall change to class so you don't have to keep track of an i variable and set position
Posted by Legacy on 12/25/2001 12:00amOriginally posted by: Eric Steimle
Replyhttp://www.codeguru.com/controls/text_progressctrl.shtml
Posted by Legacy on 12/25/2001 12:00amOriginally posted by: Eric Steimle
ReplyHere are changes for ProgressCtrl messages PBM_
Posted by Legacy on 10/26/2001 12:00amOriginally posted by: Krazer
ReplyVertical progress bar text support
Posted by Legacy on 10/04/2001 12:00amOriginally posted by: Roger Allen
ReplyProgress bar with file open action...
Posted by Legacy on 05/10/2001 12:00amOriginally posted by: Bruce Sohn
The code gives me lots of help.
I want to use the source to apply to such as 'file open' action.
If I open some file(text file, etc.), the progress bar will start increase in proportion to the file size.
The larger file size, the slower its increasing speed.
The progress bar code with 'file open' action will be needed. Instead of 'file open' action, any time-consuming action will be included.
Go for it!
ReplyGetPos() broken just like GetRange()
Posted by Legacy on 03/20/2000 12:00amOriginally posted by: David Grigsby
ReplyHow can i change the text font?
Posted by Legacy on 06/11/1999 12:00amOriginally posted by: Leigh
How can i change the text font size and style?
Reply
Vertical Control support added
Posted by Legacy on 04/19/1999 12:00amOriginally posted by: Klaus Kurzawa
ReplyLoading, Please Wait ...