Thread: SetTextColor?

  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: [email protected]

    ---------------------------------
    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,227
    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: [email protected]

    ---------------------------------
    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,227
    >>hWin = GetDC(listWin);

    SetTextColor(hWindows, COLOR_BTNFACE + 2);<<

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

  5. #5
    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,227
    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: [email protected]

    ---------------------------------
    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,227
    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: [email protected]

    ---------------------------------
    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,227
    well I didn't think so...I was just taking a stab in the dark. :stabstabstab:

  11. #11
    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: [email protected]

    ---------------------------------
    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,227
    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: [email protected]

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

  15. #15
    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

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, 06:58 AM
  2. Problems with SetTextColor()
    By Tronic in forum Windows Programming
    Replies: 2
    Last Post: 05-15-2004, 10:30 PM