locked
Adding an ColorButton to a Ribbon Bar and getting the return value of the selected color?

    Question

  • How do I get the return value of the selected color of a ColorButton control from the ribbon? I can add a standard button and assign a control variable and a value variable to it and achieve my goal, which is to change the background color of my dialog. Should I go in a different direction with this, using a ColorButton and add a command handler? In the command handler, how would I use this to achieve my goal of changing the dialog color?


    Randy "DrB" Faldon


    • Edited by DrBones71 Sunday, March 04, 2012 9:11 PM This is not a CMFCColorButton, but a RibbonColorButton.
    Sunday, March 04, 2012 3:08 PM

Answers

  • Hi,


    Based on my knowledge, there is a CMFCRibbonColorButton
    class which implements a color button that you can add to a ribbon bar. The
    ribbon color button displays a drop-down menu that contains one or more color
    palettes. Here is the function which can get the color of Ribbon button:

    COLORREF CRibbonAppDoc::GetColor(void)

    {

    CMFCRibbonBar* pRibbon = ((CMDIFrameWndEx*) AfxGetMainWnd())->GetRibbonBar();

    ASSERT_VALID(pRibbon);

    CMFCRibbonColorButton* pColor = DYNAMIC_DOWNCAST( CMFCRibbonColorButton, pRibbon->FindByID(ID_FONT_COLOR));

        // Get the selected color

    return pColor->GetColor();

    }


    In addition, here are some reference for you:

    http://msdn.microsoft.com/en-us/library/cc165845.aspx

    http://msdn.microsoft.com/en-us/library/bb983440(v=VS.90).aspx

    Best Regards,

    Rob



    Rob Pan [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by DrBones71 Thursday, March 08, 2012 2:36 AM
    Tuesday, March 06, 2012 7:50 AM

All replies

  • Hi,


    Based on my knowledge, there is a CMFCRibbonColorButton
    class which implements a color button that you can add to a ribbon bar. The
    ribbon color button displays a drop-down menu that contains one or more color
    palettes. Here is the function which can get the color of Ribbon button:

    COLORREF CRibbonAppDoc::GetColor(void)

    {

    CMFCRibbonBar* pRibbon = ((CMDIFrameWndEx*) AfxGetMainWnd())->GetRibbonBar();

    ASSERT_VALID(pRibbon);

    CMFCRibbonColorButton* pColor = DYNAMIC_DOWNCAST( CMFCRibbonColorButton, pRibbon->FindByID(ID_FONT_COLOR));

        // Get the selected color

    return pColor->GetColor();

    }


    In addition, here are some reference for you:

    http://msdn.microsoft.com/en-us/library/cc165845.aspx

    http://msdn.microsoft.com/en-us/library/bb983440(v=VS.90).aspx

    Best Regards,

    Rob



    Rob Pan [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by DrBones71 Thursday, March 08, 2012 2:36 AM
    Tuesday, March 06, 2012 7:50 AM
  • Thanks, it makes since now. But, this gives me another idea of changing my background color. What is the proper way to get a handle to my main dialog and change it during runtime? For example... My app is dialog based derived from CFormView with a ribbon bar, if the above code works like I think it should, can I do something similar with the dialog?

    Thanks,

    -DrB


    Randy "DrB" Faldon

    Wednesday, March 07, 2012 3:03 AM