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.
class CMFCStatusBar : public CPane
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. |
Name | Description |
---|---|
CMFCStatusBar::OnDrawPane | Called by the framework when it redraws the pane of the status bar. |
The following diagram shows a figure of the status bar from Status Bar Demo sample application.
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);
Header: afxstatusbar.h
virtual CSize CalcFixedLayout(
BOOL bStretch,
BOOL bHorz);
[in] bStretch
[in] bHorz
int CommandToIndex(UINT nIDFind) const;
[in] nIDFind
BOOL Create(
CWnd* pParentWnd,
DWORD dwStyle = WS_CHILD | WS_VISIBLE | CBRS_BOTTOM,
UINT nID = AFX_IDW_STATUS_BAR);
[in] pParentWnd
[in] dwStyle
[in] nID
BOOL CreateEx(
CWnd* pParentWnd,
DWORD dwCtrlStyle = 0,
DWORD dwStyle = WS_CHILD | WS_VISIBLE | CBRS_BOTTOM,
UINT nID = AFX_IDW_STATUS_BAR);
[in] pParentWnd
[in] dwCtrlStyle
[in] dwStyle
[in] nID
virtual BOOL DoesAllowDynInsertBefore() const;
Enables or disables the handling of mouse double-clicks on the status bar.
void EnablePaneDoubleClick(BOOL bEnable=TRUE);
bEnable
[in] If TRUE, enable the processing of the mouse double-click. Otherwise disable the processing of the mouse double-click.
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.
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);
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.
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.
Retrieves the number of panes in the status bar.
int GetCount() const;
The number of panes in the status bar.
BOOL GetDrawExtendedArea() const;
virtual BOOL GetExtendedArea(CRect& rect) const;
[in] rect
UINT GetItemID(int nIndex) const;
[in] nIndex
void GetItemRect(
int nIndex,
LPRECT lpRect) const;
[in] nIndex
[in] lpRect
void GetPaneInfo(
int nIndex,
UINT& nID,
UINT& nStyle,
int& cxWidth) const;
[in] nIndex
[in] nID
[in] nStyle
[in] cxWidth
long GetPaneProgress(int nIndex) const;
[in] nIndex
UINT GetPaneStyle(int nIndex) const;
[in] nIndex
void GetPaneText(
int nIndex,
CString& s) const;
CString GetPaneText(int nIndex) const;
[in] nIndex
[in] s
Retrieves the width of the pane of a status bar.
int GetPaneWidth(int nIndex) const;
nIndex
[in] Specifies the index of the status bar pane.
The width of the status bar pane that nIndex specifies; otherwise, zero if a status-bar pane does not exist.
Retrieve the tooltip text of a status bar's pane.
CString GetTipText(int nIndex) const;
nIndex
[in] Specifies the index of the pane for which to retrieve tool tip text.
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.
Invalidate the status bar pane and redraw its content.
void InvalidatePaneContent(int nIndex);
nIndex
[in] Specifies the index of the pane whose content is to be invalidated and redrawn.
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.
Redraw the pane of the status bar.
virtual void OnDrawPane(
CDC* pDC,
CMFCStatusBarPaneInfo* pPane);
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.
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.
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
[in] cs
void SetDrawExtendedArea(BOOL bSet = TRUE);
[in] bSet
BOOL SetIndicators(
const UINT* lpIDArray,
int nIDCount);
[in] lpIDArray
[in] nIDCount
Assigns an animation to the specified pane.
void SetPaneAnimation(
int nIndex,
HIMAGELIST hImageList,
UINT nFrameRate=500,
BOOL bUpdate=TRUE);
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.
If you want to disable the current animation, call SetPaneAnimation
with hImageList
set to NULL.
Sets the background color of the status bar pane.
void SetPaneBackgroundColor(
int nIndex,
COLORREF clrBackground=(COLORREF)-1,
BOOL bUpdate=TRUE);
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.
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);
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.
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.
void SetPaneInfo(
int nIndex,
UINT nID,
UINT nStyle,
int cxWidth);
[in] nIndex
[in] nID
[in] nStyle
[in] cxWidth
Set the current progress indicator of the progress bar for the specified pane.
void SetPaneProgress(
int nIndex,
long nCurr,
BOOL bUpdate=TRUE);
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.
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.
void SetPaneStyle(
int nIndex,
UINT nStyle);
[in] nIndex
[in] nStyle
virtual BOOL SetPaneText(
int nIndex,
LPCTSTR lpszNewText,
BOOL bUpdate = TRUE);
[in] nIndex
[in] lpszNewText
[in] bUpdate
Sets the text color of the specified pane.
void SetPaneTextColor(
int nIndex,
COLORREF clrText=(COLORREF)-1,
BOOL bUpdate=TRUE);
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.
Set the width of the status bar pane.
void SetPaneWidth(
int nIndex,
int cx);
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.
Set the tooltip text of a status bar pane.
void SetTipText(
int nIndex,
LPCTSTR pszTipText);
nIndex
[in] The index of the pane to which you want to assign the tooltip text.
pszTipText
[in] The new tooltip text.