Subclassing Windows Controls
Purpose: If you want a control to do something that is not already built in to the control, subclassing allows you to add that new functionality at runtime.
In the sample below, each label control is subclassed and reflects the WM_CTLCOLORSTATIC message to the subclassed windows procedure.
Subclassing involves tapping into the windows message stream for a custom control. Text labels, editboxes, listboxes, etc all have their own windows procedure. You usually don't need to concern yourself with these.
This demo creates a form with a black background and two BCX_LABELS that have their foreground and background colors changed.
Example:
GUI"test"GLOBALForm1ASCONTROLGLOBALLabel_1ASCONTROLGLOBALLabel_2ASCONTROLSUBFORMLOAD Form1=BCX_FORM("test",67,42,160,130)Label_1=BCX_LABEL("Label 1",Form1,100,5,10)Label_2=BCX_LABEL("Label 2",Form1,101,5,50)BCX_SET_FORM_COLOR(Form1,RGB(0,0,0))SubClassLabel1()SubClassLabel2()CENTER(Form1)SHOW(Form1)ENDSUBBEGINEVENTSIFCBMSG=WM_CTLCOLORSTATICTHENFUNCTION=SendMessage((HWND)lParam, Msg, wParam, lParam)ENDIFENDEVENTSSUBSubClassLabel1GLOBALOriginal_Label_1_WndProcASWNDPROC Original_Label_1_WndProc=SetWindowLong(Label_1,GWL_WNDPROC,Label_1_WndProc)ENDSUBSUBSubClassLabel2GLOBALOriginal_Label_2_WndProcASWNDPROC Original_Label_2_WndProc=SetWindowLong(Label_2,GWL_WNDPROC,Label_2_WndProc)ENDSUBCALLBACKFUNCTIONLabel_1_WndProc()IFCBMSG=WM_CTLCOLORSTATICTHENFUNCTION=SetColor(RGB(0,225,0),RGB(0,0,0),wParam,lParam)ENDIFFUNCTION=CallWindowProc(Original_Label_1_WndProc,hWnd,Msg,wParam,lParam)ENDFUNCTIONCALLBACKFUNCTIONLabel_2_WndProc()IFCBMSG=WM_CTLCOLORSTATICTHENFUNCTION=SetColor(RGB(255,0,0),RGB(0,0,0),wParam,lParam)ENDIFFUNCTION=CallWindowProc(Original_Label_2_WndProc,hWnd,Msg,wParam,lParam)ENDFUNCTIONFUNCTIONSetColor(TxtColr, BkColr, wParam, lParam)ASLRESULTGLOBALReUsableBrushASHBRUSH DeleteObject(ReUsableBrush)ReUsableBrush=CreateSolidBrush(BkColr)SetTextColor((HDC)wParam, TxtColr)SetBkColor((HDC)wParam, BkColr)FUNCTION=(LRESULT)ReUsableBrushENDFUNCTION