I would like to have a progress bar in the MFC status bar which shows instead the progress in percentage the progress in the amount of elapsed counts (e.g., 15/235), while still showing a colored progress bar.
It seems however, that I can either show the amounts and not the colored progress, or vice versa.
By doing EnablePaneProgressBar(1, 150, TRUE)
, only percentage is shown:
Is there a way how to do it? Thank you.
0
Searched the MFC sources to see how this works, and found its implementation. It’s not in the CMFCStatusBar
code actually, instead it’s in file afxvisualmanager.cpp line 1897, function CMFCVisualManager::OnDrawStatusBarProgress()
. Namely, this is an MFC feature (the MFC library draws the progress-bar), and it seems there is no some Win32 Progerss Bar control there – these do not display text anyway.
Don’t know if this can be changed, but a possible implementation could be:
- Define a new
CMFCVisualManager
-derived class, overriding theOnDrawStatusBarProgress()
member – it’s virtual fortunately. - In the override change the
Format()
call, to something likestrText.Format(_T("%d/%d"), nProgressCurr, nProgressTotal);
- Finally you have to replace the
CMFCVisualManager
instance with your overridden visual manager. It’s not quite easy to do, as the visual manager is a single-instance object, created and maintained by the MFC framework, which is a bit tricky. TheCMFCVisualManager::SetDefaultManager()
method seems to do this properly though. See here and here.
A downside is that this will change the behavior of all progress-bars in your status-bar (not a problem if there is only one). It can still be changed though (ie draw each progress-bar differently, based on its pane number).
I can’t tell if this is worth the effort, depends on your project requirements, schedule, budget etc.
EDIT:
Well, it seems it is quite easier actually. There is a call of CMFCVisualManager::SetDefaultManager()
in CMainFrame::OnCreate()
. It’s in the wizard-generated code of your frame-window class (MainFrm.cpp). Change it to use your overridden visual manager class instead.