Post by Walt Decker on Nov 5, 2021 12:36:13 GMT -5
CTL_COLOR.DLL will set the color of listboxes, textboxes, and statictext to the text color and background color of your choice. It will also color your parent window to a color of your choice.
With buttons the border color is set to a color of your choice. The attached zip contains the below source code and CTL_COLOR.DLL.
!!! EDIT !!!
I have made a significant change in CTL_COLOR.DLL. It will now accommodate DIBsection memory bitmaps loaded by either LB's LOADBMP function or gdi32.dll function LoadImage().
Although the code below will still work, results may be unexpected. Therefore it is advisable to use the source code in the zip file below.
'
[CONTROL.COLORS]
DARKRED = HEXDEC("&H00008B")
LIGHTSALMON = HEXDEC("&H7AA0FF")
VIOLETRED = HEXDEC("&H8515C7")
LIGHTPINK = HEXDEC("&HC1B6FF")
LIGHTLEMON = HEXDEC("&HCDFAFF")
ORANGERED = HEXDEC("&H0045FF")
[STATIC.CONTROL.STYLES]
SS.CENTER = HEXDEC("&H00000001")
SS.CENTERIMAGE = HEXDEC("&H00000200")
DIM LbxAry$(1) '<--- listbox array
LbxAry$(0) = "[SWAP.COLORS]"
[DEFINE.STATIC.CONTROLS]
STYLEBITS #NEW.LBL1, SS.CENTER OR SS.CENTERIMAGE, 0, 0, 0
STYLEBITS #NEW.LBL2, SS.CENTER OR SS.CENTERIMAGE, 0, 0, 0
STATICTEXT #NEW.LBL1, "LBL 1", 5, 5, 50, 20
STATICTEXT #NEW.LBL2, "LBL 2", 5, 30, 50, 20
STYLEBITS #SHO.LBL1, SS.CENTER OR SS.CENTERIMAGE, 0, 0, 0
STYLEBITS #SHO.LBL2, SS.CENTER OR SS.CENTERIMAGE, 0, 0, 0
STATICTEXT #SHO.LBL1, "LBL 1", 5, 5, 50, 20
STATICTEXT #SHO.LBL2, "LBL 2", 5, 30, 50, 20
[DEFINE.EDIT.AND.LISTBOX]
TEXTBOX #SHO.TXB, 65, 5, 125, 20
LISTBOX #NEW.LBX, LbxAry$(), DMO.END, 60, 5, 125, 125
BUTTON #NEW.BTN, "QUIT", DONE, UL, 110, 135, 50, 25
[DEFINE.PARENT.WINDOWS]
UpperLeftX = 25
UpperLeftY = 100
OPEN "NEW WIN" FOR WINDOW AS #NEW
UpperLeftX = 00
UpperLeftY = 00
OPEN "LABELS" FOR WINDOW AS #SHO
[SET.PROPERTIES]
'####################################################
'
' SET PROPERTIES FOR CONTROLS ON WINDOW "LABELS"
' "TXTCLR": 32-bit Color of text; The string "TXTCLOR" is
' a property key. It can be anything you want,
' e. g. "FORCOLOR", "TXT".
' It can also be mix-cased and be expressed as a
' string, e. g. Prop1$ = "ForeColor".
'
' "BKGCLR": See above
'
'####################################################
LblHndl = HWND(#SHO.LBL1) '<--- static control handle
RetVal = FN.SetProp(LblHndl, "TXTCLR", "BKGCLR", DARKRED, LIGHTSALMON)
LblHndl = HWND(#SHO.LBL2) '<--- static control handle
RetVal = FN.SetProp(LblHndl, "TXTCLR", "BKGCLR", VIOLETRED, LIGHTPINK)
LblHndl = HWND(#SHO.TXB) '<--- edit control handle
RetVal = FN.SetProp(LblHndl, "TXTCLR", "BKGCLR", LIGTHSALMON, DARKRED)
'<--------------- SET PROPERTIES FOR WINDOW "NEW WIN" ----------->
LbxHndl = HWND(#NEW.LBX) '<--- listbox handle
RetVal = FN.SetProp(LbxHndl, "TXTCLR", "BKGCLR", ORANGERED, LIGHTLEMON)
LbxHndl = HWND(#NEW.BTN)
RetVal = FN.SetProp(LbxHndl, "TXTCLR", "BKGCLR", LIGTHSALMON, DARKRED)
'##################################################################
' INITIALIZE THE DLL
' "TXTCLR": The property key you defined for the text color of your
' controls.
'
' "BKGCLR": The property key you defined for the background color
' of your control
'
' WinColor: The color of the parent window. This value must be
' greater than zero.
'##################################################################
OPEN "CTL_COLOR" FOR DLL AS #CTL
WinHndl = HWND(#SHO)
CALLDLL #CTL, "FN_InitProperties", WinHndl AS ULONG, "TXTCLR" AS PTR, _
"BKGCLR" AS PTR, LIGHTLEMON AS ULONG, RetVal AS ULONG
NewHndl = HWND(#NEW)
CALLDLL #CTL, "FN_InitProperties", NewHndl AS ULONG, "TXTCLR" AS PTR, _
"BKGCLR" AS PTR, 0 AS ULONG, RetVal AS ULONG '<--- SUCCESS: Non-zero
PRINT #NEW, "TRAPCLOSE DMO.END"
PRINT #SHO, "TRAPCLOSE DMO.END"
[SET.TIMER]
TIMER 6000, [SWAP.COLORS]
WAIT
'----------------------------------------------------------
'----------------------------------------------------------
[SWAP.COLORS]
TIMER 0
RetVal = 0
'<--- change the colors of controls: see [SET.PROPERTIES] above ----------->
LblHndl = HWND(#SHO.LBL1)
RetVal = FN.SetProp(LblHndl, "TXTCLR", "BKGCLR", VIOLETRED, LIGHTPINK)
LblHndl = HWND(#SHO.LBL2)
RetVal = FN.SetProp(LblHndl, "TXTCLR", "BKGCLR", DARKRED, LIGHTSALMON)
'<----------- change the text ----------------------------->
PRINT #SHO.LBL2, "Ooops"
PRINT #SHO.LBL1, "DUH!"
WAIT
[SWAP.COLORS.END]
'----------------------------------------------------
'----------------------------------------------------
SUB DMO.END WinHndl$
RetVal = 0
WinHndl = HWND(#SHO)
CALLDLL #CTL, "FN_CLOSE", WinHndl AS ULONG, RetVal AS VOID
WinHndl = HWND(#NEW)
CALLDLL #CTL, "FN_CLOSE", WinHndl AS ULONG, RetVal AS VOID
WinHndl = HWND(#SHO.LBL1)
RetVal = FN.RemoveProp(WinHndl, "TXTCLR", "BKGCLR")
WinHndl = HWND(#SHO.LBL2)
RetVal = FN.RemoveProp(WinHndl, "TXTCLR", "BKGCLR")
WinHndl = HWND(#SHO.TXB)
RetVal = FN.RemoveProp(WinHndl, "TXTCLR", "BKGCLR")
WinHndl = HWND(#NEW.LBX)
RetVal = FN.RemoveProp(WinHndl, "TXTCLR", "BKGCLR")
CLOSE #SHO
CLOSE #NEW
CLOSE #CTL
END
END SUB
SUB DONE BtnHndl$
END SUB
'---------------------------------------------------------------
'---------------------------------------------------------------
FUNCTION FN.SetProp(WinHndl, TxtClr$, Bkg$, ForeColor, BackColor)
RetVal = 0
CALLDLL #user32, "SetPropA", WinHndl AS ULONG, TxtClr$ AS PTR, _
ForeColor AS ULONG, RetVal AS VOID
CALLDLL #user32, "SetPropA", WinHndl AS ULONG, Bkg$ AS PTR, _
BackColor AS ULONG, RetVal AS VOID
END FUNCTION
'---------------------------------------------------------------
'---------------------------------------------------------------
FUNCTION FN.RemoveProp(WinHndl, Prop1$, Prop2$)
RetVal = 0
CALLDLL #user32, "RemovePropA", WinHndl AS ULONG, Prop1$ AS PTR, _
RetVal AS VOID
CALLDLL #user32, "RemovePropA", WinHndl AS ULONG, Prop2$ AS PTR, _
RetVal AS VOID
END FUNCTION
'
CONTROL_COLOR.ZIP (18.27 KB)
EDIT: Sunday, 14 November 2021
The internal working of CTL_COLOR.DLL has changed.
Tasp: You can get the color value of buttonface with:
COLOR.BTNFACE = 15
CALLDLL #user32, "GetSysColor", 15 AS LONG, SysColor AS ULONG
CALLDLL #user32, "GetSysColor", 15 AS LONG, SysColor AS ULONG