Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

MPCStatusBar - An Enhanced CStatusBar

0.00/5 (No votes)
11 Jun 2003 1  
An enhanced CStatusBar to easily and dynamically add/remove controls on a status bar

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

Additionally, 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 statusbar at their right 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 you 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.

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