WM_CTLCOLORSTATIC question.

This is a discussion on WM_CTLCOLORSTATIC question. within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I can't figure out how to handle the WM_CTLCOLORSTATIC message to change the background color of a read-only edit ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    80

    WM_CTLCOLORSTATIC question.

    Hi, I can't figure out how to handle the WM_CTLCOLORSTATIC message to change the background color of a read-only edit box. Anyone know how to do this? I would appreciate any help EXTREMELY much since I've tried searching for an example, using google, for quite some time now.

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    If it's read_only, dump the editbox and go with a static control instead. You can send messages just as easily and if for some reason you needed the message sent to the static, there shouldn't be a problem assigning the message to a char or string for any additional useage.

    Code:
           
            SetBkColor(dc, RGB(0,0,128));
            SetBkMode(dc, OPAQUE);

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    80
    Ok, but doesn't that code change only the row in the control which have text already? I think I tried something like that earlier but only one line was changed.

    EDIT: The code is for a chat client and the read-only box is used to display the conversation.
    Last edited by antex; 04-10-2007 at 10:04 AM.

  4. #4
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    Fill the TEXT(" ") with spaces, length of static. Then use SetDlgItemText to either send text to the static, or use spaces again to clear it. It'll work, whether or not it's correct is another matter.

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    80
    Yeah I guess that would work but in my opinion there should be an API for these kind of things. If there is no such thing I'll just have to try something else.

    Thanks for replying!

  6. #6
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,262
    You need to return a brush for the control to paint the non-text background with.
    Code:
    // Set the edit to white on black.
    case WM_CTLCOLORSTATIC:
    {
    	HDC hdc = (HDC)wParam;
    
    	SetBkColor(hdc, 0);
    	SetTextColor(hdc, 0xFFFFFF);
    	return (LRESULT)GetStockObject(BLACK_BRUSH);
    }

  7. #7
    Registered User
    Join Date
    Sep 2004
    Posts
    80
    Oh, thank you very much! That's the thing I was looking for !

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21