CMFCColorMenuButton Class
The CMFCColorMenuButton class supports a menu command or a toolbar button that starts a color picker dialog box.
class CMFCColorMenuButton : public CMFCToolBarMenuButton
Members
Public Constructors
Name |
Description |
---|---|
Constructs a CMFCColorMenuButton object. |
Public Methods
Name |
Description |
---|---|
Enables and disables an "automatic" button that is positioned above the regular color buttons. (The standard system automatic button is labeled Automatic.) |
|
Enables the display of document-specific colors instead of system colors. |
|
Enables and disables an "other" button that is positioned below the regular color buttons. (The standard system "other" button is labeled More Colors….) |
|
Enables the ability to tear off a color pane. |
|
Retrieves the current automatic color. |
|
Retrieves the current button's color. |
|
Retrieves the color that corresponds to a specified command ID. |
|
Called by the framework when the parent window changes. |
|
Opens a color selection dialog box. |
|
Sets the color of the current color button. |
|
Sets the color of the specified color menu button. |
|
Sets a new name for the specified color. |
|
Sets the number of columns that are displayed by a CMFCColorBar object. |
Protected Methods
Name |
Description |
---|---|
Copies another toolbar button to the current button. |
|
Creates a color picker dialog box. |
|
Indicates whether empty menus are supported. |
|
Called by the framework to display an image on a button. |
|
Called by the framework before a CMFCColorMenuButton object is displayed in the list of a toolbar customization dialog box. |
Remarks
To replace the original menu command or toolbar button with a CMFCColorMenuButton object, create the CMFCColorMenuButton object, set any appropriate CMFCColorBar Class styles, and then call the ReplaceButton method of the CMFCToolBar Class class. If you customize a toolbar, call the CMFCToolBarsCustomizeDialog::ReplaceButton method.
The color picker dialog box is created during the processing of the CMFCColorMenuButton::CreatePopupMenu event handler. The event handler notifies the parent frame with a WM_COMMAND message. The CMFCColorMenuButton object sends the control ID that is assigned to the original menu command or toolbar button.
Example
The following example demonstrates how to create and configure a color menu button by using various methods in the CMFCColorMenuButton class. In the example, a CPalette object is first created and then used to construct an object of the CMFCColorMenuButton class. The CMFCColorMenuButton object is then configured by enabling its automatic and other buttons, and setting its color and the number of columns. This code is part of the WordPad Sample: MFC WordPad Application.
CPalette m_palColorPicker; // Palette for color picker
int m_nNumColours;
...
CMFCColorMenuButton* CFormatBar::CreateColorButton ()
{
if (m_palColorPicker.GetSafeHandle () == NULL)
{
m_nNumColours = sizeof (crColours)/sizeof(ColourTableEntry);
ASSERT(m_nNumColours <= MAX_COLOURS);
if (m_nNumColours > MAX_COLOURS)
m_nNumColours = MAX_COLOURS;
// Create the palette
struct
{
LOGPALETTE LogPalette;
PALETTEENTRY PalEntry[MAX_COLOURS];
}pal;
LOGPALETTE* pLogPalette = (LOGPALETTE*) &pal;
pLogPalette->palVersion = 0x300;
pLogPalette->palNumEntries = (WORD) m_nNumColours;
for (int i = 0; i < m_nNumColours; i+)
{
pLogPalette->palPalEntry[i].peRed = GetRValue(crColours[i].crColour);
pLogPalette->palPalEntry[i].peGreen = GetGValue(crColours[i].crColour);
pLogPalette->palPalEntry[i].peBlue = GetBValue(crColours[i].crColour);
pLogPalette->palPalEntry[i].peFlags = 0;
}
m_palColorPicker.CreatePalette (pLogPalette);
}
CMFCColorMenuButton* pColorButton = new
CMFCColorMenuButton (ID_CHAR_COLOR, _T("Text Color..."), &m_palColorPicker);
pColorButton->EnableAutomaticButton (_T("Automatic"), RGB (0, 0, 0));
pColorButton->EnableOtherButton (_T("More Colors..."));
pColorButton->EnableDocumentColors (_T("Document's Colors"));
pColorButton->EnableTearOff (ID_COLOR_TEAROFF, 5, 2);
pColorButton->SetColumnsNumber (8);
pColorButton->SetColor(RGB(0,0,255));
// Initialize color names:
for (int i = 0; i < m_nNumColours; i+)
{
CMFCColorMenuButton::SetColorName (crColours[i].crColour, crColours[i].szName);
}
return pColorButton;
}
Inheritance Hierarchy
Requirements
Header: afxcolormenubutton.h
See Also
Concepts
Reference
CMFCToolBarsCustomizeDialog Class