Thread: customizing control colors

  1. #1
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768

    customizing control colors

    How can I customize the color of a control, like buttons and and text edit boxes; without using any classes or mfc, just plain api?


    Thank you.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    This comes up a lot so a board search will give you lots of information.

    Generally you handle WM_CTLCOLOR* messages which are sent to the control parent and return an HBRUSH that's used to paint the control background. This works for most controls, buttons being the notable exception. Some control message are:

    WM_CTLCOLORSTATIC
    WM_CTLCOLREDIT
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    If I understand it right, with WM_CTLCOLOR I know when the control is going to be drawn, but how do I change it's colors?
    Also why the button is an exception?


    thanks
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>how do I change its colors<<

    For example:
    From msdn for WM_CTLCOLOREDIT:
    If an application processes this message, it must return the handle of a brush. The system uses the brush to paint the background of the edit control.
    >>Also why the button is an exception?<<

    board search
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    .
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  6. #6
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    just a small problem with that... windows repaints over it, so the only thing in the edit box control that changes are the edges... so it's still white(default color)
    Last edited by Devil Panther; 02-25-2004 at 02:45 PM.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  7. #7
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    The WPARAM of the WM_CTLCOLOR* messages is the control HDC which you can use to, for example, SetBkMode or SetBkColor. You can also SetTextColor with that device context, too.

    It may be that text you are adding to the control is being drawn with a default background colour. Use SetBkMode or SetTextColor to modify this if you need to, eg:
    Code:
    SetBkMode((HDC)wParam,TRANSPARENT);
    Last edited by Ken Fitlike; 02-25-2004 at 04:18 PM.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  8. #8
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    i see... thanks alot.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  9. #9
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    Only one last problem with the edit boxes, if the control is empty and I focus on it, it returns to the default color, and then when I type something it changes to the chosen color. why? how do I fix it?
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. (Multiline) Edit Control Limit
    By P4R4N01D in forum Windows Programming
    Replies: 9
    Last Post: 05-17-2008, 11:56 AM
  2. line number on a rich edit control
    By rakan in forum Windows Programming
    Replies: 1
    Last Post: 02-18-2008, 07:58 AM
  3. Rich Edit Control Colors
    By mrafcho001 in forum Windows Programming
    Replies: 2
    Last Post: 07-08-2006, 04:26 PM
  4. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM