BCX_SET_LABEL_COLOR function

Purpose:

BCX_SET_LABEL_COLOR sets the foreground and background colors in a BCX_LABEL Control.

Syntax:

hBrush = BCX_SET_LABEL_COLOR(hLabel, _
          RGBforeground AS COLORREF, _
          RGBbackground AS COLORREF)

Return Value:

  • Data type: HBRUSH
    hBrush The handle returned if the function succeeds. The return value is NULL if the function fails.

Parameters:

  • Data type: HWND
    hLabel The handle of the BCX_EDIT control to be colored.
  • Data type: COLORREF
    RGBforeground RGB(r,g,b) expression, or equivalent COLORREF value, for foreground color of edit control.
  • Data type: COLORREF
    RGBbackground RGB(r,g,b) expression, or equivalent COLORREF value, for background color of edit control. The background color of the parent form will be used if a -1 value is entered, for example,
    BCX_SET_LABEL_COLOR(HndlWnd, RGB(255,0,0), -1)
    

Remarks:

BCX_SET_LABEL_COLOR must be placed in the BEGIN EVENTS ... END EVENTS loop, otherwise it will not work and you will get a compile error.

Example:

 GUI "BCX_SET_LABEL_COLOR", PIXELS, ICON, 300
 GLOBAL Form1 AS HWND
 GLOBAL Label1 AS HWND
 GLOBAL Focus

 CONST ID_Form1 = 0
 CONST ID_Label1 = 1

 SUB FORMLOAD
  LOCAL Label1_Styles AS DWORD
  LOCAL Label1_XStyles AS DWORD

  Label1_Styles = WS_CHILD| _
                WS_VISIBLE| _
                   SS_LEFT| _
                 SS_NOTIFY| _
            SS_CENTERIMAGE

  Label1_XStyles = WS_EX_TRANSPARENT| _
                    WS_EX_CLIENTEDGE| _
                          WS_EX_LEFT| _
                    WS_EX_LTRREADING| _
                WS_EX_RIGHTSCROLLBAR

  Form1 = BCX_FORM("Mouse", 80, 88, 273, 102)

  Label1 = BCX_LABEL("Where is the Mouse?", _
                                     Form1, _
                                 ID_Label1, _
                                        72, _
                                        24, _
                                       108, _
                                        28, _
                             Label1_Styles, _
                            Label1_XStyles)

  SetProp(Label1, "oldproc", _
   (HANDLE)GetWindowLongPtr(Label1,GWLP_WNDPROC))

  SetWindowLongPtr(Label1, GWLP_WNDPROC,(LONG_PTR)LabelProc)
  CENTER(Form1)
  ShowWindow(Form1, SW_SHOW)
 END SUB

 BEGIN EVENTS

 SELECT CASE CBMSG

  CASE WM_MOUSEMOVE
  IF Focus THEN
   Focus = FALSE
   InvalidateRect(Label1, 0, TRUE)
  END IF

  CASE WM_CTLCOLORSTATIC
  LOCAL cFG, cBG
  IF (HANDLE)lParam = Label1 THEN
   IF Focus THEN
    cFG = 16777215
    cBG = 16711808
   ELSE
    cFG = 16711808
    cBG = 16777215
   END IF
   BCX_SET_LABEL_COLOR(Label1, cFG, cBG)
  END IF

  CASE WM_PAINT
  CASE WM_SIZE, WM_MOVE
  CASE WM_CLOSE
  DestroyWindow(Form1)
  EXIT FUNCTION

 END SELECT
 END EVENTS

 CALLBACK FUNCTION LabelProc ()
  DIM lpfnOldProc AS HANDLE
  DIM lResult AS LRESULT

  lpfnOldProc = GetProp(hWnd , "oldproc")

  SELECT CASE Msg

   CASE WM_MOUSEMOVE
   IF NOT Focus THEN
    Focus = TRUE
    InvalidateRect(Label1, 0, TRUE)
   END IF

   CASE WM_DESTROY
   SetWindowLongPtr(hWnd , GWLP_WNDPROC,(LONG_PTR) GetProp(hWnd ,"oldproc"))
   RemoveProp(hWnd , "oldproc")
   FUNCTION = CallWindowProc(lpfnOldProc, hWnd , Msg, wParam, lParam)

  END SELECT
  FUNCTION = CallWindowProc(lpfnOldProc, hWnd , Msg, wParam, lParam)
 END FUNCTION

For another example of the BCX_SET_LABEL_COLOR function see FontDemo.bas.