S
SK
Hi,
I am trying to change the text colors of two static controls to two
differnt colors respectivly by iterating over them in a loop. The idea
is to change the text color from a group of the two static controls
based on certain conditions being met. The following is the brief
snapshot of the code:
The following is defined in start of DlgProc:
..............
static COLORREF Colors[] = { RGB(255, 0, 0), RGB(0,0,255) };
static COLORREF ColorRef = GetSysColor(COLOR_BTNTEXT);
static HBRUSH hBrush;
static int iLblCtrls[] = { IDC_Q1, IDC_Q2, NULL };
static HWND hwndLblCtrls[sizeof(iLblCtrls)/sizeof(int)] = {
NULL };
..............
case WM_INITDIALOG:
..............
..............
hBrush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
//hBrush destroyed prior to EndDialog
for(i=0;iLblCtrls;i++)
hwndLblCtrls=GetDlgItem(hDlg,iLblCtrls);
..............
..............
break;
case WM_CTLCOLORSTATIC:
{
int idCtrl = GetDlgCtrlID(HWND(lParam));
HDC hdc = (HDC)(wParam);
if(idCtrl >= IDC_Q1 && idCtrl <= IDC_Q2)
{
SetTextColor(hdc, ColorRef);
return (LRESULT) (hBrush);
} /*The resource id from IDC_Q1 to IDC_Q4 is sequential*/
return FALSE;
} /* IDC_Q1 and IDC_Q2 are static controls with SS_NOTIFY style */
break;
I HAVE THE FOLLOWING PROBLEM when I do this:
Somewhere in my DlgProc, I have this piece of code:
...............
...............
for(i=0;i<2;i++) /* NEVER WORKS for Colors[0] */
{
ColorRef = Colors;
InvalidateRect(hwndLblCtrls,NULL,FALSE);
UpdateWindow(hwndLblCtrls);//Even commenting this does'nt work
}
...............
...............
The above code does not change the text color of the 2 static controls
to Colors[0] and Colors[1] respectivly. Rather it changes the text
color of both the controls always to Colors[1] (ie. the color of last
call to SetTextColor) and ignores the first call change it to
Color[0].
I am using a static COLORREF variable to change the value of ColorRef
during the WM_CTLCOLORSTATIC call. I have also tried changing this in
WM_CTLCOLORSTATIC to..
case WM_CTLCOLORSTATIC:
.........................
SetTextColor(hdc, (idCtrl) == IDC_Q1 ? RGB(0,255,0) : RGB(0,0,255));
return (LRESULT) hBrush;
.........................
Even this does not work and always the two static label controls (i.e:
IDC_Q1 and IDC_Q2) get painted in the same text color. (i.e.the last
call to textcolor for changing textcolor of IDC_Q2 ALWAYS changes the
textcolor of IDC_Q1).
I have tried this is on 98/NT/Win2k Machines with the same result
everywhere.
I have also tried moving the invalidation routine to change color as a
seperate WM_USER message in the DlgProc. Even this does not work.
I have lost a lot of hair trying to solve this problem when all I
wanna do is change the text color of 2 static controls to different
colors respectivly. It seems trivial but always fails.
Is this is a bug in WM_CTLCOLORSTATIC handling from MS or is it a bug
in my code. All you Win32 gurus out there please help...!!
Thanks in advance.
Cheers
SK.
I am trying to change the text colors of two static controls to two
differnt colors respectivly by iterating over them in a loop. The idea
is to change the text color from a group of the two static controls
based on certain conditions being met. The following is the brief
snapshot of the code:
The following is defined in start of DlgProc:
..............
static COLORREF Colors[] = { RGB(255, 0, 0), RGB(0,0,255) };
static COLORREF ColorRef = GetSysColor(COLOR_BTNTEXT);
static HBRUSH hBrush;
static int iLblCtrls[] = { IDC_Q1, IDC_Q2, NULL };
static HWND hwndLblCtrls[sizeof(iLblCtrls)/sizeof(int)] = {
NULL };
..............
case WM_INITDIALOG:
..............
..............
hBrush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
//hBrush destroyed prior to EndDialog
for(i=0;iLblCtrls;i++)
hwndLblCtrls=GetDlgItem(hDlg,iLblCtrls);
..............
..............
break;
case WM_CTLCOLORSTATIC:
{
int idCtrl = GetDlgCtrlID(HWND(lParam));
HDC hdc = (HDC)(wParam);
if(idCtrl >= IDC_Q1 && idCtrl <= IDC_Q2)
{
SetTextColor(hdc, ColorRef);
return (LRESULT) (hBrush);
} /*The resource id from IDC_Q1 to IDC_Q4 is sequential*/
return FALSE;
} /* IDC_Q1 and IDC_Q2 are static controls with SS_NOTIFY style */
break;
I HAVE THE FOLLOWING PROBLEM when I do this:
Somewhere in my DlgProc, I have this piece of code:
...............
...............
for(i=0;i<2;i++) /* NEVER WORKS for Colors[0] */
{
ColorRef = Colors;
InvalidateRect(hwndLblCtrls,NULL,FALSE);
UpdateWindow(hwndLblCtrls);//Even commenting this does'nt work
}
...............
...............
The above code does not change the text color of the 2 static controls
to Colors[0] and Colors[1] respectivly. Rather it changes the text
color of both the controls always to Colors[1] (ie. the color of last
call to SetTextColor) and ignores the first call change it to
Color[0].
I am using a static COLORREF variable to change the value of ColorRef
during the WM_CTLCOLORSTATIC call. I have also tried changing this in
WM_CTLCOLORSTATIC to..
case WM_CTLCOLORSTATIC:
.........................
SetTextColor(hdc, (idCtrl) == IDC_Q1 ? RGB(0,255,0) : RGB(0,0,255));
return (LRESULT) hBrush;
.........................
Even this does not work and always the two static label controls (i.e:
IDC_Q1 and IDC_Q2) get painted in the same text color. (i.e.the last
call to textcolor for changing textcolor of IDC_Q2 ALWAYS changes the
textcolor of IDC_Q1).
I have tried this is on 98/NT/Win2k Machines with the same result
everywhere.
I have also tried moving the invalidation routine to change color as a
seperate WM_USER message in the DlgProc. Even this does not work.
I have lost a lot of hair trying to solve this problem when all I
wanna do is change the text color of 2 static controls to different
colors respectivly. It seems trivial but always fails.
Is this is a bug in WM_CTLCOLORSTATIC handling from MS or is it a bug
in my code. All you Win32 gurus out there please help...!!
Thanks in advance.
Cheers
SK.