How do you change the background colour of the Option Box. I could not find out how this can be done. If any one can help me on this.
Thanks
Option Box Color change
Re: Option Box Color change
for CheckBox is below code, maybe can be change to OptionBox:
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
- Arctic Fox
- Enthusiast
- Posts: 609
- Joined: Sun Dec 21, 2008 5:02 pm
- Location: Aarhus, Denmark
Re: Option Box Color change
+18 wrote:for CheckBox is below code, maybe can be change to OptionBox:
Code: Select all
;====================================================
; Program: CheckBox Colors Demo
; Author: netmaestro
; Date: November 29, 2006
;====================================================
Global GadgetBkg = CreateSolidBrush_(#Green)
Global BoxBkg = CreateSolidBrush_(#Yellow)
Global CheckBkg = CreateSolidBrush_(#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)
Ellipse_(dc,2,5,12,15)
If GetGadgetState(GetDlgCtrlID_(hwnd))
SelectObject_(dc, CheckBkg)
Ellipse_(dc,2,6,11,15)
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))
OptionGadget(1,10,20,245,20,"OptionGadget with a green background")
oldproc = SetWindowLong_(GadgetID(1),#GWL_WNDPROC,@GadgetProc())
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
DeleteObject_(GadgetBkg)
DeleteObject_(BoxBkg)
DeleteObject_(CheckBkg)
DeleteObject_(NullPen)
Re: Option Box Color change
Wow
Thanks Arctic Fox, i think maybe need to some improvement

Thanks Arctic Fox, i think maybe need to some improvement
- Arctic Fox
- Enthusiast
- Posts: 609
- Joined: Sun Dec 21, 2008 5:02 pm
- Location: Aarhus, Denmark
Re: Option Box Color change
Yeah, probably
- it is just a quick modification 


Re: Option Box Color change
Just to make things simpler...
Thanks go to NetMaestro for pointing out that Windows API call and its usage
Code: Select all
EnableExplicit
Global gadgetBkg
Procedure WindowProc(hWnd, msg, wParam, lParam)
If msg=#WM_CTLCOLORSTATIC
Select GetDlgCtrlID_(lParam) ;; sweet API call: allows choosing gadgets by their number
Case 1 To 3, 5
; uncomment those 2 if compiling WITHOUT XP support
; SetBkMode_(wParam,#TRANSPARENT)
; SetTextColor_(wParam, #Red)
ProcedureReturn gadgetBkg
EndSelect
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
#winType = #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered
If 0 = OpenWindow(0,0,0,260,160,"test",#winType)
End
EndIf
gadgetBkg = CreateSolidBrush_(#Green)
SetWindowCallback(@WindowProc())
Define gW = 150
Define gY = 8
OptionGadget(1,10,gY,gW,20,"gadget 1 is green")
gY + 25
OptionGadget(2,10,gY,gW,20,"gadget 2 is green")
gY + 25
OptionGadget(3,10,gY,gW,20,"gadget 3 is green")
gY + 25
CheckBoxGadget(4,10,gY,gW,20,"gadget 4... NOT green")
gY + 25
CheckBoxGadget(5,10,gY,gW,20,"gadget 5 is green")
Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow
DeleteObject_(gadgetBkg)
PB Forums : Proof positive that 2 heads (or more...) are better than one 
