2014년 10월 27일 월요일

CTextProgressCtrl. 텍스트가 들어가있는 프로그레스바

textprogressctrl_demo.zip


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); Specifies whether or not the text for the control will be displayed during updates
COLORREF SetBarColor(COLORREF crBarClr = CLR_DEFAULT); Specifies the colour of the progress control bar, and returns the previous colour. If the colour is set as CLR_DEFAULT then the Windows default colour is used.
COLORREF GetBarColor(); Returns the colour of the progress control bar, or CLR_DEFAULT if the default Windows colours are being used.
COLORREF SetBarBkColor(COLORREF crBarClr = CLR_DEFAULT); Specifies the colour for the control's background, and returns the previous background colour. If the colour is set as CLR_DEFAULT then the Windows default colour is used.
COLORREF GetBarBkColor(); Returns the colour of the control's background, or CLR_DEFAULT if the default Windows colours are being used.
COLORREF SetTextColor(COLORREF crBarClr = CLR_DEFAULT); Specifies the colour of the text, and returns the previous colour. If the colour is set as CLR_DEFAULT then the Windows default colour is used.
COLORREF GetTextColor(); Returns the colour of the text, or CLR_DEFAULT if the default Windows colours are being used.
COLORREF SetTextBkColor(COLORREF crBarClr = CLR_DEFAULT); Specifies the background colour of the text, and returns the previous background colour. If the colour is set as CLR_DEFAULT then the Windows default colour is used.
COLORREF GetTextBkColor(); Returns the background colour of the text, or CLR_DEFAULT if the default Windows colours are being used.
BOOL SetShowPercent(BOOL bShow) Sets whether or not to show the percentage value of the bar, and returns the old value
DWORD AlignText(DWORD dwAlignment = DT_CENTER) Sets the text alignment and returns the old value
BOOL SetMarquee(BOOL bOn, UINT uMsecBetweenUpdate) Sets whether or not the progress control is in marquee mode, as well as the interval in milliseconds between steps of the marquee block
int SetMarqueeOptions(int nBarSize) Sets the size of the marquee as a percentage of the total control width
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, and colours are strictly windows default colours. (These may be changed in the future versions.)

Acknowledgements
Thanks to Keith Rule for his CMemDC class.

Updates
Pete Arends went to town on the code. His updates:

Set the font used to the parent window font
Added SetTextColour() and GetTextColour() functions
Added a bunch of message handlers, so the control now responds to the standard progress bar PBM_* messages. It is now possible to control the text progress control by sending messages to it. (works great from a worker thread).
Added 2 new messages PBM_SETSHOWTEXT and PBM_SETTEXTCOLOR.
Added an OnGetPos() handler. The function GetPos() now works!!
Thanks Pete!

3 Jan 05: Kriz has also extended the code with two basic methods that allow switching between the three alignment styles LEFT, CENTER and RIGHT - even on the fly if that's needed.

Changes to the code
Created a protected DWORD member m_dwTextStyle
Disabled all dwTextStyle variables in OnPaint or replaced them by
m_dwTextStyle
Added two methods called AlignText and AlignTextInvalidate
Syntax
BOOL AlignText(DWORD aligment = DT_CENTER);
BOOL AlignTextInvalidate(DWORD aligment = DT_CENTER);
Params/Return:
"alignment" can be DT_LEFT, DT_CENTER (default) or DT_RIGHT. Using the invalidating version forces the control to repaint itself automatically. Both methods will return FALSE if a wrong alignment flag was given, otherwise they will return TRUE to the caller.

Thank you Kriz!

I've also updated the code so it compiles in VC7.X.

9 mar 06: Tony Bommarito has updated the code to include more settings for colours, made corrections to vertical text mode and added a new marquee mode.

26 Feb 07: Tony Mommarito has provided further updates:

Fixed bug where outside edge of progress bar wasn't drawn on XP when using an application manifest.
Added complete turn-off of marquee mode in a slightly different manner than that suggested in Robert Pickford message.
Fixed Unicode compile bug reported in dev75040 message.
Added three SLN and VCPROJ file sets; one each for VS2002, VS2003 and VS2005. By removing the VS… extension from the proper set, any of the three IDEs can be used.
License
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author
Chris Maunder



Sitebuilder, Editor, Staff, Admin Chris is the Co-founder, Administrator, Architect, Chief Editor and Shameless Hack who wrote and runs The Code Project. He's been programming since 1988 while pretending to be, in various guises, an astrophysicist, mathematician, physicist, hydrologist, geomorphologist, defence intelligence researcher and then, when all that got a bit rough on the nerves, a web developer. He is a Microsoft Visual C++ MVP both globally and for Canada locally.

His programming experience includes C/C++, C#, SQL, MFC, ASP, ASP.NET, and far, far too much FORTRAN. He has worked on PocketPCs, AIX mainframes, Sun workstations, and a CRAY YMP C90 behemoth but finds notebooks take up less desk space.

He dodges, he weaves, and he never gets enough sleep. He is kind to small animals.

Chris was born and bred in Australia but splits his time between Toronto and Melbourne, depending on the weather. For relaxation he is into road cycling, snowboarding, rock climbing, and storm chasing.
Occupation: Founder
Company: The Code Project
Location: Canada Canada

Other popular Miscellaneous articles:
MFC Grid control 2.26
A fully featured MFC grid control for displaying tabular data. The grid is a custom control derived from CWnd
Themed Windows XP style Explorer Bar
A fully customizable Windows XP style Explorer Bar that supports Windows XP themes and animated expand/collapse with transparency.
TaskbarNotifier, a skinnable MSN Messenger-like popup in C# and now in VB.NET too
The TaskbarNotifier class allows to display an MSN Messenger-like animated popup with a skinned background
CPPToolTip v2.1
A class that allows you to display your data for a control as tooltip
Formula Editor
Formula-editor for editing and exporting mathematical content

댓글 없음: