CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2005
    Posts
    13

    Changing Text Color in a Button

    Hi everyone,
    I have a button anda text and a window handler to it, now how do I change its text's color?

    Thanks in advance.

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Changing Text Color in a Button

    Handle the WM_CTLCOLOR message.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  3. #3
    Join Date
    Dec 2002
    Location
    Candia, NH
    Posts
    374

    Re: Changing Text Color in a Button

    I am not sure, but I think the message at the win32 level is WM_CTLCOLORxxx where xxx stands for a bunch of different items. I have always thought the only way you could color the text of a button is via an owner draw operation (at least at API level 4). In any case, the WM_CTLCOLORBTN for setting the button color does not work; its a bogus message (it is sent but it is useless). Its either the control panel or a full owner draw.

    However, I have been able to use these color messages to set the text color of static windows, edit boxes and the background color of dialog and edit boxes. However, the color of the text in a disabled edit control I have not been able to set using these messages (I have to cheat by making the edit box read only). Be careful when you handle these messages. You set text and background for the same control in different messages depending upon their status (enabled, disabled). Some controls you can't do anything with (colorwise) unless you do a full owner draw.

    Controlling Windows colors is a pain and not very consistent. Let me know how you make out in your attempts!

    Brian

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