CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2009
    Posts
    116

    How to change a button colour?

    May I know how to change a button colour using visual C++ ? Currently using visual studio 2010.

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: How to change a button colour?

    Quote Originally Posted by PHChang View Post
    May I know how to change a button colour using visual C++ ? Currently using visual studio 2010.
    http://msdn.microsoft.com/en-us/library/0wwk06hc.aspx
    http://msdn.microsoft.com/en-us/library/bb983153.aspx

  3. #3
    Join Date
    Apr 2009
    Posts
    116

    Re: How to change a button colour?

    That means I need to tie a button with control variable with CMFCButton class in order to use it right?

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: How to change a button colour?

    Quote Originally Posted by PHChang View Post
    That means I need to tie a button with control variable with CMFCButton class in order to use it right?
    You wan process WM_CTLCOLOR for regular buttons, or use a CMFCButton with its methods to set the colors. Either way.

  5. #5
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: How to change a button colour?

    the WM_CTLCOLOR route will not work for themed buttons.

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: How to change a button colour?

    BS_OWNERDRAW style is mandatory to let button be properly painted with WM_CTLCOLOR.

    WM_CTLCOLORBTN message
    The WM_CTLCOLORBTN message is sent to the parent window of a button before drawing the button. The parent window can change the button's text and background colors. However, only owner-drawn buttons respond to the parent window processing this message.
    Best regards,
    Igor

  7. #7
    Join Date
    Apr 2009
    Posts
    116

    Re: How to change a button colour?

    Thanks. I tried the CMFCButton way and it works.

    Code:
    button.SetFaceColor(RGB(255,0,0),true);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured