Advertisement

changing & checking static label text color

Started by March 11, 2002 03:25 PM
6 comments, last by solo_smiley 22 years, 7 months ago
I need help changing and checking a single Static label text color. I have 2 static labels but i only want to change the first ond when i click a button. This is what i got so far: ... case WM_CREATE: { static HWND StaticLabel1, StaticLabel2, Button1; COLORREF StaticColor = RGB(0, 0, 0); // default black #define StaticLabel1_ID 101 #define StaticLabel2_ID 102 #define Button1_ID 201 StaticLabel1 = CreateWindowEx(NULL, "STATIC", "Label 1", WS_CHILD | WS_VISIBLE, 10, 10, 180, 15, hwnd, (HMENU)StaticLabel1_ID, NULL, NULL); StaticLabel2 = CreateWindowEx(NULL, "STATIC", "Label 2", WS_CHILD | WS_VISIBLE, 10, 35, 180, 15, hwnd, (HMENU)StaticLabel2_ID, NULL, NULL); Button1 = CreateWindowEx(NULL, "BUTTON", "Text color", WS_CHILD | WS_VISIBLE, 17, 25, 75, 25, hwnd, (HMENU)Button1_ID, NULL, NULL); break; } case WM_CTLCOLORSTATIC: { SetTextColor((HDC)wParam, StaticColor); SetBkMode((HDC)wParam, TRANSPARENT); return (LONG) GetStockObject(NULL_BRUSH); } case WM_COMMAND: { switch(wParam) { case Button1_ID: { // check StaticLabel1 text color if "black" change to "red" break; } break; } } ... Edited by - solo_smiley on March 11, 2002 5:28:30 PM
Why not store the colour in a variable, you can check the variable and use SetWindowText to change if necessary.


  BOOL SetWindowText(  HWND hWnd,         // handle to window or control  LPCTSTR lpString   // title or text);  


from MSDN.


,Jay
Advertisement
i have the color declared as COLORREF:
COLORREF StaticColor = RGB(0, 0, 0); // default black

and I dont want to change the text, I want to change its color so SetWindowText would be useless unless you can use it to change the text color.
Ah, good point. I don''t think you can change the title bar text colour of a window without changing the whole system default text colours.

I had a quick browse through MSDN but could''nt find anything.

,Jay

Reference:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/windows_1w6w.asp
I dont want to change the title bar text color i want to change a label color =)
Can you define what you mean by label, the only text in your code is the window titles "Label 1", "Label 2" and "Text Color".

,Jay
Advertisement
StaticLabel1 is the label which is created by
StaticLabel1 = CreateWindowEx(NULL, "STATIC", "Label 1", WS_CHILD | WS_VISIBLE, 10, 10, 180, 15, hwnd, (HMENU)StaticLabel1_ID, NULL, NULL);

This colors all the static windows:
case WM_CTLCOLORSTATIC:
{
SetTextColor((HDC)wParam, StaticColor);
SetBkMode((HDC)wParam, TRANSPARENT);
return (LONG) GetStockObject(NULL_BRUSH);
}

I just want to change the text color of StaticLabel1

Edited by - solo_smiley on March 12, 2002 6:03:24 PM
If this code colours the windows then have you tried copying it into a function like so.

  LONG ChangeLabelColor(LONG LColor) {    SetTextColor((HDC)wParam, LColor);    SetBkMode((HDC)wParam, TRANSPARENT);    return (LONG) GetStockObject(NULL_BRUSH);}  


I don''t know if you''d have to pass wParam as well as a color.

Perhaps this would work ?

,Jay

This topic is closed to new replies.

Advertisement