Click to See Complete Forum and Search --> : Static Control, Setting colour, GetSysColor
QBasicer
August 6th, 2005, 08:07 PM
Ok, before I start, this is what it looks like:
http://img31.imageshack.us/img31/7190/bavrcguiv0600colourerr3lg.gif
And the code:
case WM_CTLCOLORSTATIC:
{
if ((HWND)lParam == GetDlgItem(hDlg, STXT_TIME)){
RECT rc;
GetClientRect((HWND)lParam, &rc);
HDC hdc= (HDC) wParam;
SetTextColor(hdc, RGB(255,0,0));
SetBkMode(hdc, TRANSPARENT);
SetBkColor(hdc,(LONG)GetSysColorBrush(COLOR_WINDOW)); // Backround color for EditBox
return (LONG)GetSysColorBrush(COLOR_WINDOW);
}
}
break;
Ok, now my question is, how do I get it so that the white behind the text is the same as the window color? For some reason, what I have (trying to get the Window COlor, fails).
Thanks!
Hacker2
August 6th, 2005, 11:19 PM
It looks exactly like code I've used, and it should work.
Are you sure the code executes?
try just
case WM_CTLCOLORSTATIC:
{
RECT rc;
GetClientRect((HWND)lParam, &rc);
HDC hdc= (HDC) wParam;
SetTextColor(hdc, RGB(255,0,0));
SetBkMode(hdc, TRANSPARENT);
SetBkColor(hdc,(LONG)GetSysColorBrush(COLOR_WINDOW));
return (LONG)GetSysColorBrush(COLOR_WINDOW);
}
break;
i.e. take out the "if", so that all statics get colored
By the way, what is GetClientRect for?
in your sample, you get it, but don't use it.
Is there another part of the code not shown?
QBasicer
August 10th, 2005, 10:35 PM
There is no more code than I have listed there, I just don't do anythign with the rect.
It doesn't help, everything else has a white BG.
humptydumpty
August 11th, 2005, 12:38 AM
Ok, before I start, this is what it looks like:
http://img31.imageshack.us/img31/7190/bavrcguiv0600colourerr3lg.gif
And the code:
case WM_CTLCOLORSTATIC:
{
if ((HWND)lParam == GetDlgItem(hDlg, STXT_TIME)){
RECT rc;
GetClientRect((HWND)lParam, &rc);
HDC hdc= (HDC) wParam;
SetTextColor(hdc, RGB(255,0,0));
SetBkMode(hdc, TRANSPARENT);
SetBkColor(hdc,(LONG)GetSysColorBrush(COLOR_WINDOW)); // Backround color for EditBox
return (LONG)GetSysColorBrush(COLOR_WINDOW);
}
}
break;
Ok, now my question is, how do I get it so that the white behind the text is the same as the window color? For some reason, what I have (trying to get the Window COlor, fails).
Thanks!
what u mean i think you wann background color of the control is same as your window color am i right
if yes
check it
HBRUSH m_hDialogBrush;
HDC hDC = (HDC)wParam;
HWND hWndStat = (HWND)lParam;
if((::GetDlgCtrlID(hWndStat) != IDC_BUTTON2) || (::GetDlgCtrlID(hWndStat) != IDC_EDIT3))
{
::SetBkMode(hDC,OPAQUE);
return (long) (HBRUSH)::CreateSolidBrush(RGB(250, 250, 255));
}
else
{
::SetBkMode(hDC,TRANSPARENT);
return (long) (HBRUSH)::CreateSolidBrush(RGB(245, 245, 245));
}
QBasicer
August 11th, 2005, 06:07 AM
what u mean i think you wann background color of the control is same as your window color am i right
The background color is still white for some reason.
humptydumpty
August 11th, 2005, 06:19 AM
The background color is still white for some reason.
it's not happen by chance. here we are setting the backgroud colorfor a static control.if you want to change the color just change your RGB value .
write these line and check it out
to see
try
::SetBkMode(hDC,TRANSPARENT);
return (long) (HBRUSH)::CreateSolidBrush(RGB(20,140,143));
you can know how you can set the background color of a statc control
QBasicer
August 12th, 2005, 07:04 PM
Solved, using COLOR_3DFACE instead of COLOR_WINDOW, I assume this because I'm using a dialog based app, but I'm not sure.
Hacker2
August 12th, 2005, 07:32 PM
I think COLOR_3DFACE is for the color of a button, (usually grey)
but COLOR_WINDOW, is the color
of the background for windows, such as the text window in NotePad.
(usually white)
So yes that would explain it. Sometimes it's just the simplest things.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.