Archived

This topic is now archived and is closed to further replies.

darkchrono4

Changing color on static text

Recommended Posts

Trying to change the color on some text. Got the color to change but the rest of the label is black. This is what I got in my WM_CTLCOLORSTATIC message: static HBRUSH g_hbrBackground; g_hbrBackground = CreateSolidBrush(RGB(0,0,0)); HDC hdc = (HDC)wParam; SetTextColor(hdc, RGB(0, 0, 100)); SetBkMode(hdc, TRANSPARENT); return (LONG)g_hbrBackground; I''m missing something but I don''t know what it is.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
this is what i''ve used in the past:

LOGBRUSH lbBkgnd;
lbBkgnd.lbStyle = BS_HOLLOW;
lbBkgnd.lbColor = 0;
lbBkgnd.lbHatch = 0;
ghTransBrush = CreateBrushIndirect(&lbBkgnd);

ghTransBrush would be equivalent to your g_hbrBackground.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
you can also use lbStyle = BS_SOLID and lbColor = GetSysColor(COLOR_BTNFACE) if you want to use a solid colored brush, although I don''t know how well this works with themed windows/controls. COLOR_BTNFACE would pick up the color for button controls, but you could substitute another type if you wanted (like COLOR_WINDOW).

Share this post


Link to post
Share on other sites
COLOR_BTNFACE, that was what I was looking for but couldn''t remember for the life of me. I used what you posted and it works. But I had to set the color on the other text labels so they were black. Not a big deal though.

You wouldn''t happen to know how to underline the text in the label? If you hadn''t figured it out I''m trying to make a couple of ''URLs'' in my about dialog.

Share this post


Link to post
Share on other sites
sorry my first response wasn't very helpful, but since my standard windows background color is black i didn't get what the problem for you was

anyway, i just did the same (statics as clickable links) last week, so i can help you here:

1) you can get the brush 'easier' if you just call GetSysColorBrush(COLOR_BTNFACE), which relieves you of having to free any created brushes at the end.

2)

    
HFONT NormalFont = (HFONT) SendMessage ( controlwindow, WM_GETFONT, 0, 0 );

// create underlined version of the same font

LOGFONT lf;
GetObject ( NormalFont, sizeof(LOGFONT), &lf );
lf.lfUnderline = TRUE;
HFONT UnderlinedFont = CreateFontIndirect ( &lf );


then you can switch between normal and underlined font via SendMessage with WM_SETFONT




[edited by - burning_ice on May 2, 2003 4:27:06 PM]

Share this post


Link to post
Share on other sites