CMFCColorMenuButton选件类

CMFCColorMenuButton 选件类支持菜单命令或启动颜色选择器对话框的工具栏按钮。

class CMFCColorMenuButton : public CMFCToolBarMenuButton

成员

Bb983045.collapse_all(zh-cn,VS.110).gif公共构造函数

名称

说明

CMFCColorMenuButton::CMFCColorMenuButton

构造 CMFCColorMenuButton 对象。

Bb983045.collapse_all(zh-cn,VS.110).gif公共方法

名称

说明

CMFCColorMenuButton::EnableAutomaticButton

启用和禁用常规的颜色按钮上确定“auto”按钮。 (标准系统自动按钮被标记 自动。)

CMFCColorMenuButton::EnableDocumentColors

使文档无需特定颜色显示而不是系统颜色。

CMFCColorMenuButton::EnableOtherButton

启用和禁用常规的颜色按钮下方的“其他”按钮。 (标准系统“other”按钮被标记 更多颜色…。)

CMFCColorMenuButton::EnableTearOff

启用此功能撕下颜色窗格。

CMFCColorMenuButton::GetAutomaticColor

检索当前自动颜色。

CMFCColorMenuButton::GetColor

检索当前按钮的颜色。

CMFCColorMenuButton::GetColorByCmdID

检索对应于指定的命令ID.的颜色

CMFCColorMenuButton::OnChangeParentWnd

调用由结构,当父窗口更改。

CMFCColorMenuButton::OpenColorDialog

打开颜色选择对话框。

CMFCColorMenuButton::SetColor

set current color按钮的颜色。

CMFCColorMenuButton::SetColorByCmdID

设置指定的颜色菜单按钮的颜色。

CMFCColorMenuButton::SetColorName

设置新名称对于指定的颜色。

CMFCColorMenuButton::SetColumnsNumber

设置由 CMFCColorBar 对象显示的列数。

Bb983045.collapse_all(zh-cn,VS.110).gif受保护的方法

名称

说明

CMFCColorMenuButton::CopyFrom

复制另一个工具栏按钮到当前按钮。

CMFCColorMenuButton::CreatePopupMenu

创建一个颜色选择器对话框。

CMFCColorMenuButton::IsEmptyMenuAllowed

指示空菜单是否支持。

CMFCColorMenuButton::OnDraw

调用框架在按钮的图像。

CMFCColorMenuButton::OnDrawOnCustomizeList

调用由结构,在 CMFCColorMenuButton 对象在工具栏自定义对话框的列表之前显示。

备注

CMFCColorMenuButton 对象若要替换原始菜单命令或工具栏按钮,请创建 CMFCColorMenuButton 对象,并设置所有适当的 CMFCColorBar选件类 样式,然后调用 CMFCToolBar选件类 选件类的 ReplaceButton 方法。 如果自定义工具栏,请调用 CMFCToolBarsCustomizeDialog::ReplaceButton 方法。

在处理 CMFCColorMenuButton::CreatePopupMenu 事件处理程序中,颜色选择器对话框中创建。 事件处理程序有两 WM_COMMAND 消息的父级框架。 分配给原始菜单命令或工具栏按钮的 CMFCColorMenuButton 对象发送控件ID。

示例

下面的示例演示如何创建和配置颜色菜单按钮使用各种方法。CMFCColorMenuButton 选件类。 在此示例中,CPalette 对象首次创建然后用于构造对象 CMFCColorMenuButton 选件类。 启用它自动和其他按钮并将其颜色和列号然后配置 CMFCColorMenuButton 对象。 此代码是 Word填充示例的一部分。

    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;
}

继承层次结构

CObject

   CMFCToolBarButton

      CMFCToolBarMenuButton

         CMFCColorMenuButton

要求

标头: afxcolormenubutton.h

请参见

参考

层次结构图

CMFCColorBar选件类

CMFCToolBar选件类

CMFCToolBarsCustomizeDialog选件类

CMFCColorButton选件类

其他资源

MFC 类