gui FreeBasic中的彩色文本

时间:2015-10-29 05:07:11

标签: colors freebasic

我已经制作了一个GUI,但想要更改此行的文本颜色。 我已经厌倦了搜索,但我能找到的只是改变打印输出的颜色。

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

我想要"警告"如果可能,请用红色。

1 个答案:

答案 0 :(得分:1)

在父窗口中处理WM_CTLCOLORSTATIC窗口消息,并返回具有彩色笔刷集的相应设备上下文句柄。这是一个例子:

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