SetTextColor?

This is a discussion on SetTextColor? within the Windows Programming forums, part of the Platform Specific Boards category; Hi. I am using SetTextColor for a listbox. How do I use it? I tried this: HDC hWin; hWin = ...

  1. #1
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Question SetTextColor?

    Hi. I am using SetTextColor for a listbox. How do I use it? I tried this:


    HDC hWin;

    hWin = GetDC(listWin);

    SetTextColor(hWindows, COLOR_BTNFACE + 2);

    But nothing happens. What do I do?
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  2. #2
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    Well first of all, I'm pretty sure that SetTextColor takes an RGB value, so you'd want more like RGB(10,0,0) over COLOR_BTNFACE+2, secondly you're setting it to the [glaringly obvious]WRONG DC[/glaringly obvious], and third, I dunno if it works on listboxes.

  3. #3
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Question What DC

    What DC do I need?
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  4. #4
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    >>hWin = GetDC(listWin);

    SetTextColor(hWindows, COLOR_BTNFACE + 2);<<

    you're storing the value in hWin but setting the text of hWindows.

  5. #5
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    You'll need to trap the WM_CTLCOLORLISTBOX message in your message handler function. The WPARAM in this message is the DC for the list box and the LPARAM is the window handle. It is sent whenever a listbox is redrawn.
    zen

  6. #6
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    Oh yeah, that was my second guess...

  7. #7
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Question Trapping?

    Can I have a short example on trapping it and changing the text color?
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  8. #8
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    probably (but don't quote me on this...)

    Code:
    case WM_CTLCOLORLISTBOX:
         hDC = (HDC)WParam; //if this doesn't work mess aorund with HIWORD and LOWORD
         SetTextColor(hDC, RGB(255,0,0));
         return 0;

  9. #9
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Unhappy That...

    That didn't work at all.
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  10. #10
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    well I didn't think so...I was just taking a stab in the dark. :stabstabstab:

  11. #11
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    Red text -

    Code:
    case WM_CTLCOLORLISTBOX:
    		SetTextColor((HDC)wParam,RGB(255,0,0));
    	
    		return (LRESULT)GetStockObject(WHITE_BRUSH);
    zen

  12. #12
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Question Ok, it works but now...

    How do I fill the whole background of the listbox with black?
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  13. #13
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    same way only SetBkColor?

  14. #14
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Question I tried...

    I tried that but it only changes text background.
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  15. #15
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    If you want a different colour brush, return a different brush to the one I returned in the above example. If the colour isn't one of the stock ones you'll have to create your own and return it.
    zen

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SetTextColor question
    By Tropicalia in forum Windows Programming
    Replies: 3
    Last Post: 10-12-2006, 07:58 AM
  2. Problems with SetTextColor()
    By Tronic in forum Windows Programming
    Replies: 2
    Last Post: 05-15-2004, 11:30 PM

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