Changing the colour of static text.

This is a discussion on Changing the colour of static text. within the Windows Programming forums, part of the Platform Specific Boards category; Hey, i'm trying to create a function that will change the colour of a string of static text by passing ...

  1. #1
    Registered User -leech-'s Avatar
    Join Date
    Nov 2001
    Posts
    54

    Changing the colour of static text.

    Hey, i'm trying to create a function that will change the colour of a string of static text by passing its resource ID. So far the function i have doesn't seem to be working but everything compiles fine with no errors:

    Code:
    void SetStaticTextColour(HWND hwnd, WPARAM wParam, int ID, unsigned short r, unsigned short g, unsigned short b)
    {
    	HDC hdcStatic = (HDC)wParam;
    	PostMessage(hwnd, WM_CTLCOLORSTATIC, (WPARAM)hdcStatic, (LPARAM)MAKEINTRESOURCE(ID));
    	SetBkMode(hdcStatic, TRANSPARENT);
    	SetTextColor(hdcStatic, RGB(r, g, b));
    }
    Any ideas?
    Not yet, have to think of one...

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Try WM_CTLCOLORSTATIC message.

    edit: don't mind me i thought you had a different message in your post.
    Last edited by MrWizard; 02-09-2003 at 10:28 PM.

  3. #3
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    You can't just post the WM_CTLCOLORSTATIC message and then do your handling - you actually have to do your handling ON the WM_CTLCOLORSTATIC message.

    Also, the return value coming off of the message should be a new brush from CreateBrush() or one of the other brush-creating functions, which defines the background color (if you leave that out, only the actual text background will be changed, not the background for the control).

    search MSDN for more info.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reset static control's text ?
    By willc0de4food in forum Windows Programming
    Replies: 12
    Last Post: 08-18-2005, 03:00 AM
  2. changing the colour of text in vc++6
    By satory in forum C Programming
    Replies: 1
    Last Post: 10-22-2004, 09:35 AM
  3. ADDING text to a STATIC control
    By Garfield in forum Windows Programming
    Replies: 2
    Last Post: 09-01-2003, 10:48 AM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 05:10 PM
  5. Setting static text color -- I know I'm doing something wrong
    By Garfield in forum Windows Programming
    Replies: 4
    Last Post: 01-26-2002, 01:59 PM

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