locked
CMFCButton SetFaceColor Error in CFormView RRS feed

  • Question

  • Hi~all

    the CMFCButton::SetFaceColor API fail when I create a project with

    Office 2007 (Black theme) Style

    But when I create dialog based project, the following code are success.

    Does anyone know what I need to do to fix this issue?

        CMFCButton *btnSubmit = new CMFCButton;
        CRect rctButton(10, 12, 125, 44);
        btnSubmit->m_bTransparent = FALSE;

        btnSubmit->Create(_T("Submit"),
            WS_CHILD | WS_VISIBLE | BS_ICON,
            rctButton,
            this,
            12004);
        btnSubmit->m_bTransparent = FALSE;
        btnSubmit->SetTextColor(RGB(127,  0,  0)); //<--Success
        btnSubmit->SetFaceColor(RGB(  0,255,  0),TRUE);    //<--Fail...


    Wednesday, May 18, 2011 3:06 AM

Answers

  • Before creating the button try this line:

     

    btnSubmit->m_bDontUseWinXPTheme = TRUE;

    • Marked as answer by 陸雲 Wednesday, May 18, 2011 7:46 AM
    Wednesday, May 18, 2011 7:05 AM

All replies

  • Why are you calling btnSubmit->m_bTransparent = FALSE; two times? IF you have an error message, can you please post the error message?

    Thanks and Regards Selvam http://www15.brinkster.com/selvamselvam/
    Wednesday, May 18, 2011 4:04 AM
  • Hi~Selvam

    Thanks your reply :)

    This is no error message in my code.

    I call btnSubmit->m_bTransparent = FALSE two time because of I'm not sure calling transparent once is valid.

    My code in Dialog based Project is fine, the button background color display green.

    I don't understand what the difference between "Dialog based project" and "Office 2007 (Black theme) Style" project....


    Wednesday, May 18, 2011 6:30 AM
  • Before creating the button try this line:

     

    btnSubmit->m_bDontUseWinXPTheme = TRUE;

    • Marked as answer by 陸雲 Wednesday, May 18, 2011 7:46 AM
    Wednesday, May 18, 2011 7:05 AM
  • Hi~Viorel_

    Your solution works fine.

    Thank you very much, I'm so glad about it :-)

    Wednesday, May 18, 2011 7:45 AM
  • Viorel_

    When I set m_bDon'tUseWinXpTheme = true and call .SetFaceColor() I loose the 3d look of the button. 

    Is that expected?

     

    Thanks,

    Andrei

    Tuesday, July 26, 2011 7:22 PM
  • Yes, it's expected, because look of button is derived from windows theme.

    So when disabled, all buttons use only "win 2k" theme, which is "not very nice".

    Has someone created such a derived class of CMFCButton, which can use face colors and don't loose other theme features, please? 

    Thursday, December 20, 2012 9:44 AM