c++mfc

How to show a different text in MFCStatusBar Progress bar


I would like to have a progress bar in the MFC status bar, which shows the progress in the amount of elapsed counts (e.g., 15/235) instead of the progress in percentage, 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 the percentage is shown:

How do I achieve this?


Solution

  • 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:

    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.