Hi and good morning!
I am not sure if I am wrong or not. But I Think it is not possible to change
the Gadget_BackColor of a ChrckBoxGadget by using
SetGadgetColor(#Gadget, FarbTyp, Farbe).
Is there any possibility for changeing the "BackColor" by API.
Martin
CheckBoxGadget BackColor
- netmaestro
- PureBasic Bullfrog
- Posts: 8425
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
-
- User
- Posts: 46
- Joined: Sat Jan 08, 2005 7:46 pm
- netmaestro
- PureBasic Bullfrog
- Posts: 8425
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
The checkbox gadget is actually a button control that has the BS_CHECKBOX style, so SetGadgetColor isn't going to work on it.
For the text it can be done by reacting To the WM_CTLCOLORSTATIC message For the control by SetBkMode_(wParam,#TRANSPARENT), SetTextColor_(wParam,<desired text color>), And returning a SolidBrush your desired background color. For the box I've never tried to do that, so I'm not sure but it can probably be managed somehow. I'll study on it for a bit and let you know if something occurs.
For the text it can be done by reacting To the WM_CTLCOLORSTATIC message For the control by SetBkMode_(wParam,#TRANSPARENT), SetTextColor_(wParam,<desired text color>), And returning a SolidBrush your desired background color. For the box I've never tried to do that, so I'm not sure but it can probably be managed somehow. I'll study on it for a bit and let you know if something occurs.
Code: Select all
Global GadgetFrg=#Black, GadgetBkg = CreateSolidBrush_(#Green)
Procedure WindowProc(hWnd, Msg, wParam, lParam)
result = #PB_ProcessPureBasicEvents
If Msg=#WM_CTLCOLORSTATIC
If GetDlgCtrlID_(lparam) = 1
SetBkMode_(wParam,#TRANSPARENT)
SetTextColor_(wParam,GadgetFrg)
result = GadgetBkg
EndIf
EndIf
ProcedureReturn result
EndProcedure
OpenWindow(0,0,0,260,160,"test",#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
SetWindowCallback(@WindowProc())
CreateGadgetList(WindowID(0))
CheckBoxGadget(1,10,20,245,20,"Checkbox gadget with a green background")
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
DeleteObject_(GadgetBkg)
BERESHEIT
- netmaestro
- PureBasic Bullfrog
- Posts: 8425
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
OK, got something. Here's an example of coloring all elements of the checkbox including background, text, box background and checkmark:
Code: Select all
;====================================================
; Program: CheckBox Colors Demo
; Author: netmaestro
; Date: November 29, 2006
;====================================================
Global GadgetBkg = CreateSolidBrush_(#Green)
Global BoxBkg = CreateSolidBrush_(#Yellow)
Global Checkcolor = #Blue
Global Textcolor = #Red
Global NullPen = CreatePen_(#PS_NULL, 0, 0)
Procedure GadgetProc(hwnd, msg, wparam, lparam)
Shared oldproc
result = CallWindowProc_(oldproc, hwnd, msg, wparam, lparam)
Select msg
Case #WM_PAINT, #WM_LBUTTONUP, #WM_LBUTTONDOWN
dc = GetDC_(hwnd)
SelectObject_(dc, BoxBkg)
SelectObject_(dc, NullPen)
Rectangle_(dc,2,5,12,15)
If GetGadgetState(GetDlgCtrlID_(hwnd))
Restore check
For i = 1 To 21
Read x
Read y
SetPixel_(dc,x+2,y+5, CheckColor)
Next
EndIf
ReleaseDC_(hwnd, dc);
EndSelect
ProcedureReturn result
EndProcedure
Procedure WindowProc(hWnd, Msg, wParam, lParam)
result = #PB_ProcessPureBasicEvents
If Msg=#WM_CTLCOLORSTATIC
If GetDlgCtrlID_(lparam) = 1
SetBkMode_(wParam,#TRANSPARENT)
SetTextColor_(wParam, Textcolor)
result = GadgetBkg
EndIf
EndIf
ProcedureReturn result
EndProcedure
OpenWindow(0,0,0,260,160,"test",#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
SetWindowCallback(@WindowProc())
CreateGadgetList(WindowID(0))
CheckBoxGadget(1,10,20,245,20,"Checkbox gadget with a green background")
oldproc = SetWindowLong_(GadgetID(1),#GWL_WNDPROC,@GadgetProc())
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
DeleteObject_(GadgetBkg)
DeleteObject_(BoxBkg)
DeleteObject_(NullPen)
DataSection
check:
Data.l 7,1,6,2,7,2,1,3,5,3,6,3,7,3,1,4,2,4,4,4,5,4,6,4,1,5,2,5,3,5,4,5,5,5,2,6,3,6,4,6,3,7
EndDataSection
Last edited by netmaestro on Wed Nov 29, 2006 10:48 am, edited 1 time in total.
BERESHEIT
-
- User
- Posts: 46
- Joined: Sat Jan 08, 2005 7:46 pm
- netmaestro
- PureBasic Bullfrog
- Posts: 8425
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
-
- Enthusiast
- Posts: 781
- Joined: Fri Apr 25, 2003 6:51 pm
- Location: NC, USA
- Contact:
Re: CheckBoxGadget BackColor
Neat idea.
But has anyone figured how to change the background color of the check box only when it has the focus (or is the active gadget)?
But has anyone figured how to change the background color of the check box only when it has the focus (or is the active gadget)?