title | ms.custom | ms.date | ms.reviewer | ms.suite | ms.technology | ms.tgt_pltfrm | ms.topic | f1_keywords | dev_langs | helpviewer_keywords | ms.assetid | caps.latest.revision | author | ms.author | manager | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
CProgressCtrl Class | Microsoft Docs |
11/04/2016 |
|
reference |
|
|
|
222630f4-1598-4026-8198-51649b1192ab |
25 |
mikeblome |
mblome |
ghogen |
Provides the functionality of the Windows common progress bar control.
class CProgressCtrl : public CWnd
Name | Description |
---|---|
CProgressCtrl::CProgressCtrl | Constructs a CProgressCtrl object. |
Name | Description |
---|---|
CProgressCtrl::Create | Creates a progress bar control and attaches it to a CProgressCtrl object. |
CProgressCtrl::CreateEx | Creates a progress control with the specified Windows extended styles and attaches it to a CProgressCtrl object. |
CProgressCtrl::GetBarColor | Gets the color of the progress indicator bar for the current progress bar control. |
CProgressCtrl::GetBkColor | Gets the background color of the current progress bar. |
CProgressCtrl::GetPos | Gets the current position of the progress bar. |
CProgressCtrl::GetRange | Gets the lower and upper limits of the range of the progress bar control. |
CProgressCtrl::GetState | Gets the state of the current progress bar control. |
CProgressCtrl::GetStep | Retrieves the step increment for the progress bar of the current progress bar control. |
CProgressCtrl::OffsetPos | Advances the current position of a progress bar control by a specified increment and redraws the bar to reflect the new position. |
CProgressCtrl::SetBarColor | Sets the color of the progress indicator bar in the current progress bar control. |
CProgressCtrl::SetBkColor | Sets the background color for the progress bar. |
CProgressCtrl::SetMarquee | Turns marquee mode on or off for the current progress bar control. |
CProgressCtrl::SetPos | Sets the current position for a progress bar control and redraws the bar to reflect the new position. |
CProgressCtrl::SetRange | Sets the minimum and maximum ranges for a progress bar control and redraws the bar to reflect the new ranges. |
CProgressCtrl::SetState | Sets the state of the current progress bar control. |
CProgressCtrl::SetStep | Specifies the step increment for a progress bar control. |
CProgressCtrl::StepIt | Advances the current position for a progress bar control by the step increment (see SetStep) and redraws the bar to reflect the new position. |
A progress bar control is a window that an application can use to indicate the progress of a lengthy operation. It consists of a rectangle that is gradually filled, from left to right, with the system highlight color as an operation progresses.
A progress bar control has a range and a current position. The range represents the total duration of the operation, and the current position represents the progress the application has made toward completing the operation. The window procedure uses the range and the current position to determine the percentage of the progress bar to fill with the highlight color. Because the range and current position values are expressed as signed integers, the possible range of current position values is from -2,147,483,648 to 2,147,483,647 inclusive.
For more information on using CProgressCtrl
, see Controls and Using CProgressCtrl.
CProgressCtrl
Header: afxcmn.h
Constructs a CProgressCtrl
object.
CProgressCtrl();
After constructing the CProgressCtrl
object, call CProgressCtrl::Create
to create the progress bar control.
[!code-cppNVC_MFC_CProgressCtrl#1]
Creates a progress bar control and attaches it to a CProgressCtrl
object.
virtual BOOL Create(
DWORD dwStyle,
const RECT& rect,
CWnd* pParentWnd,
UINT nID);
dwStyle
Specifies the progress bar control's style. Apply any combination of window stylesdescribed in CreateWindow in the Windows SDK, in addition to the following progress bar control styles, to the control:
-
PBS_VERTICAL
Displays progress information vertically, top to bottom. Without this flag, the progress bar control displays horizontally, left to right. -
PBS_SMOOTH
Displays gradual, smooth filling in the progress bar control. Without this flag, the control will fill with blocks.
rect
Specifies the progress bar control's size and position. It can be either a CRect object or a RECT structure. Because the control must be a child window, the specified coordinates are relative to the client area of the pParentWnd
.
pParentWnd
Specifies the progress bar control's parent window, usually a CDialog
. It must not be NULL.
nID
Specifies the progress bar control's ID.
TRUE if the CProgressCtrl
object is successfully created; otherwise FALSE.
You construct a CProgressCtrl
object in two steps. First, call the constructor, which creates the CProgressCtrl
object, and then call Create, which creates the progress bar control.
[!code-cppNVC_MFC_CProgressCtrl#2]
Creates a control (a child window) and associates it with the CProgressCtrl
object.
virtual BOOL CreateEx(
DWORD dwExStyle,
DWORD dwStyle,
const RECT& rect,
CWnd* pParentWnd,
UINT nID);
dwExStyle
Specifies the extended style of the control being created. For a list of extended Windows styles, see the dwExStyle
parameter for CreateWindowEx in the Windows SDK.
dwStyle
Specifies the progress bar control's style. Apply any combination of window styles described in CreateWindow in the Windows SDK.
rect
A reference to a RECT structure describing the size and position of the window to be created, in client coordinates of pParentWnd
.
pParentWnd
A pointer to the window that is the control's parent.
nID
The control's child-window ID.
Nonzero if successful; otherwise 0.
Use CreateEx
instead of Create to apply extended Windows styles, specified by the Windows extended style preface WS_EX_.
Gets the color of the progress indicator bar for the current progress bar control.
COLORREF GetBarColor() const;
The color of the current progress bar, represented as a COLORREF value, or CLR_DEFAULT
if the progress indicator bar color is the default color.
This method sends the PBM_GETBARCOLOR message, which is described in the Windows SDK.
Gets the background color of the current progress bar.
COLORREF GetBkColor() const;
The background color of the current progress bar, represented as a COLORREF value.
This method sends the PBM_GETBKCOLOR message, which is described in the Windows SDK.
Retrieves the current position of the progress bar.
int GetPos();
The position of the progress bar control.
The position of the progress bar control is not the physical location on the screen, but rather is between the upper and lower range indicated in SetRange.
[!code-cppNVC_MFC_CProgressCtrl#3]
Gets the current lower and upper limits, or range, of the progress bar control.
void GetRange(
int& nLower,
int& nUpper);
nLower
A reference to an integer receiving the lower limit of the progress bar control.
nUpper
A reference to an integer receiving the upper limit of the progress bar control.
This function copies the values of the lower and upper limits to the integers referenced by nLower
and nUpper
, respectively.
[!code-cppNVC_MFC_CProgressCtrl#4]
Gets the state of the current progress bar control.
int GetState() const;
The state of the current progress bar control, which is one of the following values:
Value | State |
---|---|
PBST_NORMAL |
In progress |
PBST_ERROR |
Error |
PBST_PAUSED |
Paused |
This method sends the PBM_GETSTATE message, which is described in the Windows SDK.
The following code example defines the variable, m_progressCtrl
, that is used to programmatically access the progress bar control. This variable is used in the next example.
[!code-cppNVC_MFC_CProgressCtrl_s1#9]
The following code example retrieves the state of the current progress bar control.
[!code-cppNVC_MFC_CProgressCtrl_s1#5]
Retrieves the step increment for the progress bar of the current progress bar control.
int GetStep() const;
The step increment of the progress bar.
The step increment is the amount by which a call to CProgressCtrl::StepIt increases the current position of the progress bar.
This method sends the PBM_GETSTEP message, which is described in the Windows SDK.
The following code example defines the variable, m_progressCtrl
, that is used to programmatically access the progress bar control. This variable is used in the next example.
[!code-cppNVC_MFC_CProgressCtrl_s1#9]
The following code example retrieves the step increment of the current progress bar control.
[!code-cppNVC_MFC_CProgressCtrl_s1#3]
Advances the progress bar control's current position by the increment specified by nPos
and redraws the bar to reflect the new position.
int OffsetPos(int nPos);
nPos
Amount to advance the position.
The previous position of the progress bar control.
[!code-cppNVC_MFC_CProgressCtrl#5]
Sets the color of the progress indicator bar in the current progress bar control.
COLORREF SetBarColor(COLORREF clrBar);
Parameter | Description |
---|---|
[in] clrBar |
A COLORREF value that specifies the new color of the progress indicator bar. Specify CLR_DEFAULT to cause the progress bar to use its default color. |
The previous color of the progress indicator bar, represented as a COLORREF value, or CLR_DEFAULT
if the color of the progress indicator bar is the default color.
The SetBarColor
method sets the progress bar color only if a [!INCLUDEwindowsver]theme is not in effect.
This method sends the PBM_SETBARCOLOR message, which is described in the Windows SDK.
The following code example defines the variable, m_progressCtrl
, that is used to programmatically access the progress bar control. This variable is used in the next example.
[!code-cppNVC_MFC_CProgressCtrl_s1#9]
The following code example changes the color of the progress bar to red, green, blue, or the default.
[!code-cppNVC_MFC_CProgressCtrl_s1#1]
Sets the background color for the progress bar.
COLORREF SetBkColor(COLORREF clrNew);
clrNew
A COLORREF value that specifies the new background color. Specify the CLR_DEFAULT
value to use the default background color for the progress bar.
The COLORREF value indicating the previous background color, or CLR_DEFAULT if the background color is the default color.
[!code-cppNVC_MFC_CProgressCtrl#6]
Turns marquee mode on or off for the current progress bar control.
BOOL SetMarquee(
BOOL fMarqueeMode,
int nInterval);
Parameter | Description |
---|---|
[in] fMarqueeMode |
true to turn marquee mode on, or false to turn marquee mode off. |
[in] nInterval |
Time in milliseconds between updates of the marquee animation. |
This method always returns true
.
When marquee mode is turned on, the progress bar is animated and scrolls like a sign on a theater marquee.
This method sends the PBM_SETMARQUEE message, which is described in the Windows SDK.
The following code example defines the variable, m_progressCtrl
, that is used to programmatically access the progress bar control. This variable is used in the next example.
[!code-cppNVC_MFC_CProgressCtrl_s1#9]
The following code example starts and stops the marquee scrolling animation.
[!code-cppNVC_MFC_CProgressCtrl_s1#2]
Sets the progress bar control's current position as specified by nPos
and redraws the bar to reflect the new position.
int SetPos(int nPos);
nPos
New position of the progress bar control.
The previous position of the progress bar control.
The position of the progress bar control is not the physical location on the screen, but rather is between the upper and lower range indicated in SetRange.
[!code-cppNVC_MFC_CProgressCtrl#7]
Sets the upper and lower limits of the progress bar control's range and redraws the bar to reflect the new ranges.
void SetRange(
short nLower,
short nUpper);
void SetRange32(
int nLower,
int nUpper);
nLower
Specifies the lower limit of the range (default is zero).
nUpper
Specifies the upper limit of the range (default is 100).
The member function SetRange32
sets the 32-bit range for the progress control.
[!code-cppNVC_MFC_CProgressCtrl#8]
Sets the state of the current progress bar control.
int SetState(int iState);
Parameter | Description |
---|---|
[in] iState |
The state to set the progress bar. Use one of the following values: - PBST_NORMAL - In progress- PBST_ERROR - Error- PBST_PAUSED - Paused |
The previous state of the current progress bar control.
This method sends the PBM_SETSTATE message, which is described in the Windows SDK.
The following code example defines the variable, m_progressCtrl
, that is used to programmatically access the progress bar control. This variable is used in the next example.
[!code-cppNVC_MFC_CProgressCtrl_s1#9]
The following code example sets the state of the current progress bar control to Paused or In Progress.
[!code-cppNVC_MFC_CProgressCtrl_s1#4]
Specifies the step increment for a progress bar control.
int SetStep(int nStep);
nStep
New step increment.
The previous step increment.
The step increment is the amount by which a call to CProgressCtrl::StepIt
increases the progress bar's current position.
The default step increment is 10.
[!code-cppNVC_MFC_CProgressCtrl#9]
Advances the current position for a progress bar control by the step increment and redraws the bar to reflect the new position.
int StepIt();
The previous position of the progress bar control.
The step increment is set by the CProgressCtrl::SetStep
member function.
[!code-cppNVC_MFC_CProgressCtrl#10]