|
|
Comments and Discussions
|
|
 |

|
I compile OK with MFC in VS 2010. The only thing I get is CMemDC has defined by MFC before, so I change the CMemDC in CMemDC.h to CKMemDC ('K' in Keith Rule) and change all references in "CTextProgressCtrl.cpp". Any everything work well after that.
|
|
|
|
|

|
Great job! It helps me a lot.
|
|
|
|

|
i compiled the demo project, compiled and ran without any problem
then moved the source code for the progress control and added it to my project and it took less than 2 minutes to integrate it to my application.
really nice. thanks
|
|
|
|

|
I had a minor problem: When a I created a dialog that overlaps with the progress bar and the dialog was closed, the
control wasn't redraw correctly.
To fix this change the OnEraseBkgnd message handler
BOOL CTextProgressCtrl::OnEraseBkgnd(CDC* /*pDC*/)
{
Invalidate();
return TRUE;
}
|
|
|
|

|
This Modification can change the bouncing Progress-Bar into a scrolling Progress-Bar.
Add to .h :
Global:
#ifndef PBM_SETSCROLL
#define PBM_SETSCROLL (WM_USER+12)
#endif
Class:
inline BOOL SetScroll(BOOL bOn)
{ ASSERT(::IsWindow(m_hWnd)); return ((BOOL) ::SendMessage(m_hWnd, PBM_SETSCROLL, (WPARAM)bOn, 0)); }
...
afx_msg LRESULT OnSetScroll(WPARAM bShow, LPARAM);
...
BOOL m_bScroll;
Add to .cpp :
Constructor:
m_bScroll = False;
Message Map:
ON_MESSAGE(PBM_SETSCROLL, OnSetScroll)
New Function:
LRESULT CTextProgressCtrl::OnSetScroll(WPARAM bShow, LPARAM)
{
// call a common routine to redraw window
CommonPaint();
// set new percent completed display state, returning old one
BOOL bOldShow = m_bScroll;
m_bScroll = (BOOL)bShow;
return ((LRESULT)bOldShow);
}
In OnTimer change:
if ((nDirection == 1) && (nPosition >= nMax))
nDirection = -1;
else if ((nDirection == -1) && (nPosition <= m_nMin))
nDirection = +1;
to:
if(m_bScroll)
{
if(nPosition >= nMax) nPosition = m_nMin;
}
else
{
if ((nDirection == 1) && (nPosition >= nMax))
nDirection = -1;
else if ((nDirection == -1) && (nPosition <= m_nMin))
nDirection = +1;
}
That's it.
|
|
|
|

|
this code below add "Time Remaining" to TextProgressCtrl !!!
in .h you have to add :
inline BOOL SetShowTimeRemaining(BOOL bShow)
{ ASSERT(::IsWindow(m_hWnd)); m_dwTimer=GetTickCount(); return ((BOOL) ::SendMessage(m_hWnd, PBM_SETSHOWTIMEREMAINING, (WPARAM)bShow, 0)); }
...
afx_msg LRESULT OnSetShowTimeRemaining(WPARAM bShow, LPARAM);
...
DWORD m_dwTimer;
BOOL m_bShowTimeRemaining;
in .cpp you have to add :
m_dwTimer=GetTickCount();
m_bShowTimeRemaining = TRUE;
...
ON_MESSAGE(PBM_SETSHOWTIMEREMAINING, OnSetShowTimeRemaining)
inline CString ToHMS(DWORD dwTime)
{
CString str;
int iHours=dwTime/3600;
str.Format("%d:%02d:%02d",iHours,dwTime/60-iHours*60,dwTime%60);
return str;
}
LRESULT CTextProgressCtrl::OnSetShowTimeRemaining(WPARAM bShow, LPARAM)
{
// call a common routine to redraw window
CommonPaint();
// set new percent completed display state, returning old one
BOOL bOldShow = m_bShowTimeRemaining;
m_bShowTimeRemaining = (BOOL)bShow;
return ((LRESULT)bOldShow);
}
in OnPaint() method, below if(m_bshowPercent) str.AppendFormat(_T("%d%%"), (int)((dFraction * 100.0) + 0.5));
if (m_bShowTimeRemaining)
{
if(m_nPos>0)
{
DWORD dwElapsed = (GetTickCount()-m_dwTimer)/1000; // Time Elapsed
DWORD dwRemaining = (dwElapsed*m_nMax/m_nPos)-dwElapsed; // Time Remaining
str.AppendFormat(_T(" - EstimatedTimeRemaining: %s"),ToHMS(dwRemaining));
}
}
Regards, OCH
-- modified at 7:12 Wednesday 29th August, 2007
|
|
|
|

|
Hello Chris,
I have a out question out of scope of this article
I use C# so I was wondering if u know how to get the windows constants values
for these especially:
DT_BOTTOM
DT_CALCRECT
DT_CENTER
DT_END_ELLIPSIS
DT_MODIFYSTRING
DT_EXPANDTABS
DT_EXTERNALLEADING
DT_HIDEPREFIX
DT_INTERNAL
DT_LEFT
DT_MODIFYSTRING
DT_NOCLIP
DT_NOFULLWIDTHCHARBREAK
DT_NOPREFIX
DT_PATH_ELLIPSIS
DT_PREFIXONLY
DT_RIGHT
DT_RTLREADING
DT_SINGLELINE
DT_TABSTOP
DT_TOP
DT_VCENTER
DT_WORDBREAK
DT_WORD_ELLIPSIS
Thanks
|
|
|
|

|
Great class, thanks!
Question:
Class CMemDC differs from it's original version by Keith Rule. I've encountered some strange behavior with this version. Where did you get this version?
Live and let live!
|
|
|
|

|
Wonderful class - thanks guys. Only one little fault.
The SetMarquee function only works properly to turn marquee mode ON - doesn't turn if off completely.
I changed OnSetMarquee() to be as follows:
// set marquee style
if ((BOOL)bShow)
ModifyStyle(0, PBS_MARQUEE);
else
ModifyStyle(PBS_MARQUEE, 0);
// can't have percent complete for this style
m_bShowPercent = !(BOOL)bShow;
Change is not made without inconvenience, even from worse to better.
Samuel Johnson
|
|
|
|

|
Hi,
First let me tell you thanks - this is a really nice class. Very useful and easy to use. I just wanted to share a couple of comments that may help clarify what I found and also help anyone who may encounter the same.
I got this to work fine on VC++ 2005, after making a change in the TextProgressCtrl.cpp file. There is a section starting at line 235 as below:
// draw text if needed
CString str;
GetWindowText(str);
if (m_bShowPercent)
str.AppendFormat("%d%%", (int)((dFraction * 100.0) + 0.5));
I dont understand the AppendFormat method, I could not find such call for CString class, so I changed the line to the following:
str.Format(L"%d%%", (int)((dFraction * 100.0) + 0.5));
//removed the Append word and added a L to "%d%d"
It worked wonderfully under VS2005
Additionally, if anyone will be customizing this further, it would be nice to have a method to allow a bouncing progress bar, sort of modified marquee style so it bounces back.
Any helpful comments will be appreciated - otherwise thanks for sharing this with everyone.
dev75040 - Victor
dev75040@yahoo.com
|
|
|
|

|
The demo project is still showing the old / previous version of the Progress Control with Text. Can you update it to the new version?
Thanks, André
|
|
|
|

|
would it have been possible to use ExtTextOut to render the text, just changing the lpRect param to control the clipping (+ ETO_CLIPPED of course)?
this is not a criticism, its just that i've not tried it before and wondered if anyone else had.
.dan.g.
AbstractSpoon Software
abstractspoon2_at_optusnet_dot_com_dot_au
|
|
|
|

|
It's simple and useful, thanks chris smart work.
liansp
|
|
|
|

|
Hi Chirs,
Any chance you can update this to use XP themes?
|
|
|
|

|
Hi, Chris
Is very Good, this Control.
I have detect one problem, when I call function
SetRange32(0, 0)
The CPU is 100%.
If I comment:
void CTextProgressCtrl::OnPaint()
{
//if (m_nMin >= m_nMax)
// return;
...
}
Not occur ???.
|
|
|
|

|
Hi,
I cant get the example project to compile under VC7 (.net), also i have no idea as to what the problem is as im to inexperienced to understand!
The compiler throws these errors:
c:\Documents and Settings\Joe\Desktop\text_progressctrl_demo\TextProgressCtrl.cpp(157): error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall CTextProgressCtrl::* )(UINT,LPCTSTR)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'
c:\Documents and Settings\Joe\Desktop\text_progressctrl_demo\TextProgressCtrl.cpp(158): error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall CTextProgressCtrl::* )(UINT,LPTSTR)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'
c:\Documents and Settings\Joe\Desktop\text_progressctrl_demo\TextProgressCtrl.cpp(165): error C2440: 'static_cast' : cannot convert from 'void (__thiscall CTextProgressCtrl::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'
c:\Documents and Settings\Joe\Desktop\text_progressctrl_demo\TextProgressCtrl.cpp(166): error C2440: 'static_cast' : cannot convert from 'void (__thiscall CTextProgressCtrl::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'
c:\Documents and Settings\Joe\Desktop\text_progressctrl_demo\TextProgressCtrl.cpp(170): error C2440: 'static_cast' : cannot convert from 'void (__thiscall CTextProgressCtrl::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'
Any ideas?
Joe
#
|
|
|
|
|

|
Easy to implement!
|
|
|
|

|
Dear Chris,
I would like to change the font in the progress bar. I use the CWnd::SetFont(.,.) function but it's not changing the font. The parent font of the dialog box is used...
Best regard from Switzerland
|
|
|
|

|
Thanks Chris and Pete for this extremely simple but useful class. "It worked straight from the box" - as most customers who buy online review their recent buys . Your CTextProgressCtrl class just adds to CProgressCtrl what I perceived to be missing, but without getting overly fancy.
I read that MFC supports the ComCtl32.dll but I wonder what type of support there is for the newer MsComCtl? I suppose you just have to add the MsComCtl.ocx to your project and drag the new slider control on your form. Any experience with these new controls?
Hidde Wallaart
software engineer
www.leo-em.co.uk
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
A smooth progress control with text
| Type | Article |
| Licence | CPOL |
| First Posted | 29 Nov 1999 |
| Views | 167,557 |
| Downloads | 5,796 |
| Bookmarked | 125 times |
|
|