1

Ive made a GUI but would like to change the text color for this line. I have tired to search but all I can find is changing colors for print output.

warn1 = CreateWindowEx( 0, "STATIC", "", WS_VISIBLE Or WS_CHILD, 20, 150, 300, 40, hWnd, 0, 0, 0 )
SetWindowText( warn1, "WARNING:")

I would like the "WARNING" in red if possible.

shaggs
  • 600
  • 7
  • 27

1 Answers1

1

Handle the WM_CTLCOLORSTATIC window message in the parent window and return the respective device context handle having a color brush set. Here is an example:

function WinProc(hWnd As HWND, uMsg As UINT, wParam As WPARAM, lParam As LPARAM) As LRESULT
  Select Case uMsg
    Case WM_CREATE:
      warn1 = CreateWindowEx( 0, "STATIC", "", WS_VISIBLE Or WS_CHILD, 20, 150, 300, 40, hWnd, 0, 0, 0 )
      SetWindowText( warn1, "WARNING:")

    case WM_CTLCOLORSTATIC:
      If lParam = warn1 Then
        Dim As LRESULT lBrush = DefWindowProc(hWnd, uMsg, wParam, lParam)
        SetBkMode(wParam, TRANSPARENT)
        'SetBkColor(wParam, BGR(100, 100, 200))
        SetTextColor(wParam, BGR(255,0,0))
        return lBrush
      EndIf

      ...

  End Select

  Return DefWindowProc(hWnd, uMsg, wParam, lParam)
End Function
StW
  • 243
  • 2
  • 8