Click here to Skip to main content
Click here to Skip to main content

MPCStatusBar - An Enhanced CStatusBar

, 11 Jun 2003
Rate this:
Please Sign up or sign in to vote.
An enhanced CStatusBar to easily and dynamically add/remove controls on a status bar
  • Download demo project - 43 Kb
  • Download source files - 5 Kb

    Sample Image - MPCStatusBar.gif

    Overview

    The MPCStatusBar class allows you to easily add/remove standard indicators, and/or add/remove controls on the status bar. MPCStatusBarPane and MPCStatusBarPaneControlInfo classes comes with MPCStatusBar.

    Additionally, there's a "ready to use" class, the MPCLogoPane class, that you can use to add the logo of your firm, or software on the left side of the status bar. Of course, a simple MDI application comes with the source code, where you can see the MPCStatusBar class used in conjunction MPCLogoPane and a standard CEdit on the status bar.


    Sample

    Sample source code to dynamically add/remove a control:

    Declare a MPCStatusBar in replacement of CStatusBar, in your mainframe.h (or childframes):

    MPCStatusBar m_wndStatusBar;
    

    A sample function to add/remove a control:

    void Function_addcontrol( BOOL bAddalogo )
    {
        // Get the mainframe
        CMainFrame * pMainframe = (CMainFrame *) AfxGetApp()->m_pMainWnd;
    
        if ( bAddalogo )
        {
            // Add an indicator, with width, ..
            pMainframe->m_wndStatusBar.AddIndicator(0,INDICATOR_LOGO);
            // set the width and style
            int idx = pMainframe->m_wndStatusBar.CommandToIndex(INDICATOR_LOGO);
            pMainframe->m_wndStatusBar.SetPaneWidth(idx,120);
            pMainframe->m_wndStatusBar.SetPaneStyle(idx, 
                                     pMainframe->m_wndStatusBar.GetPaneStyle(idx) 
                                      | SBPS_NOBORDERS );
    
            // Create a log pane window, and append it to status bar
            MPCLogoPane * pLogo = new MPCLogoPane;
            pLogo->Create("Your App Name ",WS_CHILD|WS_VISIBLE,
                          &pMainframe->m_wndStatusBar,120);
            pLogo->SetLogoFont("Arial", 18);
            pMainframe->m_wndStatusBar.AddControl(pLogo,INDICATOR_LOGO);
        }
        else
        {
            pMainframe->m_wndStatusBar.RemovePane(INDICATOR_LOGO);
        }
    }
    
    

    Classes

    • MPCStatusBar
    • MPCStatusBarPane
    • MPCStatusBarPaneControlInfo

    Additionaly, you can use the 'ready to use' MPCLogoPane class to add a logo to your app, in the status bar.


    MPCStatusBar

    This is the class you use in replacement of CStatusBar.

    void PositionControls()
    Used to move the controls in the statusbas at their rite place (==the RECT of the indicator). Internally used.

    MPCStatusBarPaneControlInfo * GetPanControl(int nPaneID)
    Return some information about a control on an indicator, or NULL.

    BOOL AddControl(CWnd * pWnd, int nPaneID, BOOL bAutodeleteControl = TRUE )
    Insert a control (pWnd) on a pane (nPaneID). If bAutodelete is TRUE, the control's window will be closed, and the control deleted, when the pane (nPaneID) will be removed, or MPCStatusBar destructor called. Returns TRUE if control appended. Before to append a control on a pane, you need to create a pane (see AddIndicator), or use an already existing pane that is not already used for a control.

    void SetPaneWidth(int index, int cxWidth)
    Change the width of a pane (with or without a control)

    BOOL AddIndicator( int position, UINT paneID)
    Add an indicator to the statusbar.

    BOOL GetStatusPane(int nIndex, MPCStatusBarPane & xfxpane)
    xfxpane is filled with some information about the pane at nIndex.

    void RemovePane(int nPaneID)
    Remove a pane. If the pane has a control, it is deleted if the control was added with autodelete=true (see AddControl).


    MPCStatusBarPane

    This class allows you to get information about a pane in a MPCStatusBar. See MPCStatusBar.

    UINT nID;
    The ID of pane

    int cxText;
    Text size

    UINT nStyle;
    Style of indicator

    UINT nFlags;
    Internal flags used by MFC

    CString strText;
    Text of pane

    MPCStatusBarPane::MPCStatusBarPane(MPCStatusBarPane & xfxpane )
    Copy constructor.

    MPCStatusBarPane& MPCStatusBarPane::operator=(MPCStatusBarPane & xfxpane )
    Assignment operator.


    MPCStatusBarPaneControlInfo

    This class allows you to get additional information about a pane in a MPCStatusBar, having a control.

    CWnd * m_hWnd;
    The control.

    int m_nPaneID;
    The pane where this control is on

    BOOL m_bAutodelete;
    Indicator of autodeletion when the pane is removed, of when MPCStatusBar's destructor is called.


    MPCLogoPane

    BOOL MPCLogoPane::Create(CString sText, DWORD dwStyle, CWnd * pParent, UINT nID)
    sText -- text you want to display in the window
    dwStyle -- style of window (WS_CHILD | WS_VISIBLE to use in the status bar)
    nID -- ID of window

    void MPCLogoPane::SetLogoFont(CString Name, int nHeight/* = 24*/, int nWeight/* = FW_BOLD*/, BYTE bItalic/* = true*/, BYTE bUnderline/* = false*/)
    Set the font for the displaying text.

    void MPCLogoPane::SetLogoText(CString sTxt)
    Set the text to display
  • License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    About the Author

    No Biography provided

    Comments and Discussions

     
    QuestionLicense? PinmemberNathan Lewis29-Nov-07 5:48 
    GeneralClock in StatusBar PinsussAnonymous16-May-05 7:53 
    Generalhello is it possible to check the ready state of the normal window (Except internet explorer)and other applications Pinmember1lokii28-Dec-04 19:06 
    Generalhello is it possible to check the ready state of the normal window and other applications Pinmember1lokii28-Dec-04 19:03 
    GeneralNice Article,But one question though.... PinmemberKoundinya22-Apr-04 18:31 
    Questionhow can i change the backgroud clr? PinmemberPanda_w4-Nov-03 20:13 
    AnswerRe: how can i change the backgroud clr? PinsussAnonymous23-Jan-04 5:35 
    GeneralDoesn't work properly on XP with CommonCtrl Lib 6 PinmemberAndreas Gut9-Oct-02 4:41 
    GeneralRe: Doesn't work properly on XP with CommonCtrl Lib 6 PinmemberAndreas Gut9-Oct-02 4:59 
    GeneralTrying to respond to the Edit box (enter key) PinmemberAnonymous21-May-02 12:58 
    GeneralRe: Trying to respond to the Edit box (enter key) PinmemberGernot Frisch14-Jan-03 1:18 
    GeneralRe: Trying to respond to the Edit box (enter key) PinmemberDiarrhio1-Mar-03 7:52 
    GeneralTo remove all the panes (NUM etc) PinmemberAnonymous21-May-02 12:21 
    GeneralRe: To remove all the panes (NUM etc) PinsussAnonymous6-Oct-02 5:40 
    GeneralDisable "Ready" string. PinmemberEric Lee28-Apr-02 16:54 
    GeneralRe: Disable "Ready" string. PinmemberArmen Hakobyan7-May-02 4:00 
    QuestionHow could i add the tips for pane and control? PinmemberPanda_w6-Apr-02 2:21 
    AnswerRe: How could i add the tips for pane and control? PinmemberArmen Hakobyan7-May-02 4:30 
    GeneralCool Pinmembernickong1-Mar-02 3:36 
    GeneralProgress Control PinmemberGiancarlo25-Jun-01 5:54 
    GeneralRe: Progress Control Pinmemberraven_poet17-Aug-03 14:44 
    GeneralDisabled controls. PinmemberDavid Msika7-Jun-01 8:30 
    GeneralCool code. Small questions. Please help. PinsussErich J. Ruth8-Jun-00 14:04 
    GeneralThe app name PinsussPeter Hartmann17-Feb-00 19:40 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    | Advertise | Privacy | Mobile
    Web02 | 2.8.140709.1 | Last Updated 12 Jun 2003
    Article Copyright 2000 by Pierre Mellinand
    Everything else Copyright © CodeProject, 1999-2014
    Terms of Service
    Layout: fixed | fluid