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, _ RGBbackground) Parameters:
Return Value:
|
Example:
GUI "EZIDEPROG", 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)GetWindowLong(Label1,GWL_WNDPROC))
SetWindowLong(Label1, GWL_WNDPROC,(DWORD)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 FARPROC
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
SetWindowLong(hWnd, GWL_WNDPROC,(DWORD) GetProp(hWnd,"oldproc"))
RemoveProp(hWnd, "oldproc")
FUNCTION = CallWindowProc(lpfnOldProc, hWnd, Msg, wParam, lParam)
END SELECT
FUNCTION = CallWindowProc(lpfnOldProc, hWnd, Msg, wParam, lParam)
END FUNCTION
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.
BCX_SET_LABEL_COLOR expands to the following
C code inside the Windows Procedure and also automatically links in
the Set_Color function:
if((HWND)lParam==Label_1 && Msg==WM_CTLCOLORSTATIC)
return Set_Color(RGB(255,255,255),RGB(0,0,0),wParam,lParam);
LRESULT Set_Color(int TxtColr,int BkColr,int wParam,int lParam)
{
static HBRUSH ReUsableBrush;
DeleteObject(ReUsableBrush);
ReUsableBrush=CreateSolidBrush(BkColr);
SetTextColor((HDC)wParam,TxtColr);
SetBkColor((HDC)wParam,BkColr);
return(LRESULT)ReUsableBrush;
}
For another example of the BCX_SET_LABEL_COLOR function see FontDemo.bas.