Compartir a través de


CMFCStatusBar Class

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at CMFCStatusBar Class.

The CMFCStatusBar class implements a status bar similar to the CStatusBar class. However, the CMFCStatusBar class has features not offered by the CStatusBar class, such as the ability to display images, animations, and progress bars; and the ability to respond to mouse double-clicks.

Syntax

class CMFCStatusBar : public CPane  

Members

Public Methods

Name Description
CMFCStatusBar::CalcFixedLayout (Overrides CBasePane::CalcFixedLayout.)
CMFCStatusBar::CommandToIndex
CMFCStatusBar::Create Creates a control bar and attaches it to the CPane object. (Overrides CPane::Create.)
CMFCStatusBar::CreateEx Creates a control bar and attaches it to the CPane object. (Overrides CPane::CreateEx.)
CMFCStatusBar::DoesAllowDynInsertBefore Determines whether another pane can be dynamically inserted between this pane and the parent frame. (Overrides CBasePane::DoesAllowDynInsertBefore.)
CMFCStatusBar::EnablePaneDoubleClick Enables or disables the handling of mouse double-clicks on the status bar.
CMFCStatusBar::EnablePaneProgressBar Displays a progress bar on the specified pane.
CMFCStatusBar::GetCount Returns the number of panes on the status bar.
CMFCStatusBar::GetDrawExtendedArea
CMFCStatusBar::GetExtendedArea
CMFCStatusBar::GetItemID
CMFCStatusBar::GetItemRect
CMFCStatusBar::GetPaneInfo
CMFCStatusBar::GetPaneProgress
CMFCStatusBar::GetPaneStyle Returns the pane style. (Overrides CBasePane::GetPaneStyle.)
CMFCStatusBar::GetPaneText
CMFCStatusBar::GetPaneWidth Returns the width, in pixels, of the specified pane of the status bar.
CMFCStatusBar::GetTipText Returns the tool tip text for the specified pane of the status bar.
CMFCStatusBar::InvalidatePaneContent Invalidates the specified pane and redraws its content.
CMFCStatusBar::PreCreateWindow Called by the framework before the creation of the Windows window attached to this CWnd object. (Overrides CWnd::PreCreateWindow.)
CMFCStatusBar::SetDrawExtendedArea
CMFCStatusBar::SetIndicators
CMFCStatusBar::SetPaneAnimation Assigns an animation to the specified pane.
CMFCStatusBar::SetPaneBackgroundColor Sets the background color for the specified pane of the status bar.
CMFCStatusBar::SetPaneIcon Sets the indicator icon for the specified pane of the status bar.
CMFCStatusBar::SetPaneInfo
CMFCStatusBar::SetPaneProgress Sets the current progress of the progress bar for the specified pane of the status bar.
CMFCStatusBar::SetPaneStyle Sets the style of the pane. (Overrides CBasePane::SetPaneStyle.)
CMFCStatusBar::SetPaneText
CMFCStatusBar::SetPaneTextColor Sets the text color for the specified pane of the status bar.
CMFCStatusBar::SetPaneWidth Sets the width in pixels of the specified pane of the status bar.
CMFCStatusBar::SetTipText Sets the tool tip text for the specified pane of the status bar.

Protected Methods

Name Description
CMFCStatusBar::OnDrawPane Called by the framework when it redraws the pane of the status bar.

Remarks

The following diagram shows a figure of the status bar from Status Bar Demo sample application.

Example of CMFCStatusBar

Example

The following example demonstrates the local variables that the application uses to call various methods in the CMFCStatusBar class. These variables are declared in StatusBarDemoView.h. The main frame is declared in MainFrm.h, the document is declared in StatusBarDemoDoc.h, and the view is declared in StatusBarDemoView.h. This code snippet is part of the Status Bar Demo sample.

   int         m_nProgressCurr;
    BOOL        m_bInProgress;

    CImageList  m_imlStatusAnimation;
    BOOL        m_bInAnimation;

    CBitmap     m_bmpIcon1;
    CBitmap     m_bmpIcon2;

Example

The following example demonstrates how to get a reference to CMFCStatusBar object by introducing the GetStatusBar method in MainFrm.h and then calling this method from the GetStatusBar method in StatusBarDemoView.h. This code snippet is part of the Status Bar Demo sample.

// in MainFrm.h
public:
    CMFCStatusBar& GetStatusBar ()
    {
        return m_wndStatusBar;
    }
 // in StatusBarDemoView.h
    CMFCStatusBar& GetStatusBar () const
    {
        return ((CMainFrame*) AfxGetMainWnd ())->GetStatusBar ();
    }

Example

The following example demonstrates how to call various methods in the CMFCStatusBar class in StatusBarDemoView.cpp. The constants are declared in MainFrm.h. The example shows how to set the icon, set the tooltip text of the status bar pane, display a progress bar on the specified pane, assign an animation to the specified pane, set the text and the width of the status bar pane, and set the current progress indicator of the progress bar for the status bar pane. This code snippet is part of the Status Bar Demo sample.

// in MainFrm.h
const int nStatusIcon = 0;
const int nStatusInfo = 1;
const int nStatusProgress = 2;
const int nStatusLabel = 3;
const int nStatusAnimation = 4;
   // in StatusBarDemoView.cpp
    GetStatusBar ().SetPaneIcon (nStatusIcon, m_bmpIcon1);
    GetStatusBar ().SetTipText (nStatusIcon, _T("This is a tooltip"));
    GetStatusBar ().EnablePaneProgressBar (nStatusProgress, PROGRESS_MAX);
        GetStatusBar ().SetPaneAnimation (nStatusAnimation, NULL);
    GetStatusBar ().SetPaneAnimation (nStatusAnimation, m_imlStatusAnimation);
    GetStatusBar ().SetPaneText (nStatusAnimation, _T(""));
    GetStatusBar ().SetPaneWidth (nStatusAnimation, 16);
      GetStatusBar ().SetPaneProgress (nStatusProgress, m_nProgressCurr);

Inheritance Hierarchy

CObject

CCmdTarget

CWnd

CBasePane

CPane

CMFCStatusBar

Requirements

Header: afxstatusbar.h

CMFCStatusBar::CalcFixedLayout

This topic is included for completeness. For more detail see the source code located in the VC\atlmfc\src\mfc folder of your Visual Studio installation.

virtual CSize CalcFixedLayout(
    BOOL bStretch,  
    BOOL bHorz);

Parameters

[in] bStretch
[in] bHorz

Return Value

Remarks

CMFCStatusBar::CommandToIndex

This topic is included for completeness. For more detail see the source code located in the VC\atlmfc\src\mfc folder of your Visual Studio installation.

int CommandToIndex(UINT nIDFind) const;  

Parameters

[in] nIDFind

Return Value

Remarks

CMFCStatusBar::Create

This topic is included for completeness. For more detail see the source code located in the VC\atlmfc\src\mfc folder of your Visual Studio installation.

BOOL Create(
    CWnd* pParentWnd,  
    DWORD dwStyle=WS_CHILD|WS_VISIBLE|CBRS_BOTTOM,  
    UINT nID=AFX_IDW_STATUS_BAR);

Parameters

[in] pParentWnd
[in] dwStyle
[in] nID

Return Value

Remarks

CMFCStatusBar::CreateEx

This topic is included for completeness. For more detail see the source code located in the VC\atlmfc\src\mfc folder of your Visual Studio installation.

BOOL CreateEx(
    CWnd* pParentWnd,  
    DWORD dwCtrlStyle=0,  
    DWORD dwStyle=WS_CHILD|WS_VISIBLE|CBRS_BOTTOM,  
    UINT nID=AFX_IDW_STATUS_BAR);

Parameters

[in] pParentWnd
[in] dwCtrlStyle
[in] dwStyle
[in] nID

Return Value

Remarks

CMFCStatusBar::DoesAllowDynInsertBefore

This topic is included for completeness. For more detail see the source code located in the VC\atlmfc\src\mfc folder of your Visual Studio installation.

virtual BOOL DoesAllowDynInsertBefore() const;  

Return Value

Remarks

CMFCStatusBar::EnablePaneDoubleClick

Enables or disables the handling of mouse double-clicks on the status bar.

void EnablePaneDoubleClick(BOOL bEnable=TRUE);

Parameters

[in] bEnable
If TRUE, enable the processing of the mouse double-click. Otherwise disable the processing of the mouse double-click.

Remarks

If the status bar is enabled to process double clicks, Windows sends the WM_COMMAND notification together with a resource ID to the owner of the status bar every time that the user double clicks on the status bar pane.

CMFCStatusBar::EnablePaneProgressBar

Display a progress bar on the specified pane.

void EnablePaneProgressBar(
    int nIndex,  
    long nTotal=100,  
    BOOL bDisplayText=FALSE,  
    COLORREF clrBar=-1,  
    COLORREF clrBarDest=-1,  
    COLORREF clrProgressText=-1);

Parameters

[in] nIndex
Specifies the index of the pane whose progress bar to enable.

[in] nTotal
Specifies the maximum value for the progress bar.

[in] bDisplayText
Specifies whether the progress bar should display the current progress value.

[in] clrBar
Specifies the background color of the progress bar.

[in] clrBarDest
Specifies the secondary color of the progress bar background. Use different value than clrBar to fill by a color blended into a gradient.

[in] clrProgressText
Specifies the color of the text of the progress bar.

Remarks

If you want to disable the progress bar call EnablePaneProgressBar with nTotal set to -1. By default nTotal is set to 100. Therefore, you do not need any additional calculations to display progress as percentage.

You should pass different values for clrBar and clrBarDest so that the background color of the progress bar displays a color blended into a gradient. .

To set the current progress, call the CMFCStatusBar::SetPaneProgress method.

CMFCStatusBar::GetCount

Retrieves the number of panes in the status bar.

int GetCount() const;  

Return Value

The number of panes in the status bar.

CMFCStatusBar::GetDrawExtendedArea

This topic is included for completeness. For more detail see the source code located in the VC\atlmfc\src\mfc folder of your Visual Studio installation.

BOOL GetDrawExtendedArea() const;  

Return Value

Remarks

CMFCStatusBar::GetExtendedArea

This topic is included for completeness. For more detail see the source code located in the VC\atlmfc\src\mfc folder of your Visual Studio installation.

virtual BOOL GetExtendedArea(CRect& rect) const;  

Parameters

[in] rect

Return Value

Remarks

CMFCStatusBar::GetItemID

This topic is included for completeness. For more detail see the source code located in the VC\atlmfc\src\mfc folder of your Visual Studio installation.

UINT GetItemID(int nIndex) const;  

Parameters

[in] nIndex

Return Value

Remarks

CMFCStatusBar::GetItemRect

This topic is included for completeness. For more detail see the source code located in the VC\atlmfc\src\mfc folder of your Visual Studio installation.

void GetItemRect(
    int nIndex,  
    LPRECT lpRect) const;  

Parameters

[in] nIndex
[in] lpRect

Remarks

CMFCStatusBar::GetPaneInfo

This topic is included for completeness. For more detail see the source code located in the VC\atlmfc\src\mfc folder of your Visual Studio installation.

void GetPaneInfo(
    int nIndex,  
    UINT& nID,  
    UINT& nStyle,  
    int& cxWidth) const;  

Parameters

[in] nIndex
[in] nID
[in] nStyle
[in] cxWidth

Remarks

CMFCStatusBar::GetPaneProgress

This topic is included for completeness. For more detail see the source code located in the VC\atlmfc\src\mfc folder of your Visual Studio installation.

long GetPaneProgress(int nIndex) const;  

Parameters

[in] nIndex

Return Value

Remarks

CMFCStatusBar::GetPaneStyle

This topic is included for completeness. For more detail see the source code located in the VC\atlmfc\src\mfc folder of your Visual Studio installation.

UINT GetPaneStyle(int nIndex) const;  

Parameters

[in] nIndex

Return Value

Remarks

CMFCStatusBar::GetPaneText

This topic is included for completeness. For more detail see the source code located in the VC\atlmfc\src\mfc folder of your Visual Studio installation.

void GetPaneText(
    int nIndex,  
    CString& s) const;  
  
CString GetPaneText(int nIndex) const;  

Parameters

[in] nIndex
[in] s

Return Value

Remarks

CMFCStatusBar::GetPaneWidth

Retrieves the width of the pane of a status bar.

int GetPaneWidth(int nIndex) const;  

Parameters

[in] nIndex
Specifies the index of the status bar pane.

Return Value

The width of the status bar pane that nIndex specifies; otherwise, zero if a status-bar pane does not exist.

CMFCStatusBar::GetTipText

Retrieve the tooltip text of a status bar's pane.

CString GetTipText(int nIndex) const;  

Parameters

[in] nIndex
Specifies the index of the pane for which to retrieve tool tip text.

Return Value

The tooltip text of the status-bar pane that nIndex specifies. Otherwise, the empty string if a status bar pane does not exist for the specified nIndex or if its tooltip text is empty.

CMFCStatusBar::InvalidatePaneContent

Invalidate the status bar pane and redraw its content.

void InvalidatePaneContent(int nIndex);

Parameters

[in] nIndex
Specifies the index of the pane whose content is to be invalidated and redrawn.

Remarks

When the status bar is invalidated, it is marked for redrawing. Windows redraws it when the UpdateWindow method sends a WM_PAINT message to the OnPaint method.

CMFCStatusBar::OnDrawPane

Redraw the pane of the status bar.

virtual void OnDrawPane(
    CDC* pDC,  
    CMFCStatusBarPaneInfo* pPane);

Parameters

[in] pDC
A pointer to a device context for drawing.

[in] pPane
A pointer to a CMFCStatusBarPaneInfo structure that contains the information about the pane to be redrawn.

Remarks

By default, OnDrawPane redraws the pane by using the device context pDC according to the pane's style and content.

Override this method in a CMFCStatusBar-derived class to customize the appearance of a pane.

CMFCStatusBar::PreCreateWindow

This topic is included for completeness. For more detail see the source code located in the VC\atlmfc\src\mfc folder of your Visual Studio installation.

virtual BOOL PreCreateWindow(CREATESTRUCT& cs);

Parameters

[in] cs

Return Value

Remarks

CMFCStatusBar::SetDrawExtendedArea

This topic is included for completeness. For more detail see the source code located in the VC\atlmfc\src\mfc folder of your Visual Studio installation.

void SetDrawExtendedArea(BOOL bSet = TRUE);

Parameters

[in] bSet

Remarks

CMFCStatusBar::SetIndicators

This topic is included for completeness. For more detail see the source code located in the VC\atlmfc\src\mfc folder of your Visual Studio installation.

BOOL SetIndicators(
    const UINT* lpIDArray,  
    int nIDCount);

Parameters

[in] lpIDArray
[in] nIDCount

Return Value

Remarks

CMFCStatusBar::SetPaneAnimation

Assigns an animation to the specified pane.

void SetPaneAnimation(
    int nIndex,  
    HIMAGELIST hImageList,  
    UINT nFrameRate=500,  
    BOOL bUpdate=TRUE);

Parameters

[in] nIndex
Specifies the index of the pane to which you want to assign to it an animation.

[in] hImageList
Specifies a handle to the image list that holds the animation frames.

[in] nFrameRate
Specifies the frame rate, in milliseconds, for the animation.

[in] bUpdate
If TRUE, update the pane content immediately. Otherwise, the pane content is updated when it is invalidated.

Remarks

If you want to disable the current animation, call SetPaneAnimation with hImageList set to NULL.

CMFCStatusBar::SetPaneBackgroundColor

Sets the background color of the status bar pane.

void SetPaneBackgroundColor(
    int nIndex,  
    COLORREF clrBackground=(COLORREF)-1,  
    BOOL bUpdate=TRUE);

Parameters

[in] nIndex
Specifies the index of the pane for which to set a new background color.

[in] clrBackground
Specifies the new background color.

[in] bUpdate
If TRUE, update the pane content immediately. Otherwise, do not update the pane content until the pane is invalidated by another method.

CMFCStatusBar::SetPaneIcon

Set the icon of the status bar pane.

void SetPaneIcon(
    int nIndex,  
    HICON hIcon,  
    BOOL bUpdate=TRUE);

 
void SetPaneIcon(
    int nIndex,  
    HBITMAP hBmp,  
    COLORREF clrTransparent=RGB(255, 0, 255),  
    BOOL bUpdate=TRUE);

Parameters

[in] nIndex
Specifies the index of the pane for which to set the image.

[in] hIcon
Specifies a handle to the icon to be set as the pane image.

[in] bUpdate
Specifies whether to update the pane content immediately.

[in] hBmp
Specifies a handle to the bitmap to be set as the pane image.

[in] clrTransparent
Specifies the transparent color of the bitmap that the hBmp indicates.

Remarks

You can pass either HICON or HBITMAP together with the transparent color to set the pane's image. If you do not want to display the image any longer, pass the NULL value as the image handle.

If there is any running animation that CMFCStatusBar::SetPaneAnimation has set, the animation will be stopped.

CMFCStatusBar::SetPaneInfo

This topic is included for completeness. For more detail see the source code located in the VC\atlmfc\src\mfc folder of your Visual Studio installation.

void SetPaneInfo(
    int nIndex,  
    UINT nID,  
    UINT nStyle,  
    int cxWidth);

Parameters

[in] nIndex
[in] nID
[in] nStyle
[in] cxWidth

Remarks

CMFCStatusBar::SetPaneProgress

Set the current progress indicator of the progress bar for the specified pane.

void SetPaneProgress(
    int nIndex,  
    long nCurr,  
    BOOL bUpdate=TRUE);

Parameters

[in] nIndex
Specifies the index of the pane for which to update the progress indicator.

[in] nCurr
Specifies the current value of the progress indicator.

[in] bUpdate
Specifies whether the pane should be updated immediately.

Remarks

Call this method when you want to update the progress indicator for the progress bar in the specified pane.

To use this function for the given pane, you must call CMFCStatusBar::EnablePaneProgressBar first.

CMFCStatusBar::SetPaneStyle

This topic is included for completeness. For more detail see the source code located in the VC\atlmfc\src\mfc folder of your Visual Studio installation.

void SetPaneStyle(
    int nIndex,  
    UINT nStyle);

Parameters

[in] nIndex
[in] nStyle

Remarks

CMFCStatusBar::SetPaneText

This topic is included for completeness. For more detail see the source code located in the VC\atlmfc\src\mfc folder of your Visual Studio installation.

virtual BOOL SetPaneText(
    int nIndex,  
    LPCTSTR lpszNewText,  
    BOOL bUpdate = TRUE);

Parameters

[in] nIndex
[in] lpszNewText
[in] bUpdate

Return Value

Remarks

CMFCStatusBar::SetPaneTextColor

Sets the text color of the specified pane.

void SetPaneTextColor(
    int nIndex,  
    COLORREF clrText=(COLORREF)-1,  
    BOOL bUpdate=TRUE);

Parameters

[in] nIndex
Specifies the index of the pane to which you want to assign a new text color.

[in] clrText
Specifies the text color.

[in] bUpdate
If TRUE, update the pane content immediately. Otherwise, do not update the pane content until the pane is invalidated by another method.

CMFCStatusBar::SetPaneWidth

Set the width of the status bar pane.

void SetPaneWidth(
    int nIndex,  
    int cx);

Parameters

[in] nIndex
The index of the status bar pane for which to set a new width.

[in] cx
The new width of the status bar pane, in pixels.

CMFCStatusBar::SetTipText

Set the tooltip text of a status bar pane.

void SetTipText(
    int nIndex,  
    LPCTSTR pszTipText);

Parameters

[in] nIndex
The index of the pane to which you want to assign the tooltip text.

[in] pszTipText
The new tooltip text.

See Also

Hierarchy Chart
Classes
CPane Class
CStatusBar Class