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?
Printable View
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?
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.
What DC do I need?
>>hWin = GetDC(listWin);
SetTextColor(hWindows, COLOR_BTNFACE + 2);<<
you're storing the value in hWin but setting the text of hWindows.
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.
Oh yeah, that was my second guess...:)
Can I have a short example on trapping it and changing the text color?
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;
That didn't work at all.
well I didn't think so...I was just taking a stab in the dark. :stabstabstab:
Red text -
Code:case WM_CTLCOLORLISTBOX:
SetTextColor((HDC)wParam,RGB(255,0,0));
return (LRESULT)GetStockObject(WHITE_BRUSH);
How do I fill the whole background of the listbox with black?
same way only SetBkColor?
I tried that but it only changes text background.
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.