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.
For more detail see the source code located in the VC\atlmfc\src\mfc folder of your Visual Studio installation.
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.
Examples
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;
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();
}
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
Requirements
Header: afxstatusbar.h
CMFCStatusBar::CalcFixedLayout
virtual CSize CalcFixedLayout(
BOOL bStretch,
BOOL bHorz);
Parameters
[in] bStretch
[in] bHorz
Return Value
Remarks
CMFCStatusBar::CommandToIndex
int CommandToIndex(UINT nIDFind) const;
Parameters
[in] nIDFind
Return Value
Remarks
CMFCStatusBar::Create
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
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
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
bEnable
[in] 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
nIndex
[in] Specifies the index of the pane whose progress bar to enable.
nTotal
[in] Specifies the maximum value for the progress bar.
bDisplayText
[in] Specifies whether the progress bar should display the current progress value.
clrBar
[in] Specifies the background color of the progress bar.
clrBarDest
[in] Specifies the secondary color of the progress bar background. Use different value than clrBar to fill by a color blended into a gradient.
clrProgressText
[in] 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
BOOL GetDrawExtendedArea() const;
Return Value
Remarks
CMFCStatusBar::GetExtendedArea
virtual BOOL GetExtendedArea(CRect& rect) const;
Parameters
[in] rect
Return Value
Remarks
CMFCStatusBar::GetItemID
UINT GetItemID(int nIndex) const;
Parameters
[in] nIndex
Return Value
Remarks
CMFCStatusBar::GetItemRect
void GetItemRect(
int nIndex,
LPRECT lpRect) const;
Parameters
[in] nIndex
[in] lpRect
Remarks
CMFCStatusBar::GetPaneInfo
void GetPaneInfo(
int nIndex,
UINT& nID,
UINT& nStyle,
int& cxWidth) const;
Parameters
[in] nIndex
[in] nID
[in] nStyle
[in] cxWidth
Remarks
CMFCStatusBar::GetPaneProgress
long GetPaneProgress(int nIndex) const;
Parameters
[in] nIndex
Return Value
Remarks
CMFCStatusBar::GetPaneStyle
UINT GetPaneStyle(int nIndex) const;
Parameters
[in] nIndex
Return Value
Remarks
CMFCStatusBar::GetPaneText
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
nIndex
[in] 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
nIndex
[in] 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
nIndex
[in] 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
pDC
[in] A pointer to a device context for drawing.
pPane
[in] 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
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
Parameters
[in] cs
Return Value
Remarks
CMFCStatusBar::SetDrawExtendedArea
void SetDrawExtendedArea(BOOL bSet = TRUE);
Parameters
[in] bSet
Remarks
CMFCStatusBar::SetIndicators
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
nIndex
[in] Specifies the index of the pane to which you want to assign to it an animation.
hImageList
[in] Specifies a handle to the image list that holds the animation frames.
nFrameRate
[in] Specifies the frame rate, in milliseconds, for the animation.
bUpdate
[in] 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
nIndex
[in] Specifies the index of the pane for which to set a new background color.
clrBackground
[in] Specifies the new background color.
bUpdate
[in] 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
nIndex
[in] Specifies the index of the pane for which to set the image.
hIcon
[in] Specifies a handle to the icon to be set as the pane image.
bUpdate
[in] Specifies whether to update the pane content immediately.
hBmp
[in] Specifies a handle to the bitmap to be set as the pane image.
clrTransparent
[in] 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
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
nIndex
[in] Specifies the index of the pane for which to update the progress indicator.
nCurr
[in] Specifies the current value of the progress indicator.
bUpdate
[in] 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
void SetPaneStyle(
int nIndex,
UINT nStyle);
Parameters
[in] nIndex
[in] nStyle
Remarks
CMFCStatusBar::SetPaneText
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
nIndex
[in] Specifies the index of the pane to which you want to assign a new text color.
clrText
[in] Specifies the text color.
bUpdate
[in] 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
nIndex
[in] The index of the status bar pane for which to set a new width.
cx
[in] 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
nIndex
[in] The index of the pane to which you want to assign the tooltip text.
pszTipText
[in] The new tooltip text.