description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: CMFCColorBar Class |
CMFCColorBar Class |
11/04/2016 |
|
|
4756ee40-25a5-4cee-af7f-acab7993d1c7 |
The CMFCColorBar
class represents a docking control bar that can select colors in a document or application.
class CMFCColorBar : public CMFCPopupMenuBar
Name | Description |
---|---|
CMFCColorBar::CMFCColorBar | Constructs a CMFCColorBar object. |
Name | Description |
---|---|
CMFCColorBar::ContextToSize | Calculates the vertical and horizontal margins that are required to contain the buttons on the color bar control and then adjusts the location of those buttons. |
CMFCColorBar::CreateControl | Creates a color bar control window, attaches it to the CMFCColorBar object, and resizes the control to contain the specified palette of colors. |
CMFCColorBar::Create | Creates a color bar control window and attaches it to the CMFCColorBar object. |
CMFCColorBar::EnableAutomaticButton | Shows or hides the automatic button. |
CMFCColorBar::EnableOtherButton | Enables or disables the display of a dialog box that lets the user select more colors. |
CMFCColorBar::GetColor | Retrieves the currently selected color. |
CMFCColorBar::GetCommandID | Retrieves the command ID of the current color bar control. |
CMFCColorBar::GetHighlightedColor | Retrieves the color that signifies that a color button has the focus; that is, the button is hot. |
CMFCColorBar::GetHorzMargin | Retrieves the horizontal margin, which is the space between the left or right color cell and the client area boundary. |
CMFCColorBar::GetVertMargin | Retrieves the vertical margin, which is the space between the top or bottom color cell and the client area boundary. |
CMFCColorBar::IsTearOff | Indicates whether the current color bar is dockable. |
CMFCColorBar::SetColor | Sets the color that is currently selected. |
CMFCColorBar::SetColorName | Sets a new name for a specified color. |
CMFCColorBar::SetCommandID | Sets a new command ID for a color bar control. |
CMFCColorBar::SetDocumentColors | Sets the list of colors that are used in the current document. |
CMFCColorBar::SetHorzMargin | Sets the horizontal margin, which is the space between the left or right color cell and the client area boundary. |
CMFCColorBar::SetVertMargin | Sets the vertical margin, which is the space between the top or bottom color cell and the client area boundary. |
Name | Description |
---|---|
CMFCColorBar::AdjustLocations | Adjusts the positions of the color buttons on the color bar control. |
CMFCColorBar::AllowChangeTextLabels | Indicates whether the text label of color buttons can change. |
CMFCColorBar::AllowShowOnList | Indicates whether the color bar control object can appear in a toolbar list during the customization process. |
CMFCColorBar::CalcSize | Called by the framework as part of the layout calculation process. |
CMFCColorBar::CreatePalette | Initializes a palette with the colors in a specified array of colors. |
CMFCColorBar::GetColorGridSize | Calculates the number of rows and columns in the grid of a color bar control. |
CMFCColorBar::GetExtraHeight | Calculates the additional height that the current color bar requires to display miscellaneous user interface elements such as the Other button, document colors, and so on. |
CMFCColorBar::InitColors | Initializes an array of colors with the colors in a specified palette or the system default palette. |
CMFCColorBar::OnKey | Called by the framework when a user presses a keyboard button. |
CMFCColorBar::OnSendCommand | Called by the framework to close a hierarchy of popup controls. |
CMFCColorBar::OnUpdateCmdUI | Called by the framework to enable or disable a user-interface item of a color bar control before the item is displayed. |
CMFCColorBar::OpenColorDialog | Opens a color dialog box. |
CMFCColorBar::Rebuild | Completely redraws the color bar control. |
CMFCColorBar::SelectPalette | Sets the logical palette of the specified device context to the palette of the parent button of the current color bar control. |
CMFCColorBar::SetPropList | Sets the m_pWndPropList protected data member to the specified pointer to a property grid control. |
CMFCColorBar::ShowCommandMessageString | Requests the frame window that owns the color bar control to update the message line in the status bar. |
Name | Description |
---|---|
m_bInternal |
A Boolean field that determines whether mouse events are processed. Typically, mouse events are processed when this field is TRUE and customization mode is FALSE. |
m_bIsEnabled |
A Boolean that indicates whether a control is enabled. |
m_bIsTearOff |
A Boolean that indicates whether the color bar control supports docking. |
m_BoxSize |
A CSize object that specifies the size of a cell in a color bar grid. |
m_bShowDocColorsWhenDocked |
A Boolean that indicates whether to show document colors when the color bar is docked. For more information, see CMFCColorBar::SetDocumentColors. |
m_bStdColorDlg |
A Boolean that indicates whether to show the standard system color dialog box or the CMFCColorDialog dialog box. For more information, see CMFCColorBar::EnableOtherButton. |
m_ColorAutomatic |
A COLORREF that stores the current automatic color. For more information, see CMFCColorBar::EnableOtherButton. |
m_ColorNames |
An CMap object that associates a set of RGB colors with their names. |
m_colors |
A CArray of COLORREF values that contains the colors that are displayed in the color bar control. |
m_ColorSelected |
A COLORREF value that is the color that the user has currently selected from the color bar control. |
m_lstDocColors |
A CList of COLORREF values that contains the colors that are currently used in a document. |
m_nCommandID |
An unsigned integer that is the command ID of a color button. |
m_nHorzMargin |
An integer that is the horizontal margin between the color buttons in a grid of colors. |
m_nHorzOffset |
An integer that is the horizontal offset to the center of the color button. This value is significant if the button displays text or an image in addition to a color. |
m_nNumColumns |
An integer that is the number of columns in a color bar control grid of colors. |
m_nNumColumnsVert |
An integer that is the number of columns in a vertically oriented grid of colors. |
m_nNumRowsHorz |
An integer that is the number of columns in a horizontally oriented grid of colors. |
m_nRowHeight |
An integer that is the height of a row of color buttons in a grid of colors. |
m_nVertMargin |
An integer that is the vertical margin between the color buttons in a grid of colors. |
m_nVertOffset |
An integer that is the vertical offset to the center of the color button. This value is significant if the button displays text or an image in addition to a color. |
m_Palette |
A CPalette of the colors that are used in the color bar control. |
m_pParentBtn |
A pointer to a CMFCColorButton object that is the parent of the current button. This value is significant if the color button is in a hierarchy of toolbar controls or is in a color property grid control. |
m_pParentRibbonBtn |
A pointer to a CMFCRibbonColorButton object that is on the ribbon and is the parent button of the current button. This value is significant if the color button is in a hierarchy of toolbar controls or is in a color property grid control. |
m_pWndPropList |
A pointer to a CMFCPropertyGridCtrl object. |
m_strAutoColor |
A CString that is the text that is displayed on the Automatic button. For more information, see CMFCColorBar::EnableAutomaticButton. |
m_strDocColors |
A CString that is the text that is displayed on the document colors button. For more information, see CMFCColorBar::SetDocumentColors. |
m_strOtherColor |
A CString that is the text that is displayed on the other button. For more information, see CMFCColorBar::EnableOtherButton. |
Usually, you do not create a CMFCColorBar
object directly. Instead, the CMFCColorMenuButton Class (used in menus and toolbars) or the CMFCColorButton Class creates the CMFCColorBar
object.
The CMFCColorBar
class provides the following functionality:
-
Automatically adjusts the list of document colors.
-
Saves and restores its state, together with the document state.
-
Manages the "automatic" button.
-
Uses the CMFCColorPickerCtrl Class control to select a custom color.
-
Supports a "tear-off" state (if it is created by using the CMFCColorMenuButton Class).
To incorporate the CMFCColorBar
functionality into your application:
-
Create a regular menu button and assign it an ID, for example ID_CHAR_COLOR.
-
In your frame window class, override the CFrameWndEx::OnShowPopupMenu method and replace the regular menu button with a CMFCColorMenuButton Class object (by calling CMFCToolBar::ReplaceButton).
-
Set all the styles and enable or disable the features of the
CMFCColorBar
object during CMFCColorMenuButton Class creation. TheCMFCColorMenuButton
object dynamically creates theCMFCColorBar
object after the framework calls theCreatePopupMenu
method.
When the user clicks a color bar control button, the framework uses the ON_COMMAND
macro to notify the parent of the color bar control. In the macro, the command ID parameter is the value that you assigned to the color bar control button in step 1 (ID_CHAR_COLOR in this example). For more information, see the CMFCColorMenuButton Class, CMFCColorButton Class, CMFCColorPickerCtrl Class, CFrameWndEx Class, and CMFCToolBar Class classes.
The following example demonstrates how to configure a color bar by using various methods in the CMFCColorBar
class. The methods set the horizontal and vertical margins, enable the other button, create a color bar control window, and sets the currently selected color. This example is part of the New Controls sample.
[!code-cppNVC_MFC_NewControls#1] [!code-cppNVC_MFC_NewControls#2]
Header: afxcolorbar.h
Adjusts the positions of the color buttons on the color bar control.
virtual void AdjustLocations();
This method is called by the framework during WM_SIZE message processing.
Indicates whether the text label of color buttons can change.
virtual BOOL AllowChangeTextLabels() const;
Always FALSE.
By default, this method always returns FALSE, which means text labels cannot be modified. Override this method to enable modifying text labels.
Indicates whether the color bar control object can appear in a toolbar list during the customization process.
virtual BOOL AllowShowOnList() const;
Always TRUE.
By default, this method always returns TRUE, which means the framework can display the color bar control during the customization process. Override this method to implement a different behavior.
Called by the framework as part of the layout calculation process.
virtual CSize CalcSize(BOOL bVertDock);
bVertDock
[in] TRUE to specify that the color bar control is docked vertically; FALSE to specify that the color bar control is docked horizontally.
The size of the array of color buttons in a color bar control.
Constructs a CMFCColorBar
object.
CMFCColorBar(
const CArray<COLORREF,COLORREF>& colors,
COLORREF color,
LPCTSTR lpszAutoColor,
LPCTSTR lpszOtherColor,
LPCTSTR lpszDocColors,
CList<COLORREF,COLORREF>& lstDocColors,
int nColumns,
int nRowsDockHorz,
int nColDockVert,
COLORREF colorAutomatic,
UINT nCommandID,
CMFCColorButton* pParentBtn);
CMFCColorBar(
const CArray<COLORREF,COLORREF>& colors,
COLORREF color,
LPCTSTR lpszAutoColor,
LPCTSTR lpszOtherColor,
LPCTSTR lpszDocColors,
CList<COLORREF,COLORREF>& lstDocColors,
int nColumns,
COLORREF colorAutomatic,
UINT nCommandID,
CMFCRibbonColorButton* pParentRibbonBtn);
CMFCColorBar(
CMFCColorBar& src,
UINT uiCommandID);
colors
[in] An array of colors that the framework displays on the color bar control.
color
[in] The initially selected color.
lpszAutoColor
[in] The text label of the automatic (default) color button, or NULL.
The standard label for the automatic button is Automatic.
lpszOtherColor
[in] The text label of the other button, which displays more color choices, or NULL.
The standard label for the other button is More Colors....
lpszDocColors
[in] The text label of the document colors button. The document colors palette lists all the colors that the document currently uses.
lstDocColors
[in] A list of colors that the document currently uses.
nColumns
[in] The number of columns that the array of colors has.
nRowsDockHorz
[in] The number of rows that the color bar has when it is docked horizontally.
nColDockVert
[in] The number of columns that the color bar has when it is docked vertically.
colorAutomatic
[in] The default color that the framework applies when you click the automatic button.
nCommandID
[in] The color bar control command ID.
pParentBtn
[in] A pointer to a parent button.
src
[in] An existing CMFCColorBar
object to be copied into the new CMFCColorBar
object.
uiCommandID
[in] The command ID.
Calculates the vertical and horizontal margins that are required to contain the buttons on the color bar control, and adjusts the location of those buttons.
void ContextToSize(
BOOL bSquareButtons = TRUE,
BOOL bCenterButtons = TRUE);
bSquareButtons
[in] TRUE to specify that the shape of the buttons on a color bar control are square; otherwise, FALSE. The default value is TRUE.
bCenterButtons
[in] TRUE to specify that the content on the face of a color bar control button is centered; otherwise, FALSE. The default value is TRUE.
Creates a color bar control window and attaches it to the CMFCColorBar
object.
virtual BOOL Create(
CWnd* pParentWnd,
DWORD dwStyle,
UINT nID,
CPalette* pPalette=NULL,
int nColumns=0,
int nRowsDockHorz=0,
int nColDockVert=0);
pParentWnd
[in] Pointer to the parent window.
dwStyle
[in] A bitwise combination (OR) of window styles.
nID
[in] The command ID.
pPalette
[in] Pointer to a palette of colors. The default is NULL.
nColumns
[in] The number of columns in the color bar control. The default is 0.
nRowsDockHorz
[in] The number of rows in the color bar control when it is docked horizontally. The default is 0.
nColDockVert
[in] The number of columns in the color bar control when it is docked vertically. The default is 0.
TRUE if this method is successful; otherwise, FALSE.
To construct a CMFCColorBar
object, call the class constructor then this method. The Create
method creates the Windows control and initializes a list of colors.
Creates a color bar control window, attaches it to the CMFCColorBar
object, and resizes the control window to contain the specified palette of colors.
virtual BOOL CreateControl(
CWnd* pParentWnd,
const CRect& rect,
UINT nID,
int nColumns=-1,
CPalette* pPalette=NULL);
pParentWnd
[in] Pointer to the parent window. Cannot be NULL.
rect
[in] A bounding rectangle that specifies where to draw the color bar control.
nID
[in] The control ID.
nColumns
[in] The ideal number of columns in the color bar control. This method modifies that number to fit the specified palette of colors. The default is -1, which means this parameter is not specified.
pPalette
[in] Pointer to a palette of colors, or NULL. If this parameter is NULL, this method calculates the size of the color bar control as if 20 colors were specified. The default is NULL.
TRUE if this method succeeds; otherwise FALSE.
This method uses the rect, nColumns, and pPalette parameters to calculate the appropriate number or rows and columns in the color bar control, and then calls the CMFCColorBar::Create method.
Initializes a palette with the colors in a specified array of colors.
static BOOL CreatePalette(
const CArray<COLORREF, COLORREF>& arColors,
CPalette& palette);
arColors
[in] An array of colors.
palette
[in] A palette of colors.
TRUE if this method is successful; otherwise, FALSE.
Shows or hides the automatic button.
void EnableAutomaticButton(
LPCTSTR lpszLabel,
COLORREF colorAutomatic,
BOOL bEnable=TRUE);
lpszLabel
[in] The text label of the automatic (default) color button, or NULL.
The standard label for the automatic button is Automatic.
colorAutomatic
[in] The default color that the framework applies when you click the automatic button.
bEnable
[in] TRUE to enable the automatic button; FALSE to disable the automatic button. The default value is TRUE.
The text label of the automatic button is deleted if the lpszLabel parameter is NULL or the bEnable parameter is FALSE.
Enables or disables the display of a dialog box that lets the user select more colors.
void EnableOtherButton(
LPCTSTR lpszLabel,
BOOL bAltColorDlg=TRUE,
BOOL bEnable=TRUE);
lpszLabel
[in] The text label of the other button, which displays more color choices, or NULL.
The standard label for this button is More Colors....
bAltColorDlg
[in] TRUE to display the CMFCColorDialog dialog box; FALSE to display the standard CColorDialog dialog box. The default value is TRUE.
bEnable
[in] TRUE to enable the button; FALSE to disable the button. The default value is TRUE.
Retrieves the currently selected color.
COLORREF GetColor() const;
The currently selected color.
Calculates the number of rows and columns in the grid of a color bar control.
CSize GetColorGridSize(BOOL bVertDock) const;
bVertDock
[in] TRUE to perform the calculation for a vertically docked color bar control; otherwise, perform the calculation for a horizontally docked control.
A CSize object whose cx
component contains the number of columns and whose cy
component contains the number of rows.
Retrieves the command ID of the current color bar control.
UINT GetCommandID() const;
A command ID.
When the user selects a new color, the framework sends the command ID in a WM_COMMAND message to notify the parent of the CMFCColorBar
object.
Calculates the additional height that the current color bar requires to display miscellaneous user interface elements, such as the Other button or document colors.
int GetExtraHeight(int nNumColumns) const;
nNumColumns
[in] If the color bar control contains document colors, the number of columns to display in the grid of document colors. Otherwise, this value is not used.
The calculated extra height that is required.
Retrieves the color that signifies that a color button has the focus; that is, the button is hot.
COLORREF GetHighlightedColor() const;
An RGB value.
Retrieves the horizontal margin, which is the space between the left or right color cell and the client area boundary.
int GetHorzMargin();
The horizontal margin.
Retrieves the vertical margin, which is the space between the top or bottom color cell and the client area boundary.
int GetVertMargin() const;
The vertical margin.
Initializes an array of colors with the colors in a specified palette, or with the system default palette.
static int InitColors(
CPalette* pPalette,
CArray<COLORREF, COLORREF>& arColors);
pPalette
[in] A pointer to a palette object, or NULL. If this parameter is NULL, this method uses the default palette of the operating system.
arColors
[in] An array of colors.
The number of elements in the array of colors.
Indicates whether the current color bar is dockable.
BOOL IsTearOff() const;
TRUE if the current color bar control is dockable; otherwise, FALSE.
If the color bar control is dockable, it can be torn off a control bar and docked at another location.
Called by the framework when a user presses a keyboard button.
virtual BOOL OnKey(UINT nChar);
nChar
[in] The virtual-key code for the key that a user pressed.
TRUE if this method processes the specified key; otherwise, FALSE.
Called by the framework to close a hierarchy of pop-up controls.
virtual BOOL OnSendCommand(const CMFCToolBarButton* pButton);
pButton
[in] Pointer to a control that resides on a toolbar.
TRUE if this method is successful; otherwise, FALSE.
Called by the framework to enable or disable a user-interface item of a color bar control before the item is displayed.
virtual void OnUpdateCmdUI(
CFrameWnd* pTarget,
BOOL bDisableIfNoHndler);
pTarget
[in] Pointer to a window that contains a user-interface item to update.
bDisableIfNoHndler
[in] TRUE to disable the user-interface item if no handler is defined in a message map; otherwise, FALSE.
When a user of your application clicks a user-interface item, the item must know whether it should be displayed as enabled or disabled. The target of the command message provides this information by implementing an ON_UPDATE_COMMAND_UI command handler. Use this method to help process the command. For more information, see CCmdUI Class.
Opens a color dialog box.
virtual BOOL OpenColorDialog(
const COLORREF colorDefault,
COLORREF& colorRes);
colorDefault
[in] The color that is selected by default when the color dialog box opens.
colorRes
[out] The color that a user selected.
TRUE if the user selected a color; FALSE if the user canceled the color dialog box.
Completely redraws the color bar control.
virtual void Rebuild();
Sets the logical palette of the specified device context to the palette of the parent button of the current color bar control.
CPalette* SelectPalette(CDC* pDC);
pDC
[in] Pointer to the device context of the parent button of the current color bar control.
Pointer to the palette that is replaced by the palette of the parent button of the current color bar control.
Sets the color that is currently selected.
void SetColor(COLORREF color);
color
[in] An RGB color value.
Sets a new name for a specified color.
static void SetColorName(
COLORREF color,
const CString& strName);
color
[in] The RGB value of a color.
strName
[in] The new name for the specified color.
This method changes the name of the specified color in all CMFCColorBar
objects in your application.
Sets a new command ID for a color bar control.
void SetCommandID(UINT nCommandID);
nCommandID
[in] A command ID.
Call this method to modify the command ID of a color bar control and to notify the parent window of the control that the ID has changed.
Sets the list of colors that are used in the current document.
void SetDocumentColors(
LPCTSTR lpszCaption,
CList<COLORREF,COLORREF>& lstDocColors,
BOOL bShowWhenDocked=FALSE);
lpszCaption
[in] A caption that is displayed when the color bar control is not docked.
lstDocColors
[in] A list of colors that replaces the current document colors.
bShowWhenDocked
[in] TRUE to show document colors when the color bar control is docked; otherwise, FALSE. The default value is FALSE.
Document colors are the colors that are currently used in a document. The framework automatically maintains a list of document colors, but you can use this method to modify the list.
Sets the horizontal margin, which is the space between the left or right color cell and the boundary of the client area.
void SetHorzMargin(int nHorzMargin);
nHorzMargin
[in] The horizontal margin, in pixels.
By default, the CMFCColorBar::CMFCColorBar constructor sets the horizontal margin to 4 pixels.
Sets the m_pWndPropList
protected data member to the specified pointer to a property grid control.
void SetPropList(CMFCPropertyGridCtrl* pWndList);
pWndList
[in] Pointer to property grid control object.
Sets the vertical margin, which is the space between the top or bottom color cell and the client area boundary.
void SetVertMargin(int nVertMargin);
nVertMargin
[in] The vertical margin, in pixels.
By default, the CMFCColorBar::CMFCColorBar constructor sets the vertical margin to 4 pixels.
Requests the frame window that owns the color bar control to update the message line in the status bar.
virtual void ShowCommandMessageString(UINT uiCmdId);
uiCmdId
[in] A command ID. (This parameter is ignored.)
This method sends the WM_SETMESSAGESTRING message to the owner of the color bar control.