Static control text color

I have a static control:

HWND hLabelControl=CreateWindowEx(WS_EX_CLIENTEDGE,"STATIC","",
            WS_TABSTOP|WS_VISIBLE|WS_CHILD|SS_CENTER,0,0,24,24,
        hwnd,(HMENU)hS1,GetModuleHandle(NULL),NULL);

I want the button to click the color of the text on the static label to, for example, go to red.

How can i do this?

I know that there is

SetTextColor(
  _In_  HDC hdc,
  _In_  COLORREF crColor
);

but I can’t figure out how to get HDC static control.

Thanks in advance.

EDIT:

This does not work:

        HDC hDC=GetDC(hLabelControl);
        SetTextColor(hDC,RGB(255,0,0));
+5
source share
1 answer

Static controls send a message WM_CTLCOLORSTATICto parents immediately before drawing them. You can change the DC by processing this message.

case WM_CTLCOLORSTATIC:
  if (the_button_was_clicked) {
    HDC hdc = reinterpret_cast<HDC>(wParam);
    SetTextColor(hdc, COLORREF(0xFF, 0x00, 0x00));
  }
  return ::GetSysColorBrush(COLOR_WINDOW);  // example color, adjust for your circumstance

, , . , , , InvalidateRect.

+6

All Articles