次の方法で共有


CMFCColorMenuButton クラス

CMFCColorMenuButton クラスは、カラー ピッカー ダイアログ ボックスを起動するメニュー コマンドまたはツール バーのボタンをサポートします。

class CMFCColorMenuButton : public CMFCToolBarMenuButton

メンバー

パブリック コンストラクター

[名前]

説明

CMFCColorMenuButton::CMFCColorMenuButton

CMFCColorMenuButton オブジェクトを構築します。

パブリック メソッド

[名前]

説明

CMFCColorMenuButton::EnableAutomaticButton

標準のカラー ボタンの上にある "自動" ボタンを有効または無効にします (標準システムの自動ボタンのラベルは [自動] です)。

CMFCColorMenuButton::EnableDocumentColors

システム カラーの代わりにドキュメント固有の色を表示できるようにします。

CMFCColorMenuButton::EnableOtherButton

標準のカラー ボタンの下にある "その他" ボタンを有効または無効にします (標準的なシステムの "その他" ボタンのラベルは [その他の色] です)。

CMFCColorMenuButton::EnableTearOff

カラー ペインのティアオフ機能を有効にします。

CMFCColorMenuButton::GetAutomaticColor

現在の自動設定の色を取得します。

CMFCColorMenuButton::GetColor

現在のボタンの色を取得します。

CMFCColorMenuButton::GetColorByCmdID

指定されたコマンド ID に対応する色を取得します。

CMFCColorMenuButton::OnChangeParentWnd

親ウィンドウが変更されたときに、フレームワークによって呼び出されます。

CMFCColorMenuButton::OpenColorDialog

色を選択するためのダイアログ ボックスを開きます。

CMFCColorMenuButton::SetColor

現在のカラー ボタンの色を設定します。

CMFCColorMenuButton::SetColorByCmdID

指定されたカラー メニュー ボタンの色を設定します。

CMFCColorMenuButton::SetColorName

指定した色の新しい名前を設定します。

CMFCColorMenuButton::SetColumnsNumber

CMFCColorBar オブジェクトにより表示される列数を設定します。

プロテクト メソッド

[名前]

説明

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 オブジェクトを設定します。 このコードは、「ワードパッドのサンプル:MFC ワードパッド アプリケーション」の一部です。

    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 クラス