Option Gadget - Checkbox Gadget (Windows)

Share your advanced PureBasic knowledge/code with the community.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Option Gadget - Checkbox Gadget (Windows)

Post by RASHAD »

- Any degree of Opacity
- Can be Transparent
- With or Without Frame
And many more ........

Code: Select all

Global Checkf,Checkf2

Procedure ButtonFace(Fimg,Simg,Text$,Txcolor,Brcolor,Opac)          ;Opac = 1 to 255 (255 = Transparent)
  CreateImage(Fimg,140,20)                                           ;If Brcolor < 0 No Border Color
    StartDrawing(ImageOutput(Fimg))
      Box(0,0,140,20,$F6F6F6)
      DrawAlphaImage(ImageID(Simg),0,0,Opac)
      If Brcolor > 0
        DrawingMode(#PB_2DDrawing_Outlined)
        Box(0,0,140,20,Brcolor)
      EndIf
      DrawingMode(#PB_2DDrawing_Transparent)
      DrawText(26, 1,Text$,Txcolor)
    StopDrawing()
  FreeImage(Simg)
EndProcedure

CreateImage(0, 250, 350)
StartDrawing(ImageOutput(0))
  For x = 0 To 249
    For y = 0 To 349
      Plot(x,y, RGB(x,y,x*y))
    Next
  Next
StopDrawing()

hBrush = CreatePatternBrush_(ImageID(0))
hwnd=OpenWindow(0,0,0,250,350,"Test",#PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar|#PB_Window_ScreenCentered)
SetClassLongPtr_(WindowID(0), #GCL_HBRBACKGROUND, hBrush)
InvalidateRect_(WindowID(0), 0, 1)

OptionGadget(1,12,13,14,14,"")
OptionGadget(2,12,38,14,14,"")
OptionGadget(3,12,63,14,14,"")

GrabImage(0, 1, 10, 10, 140,20)
ButtonFace(2,1,"Option 1",$FFFFFF,-1,150)
ImageGadget(4, 10, 10,140,20,ImageID(2))
SetWindowLongPtr_(GadgetID(4), #GWL_STYLE,GetWindowLongPtr_(GadgetID(4), #GWL_STYLE) |#WS_CLIPSIBLINGS)

GrabImage(0, 1, 10, 35, 140,20)
ButtonFace(3,1,"Option 2",$FFFFFF,-1,220)
ImageGadget(5, 10, 35,140,20,ImageID(3))
SetWindowLongPtr_(GadgetID(5), #GWL_STYLE,GetWindowLongPtr_(GadgetID(5), #GWL_STYLE) |#WS_CLIPSIBLINGS)

GrabImage(0, 1, 10, 60, 140,20)
ButtonFace(4,1,"Option 3",$FFFFFF,-1,255)
ImageGadget(6, 10, 60,140,20,ImageID(4))
SetWindowLongPtr_(GadgetID(6), #GWL_STYLE,GetWindowLongPtr_(GadgetID(6), #GWL_STYLE) |#WS_CLIPSIBLINGS)

GrabImage(0, 1, 10, 290, 140,20)
ButtonFace(5,1,"Check Box 1",$FFFFFF,$0002FF,180)
CheckBoxGadget(7, 12, 292,15,15,"",#WS_CLIPSIBLINGS)
ImageGadget(8, 10, 290,140,20,ImageID(5))
SetWindowLongPtr_(GadgetID(8), #GWL_STYLE,GetWindowLongPtr_(GadgetID(8), #GWL_STYLE) |#WS_CLIPSIBLINGS)

GrabImage(0, 1, 10, 320, 140,20)
ButtonFace(6,1,"Check Box 2",$FFFFFF,-1,255)
CheckBoxGadget(9, 12, 322,15,15,"",#WS_CLIPSIBLINGS)
ImageGadget(10, 10, 320,140,20,ImageID(6))
SetWindowLongPtr_(GadgetID(10), #GWL_STYLE,GetWindowLongPtr_(GadgetID(10), #GWL_STYLE) |#WS_CLIPSIBLINGS)

Repeat 
  
  Select WaitWindowEvent() 
  
   Case #PB_Event_Gadget
    Select EventGadget()        
     Case 4
        SetGadgetState(1, 1)
        
     Case 5
        SetGadgetState(2, 1)
        
     Case 6
        SetGadgetState(3, 1)
        
     Case 7,8
       Checkf = Checkf ! 1
        If Checkf = 1
          SetGadgetState(7,#PB_Checkbox_Checked)
        Else
          SetGadgetState(7,#PB_Checkbox_Unchecked)
        EndIf
        
     Case 9,10
       Checkf2 = Checkf2 ! 1
        If Checkf2 = 1
          SetGadgetState(9,#PB_Checkbox_Checked)
        Else
          SetGadgetState(9,#PB_Checkbox_Unchecked)
        EndIf
            
    EndSelect    
    

   Case #PB_Event_CloseWindow
       Quit = 1
     
 EndSelect
  
Until Quit = 1

Egypt my love
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: Option Gadget - Checkbox Gadget (Windows)

Post by RASHAD »

More to go

Code: Select all

Global Checkf,Checkf2

Procedure ButtonFace(Fimg,Simg,Text$,Txcolor,Brcolor,Opac)          ;Opac = 1 to 255 (255 = Transparent)
  CreateImage(Fimg,140,20)                                           ;If Brcolor < 0 No Border Color
    StartDrawing(ImageOutput(Fimg))
      Box(0,0,140,20,$F6F6F6)
      DrawAlphaImage(ImageID(Simg),0,0,Opac)
      
      DrawingMode(#PB_2DDrawing_Outlined)
      If Brcolor > 0
        Box(0,0,140,20,Brcolor)        
      EndIf
      Box(2,2,16,16,Brcolor)
      Box(3,3,14,14,Brcolor)
      
      DrawingMode(#PB_2DDrawing_Transparent)
      DrawText(26, 1,Text$,Txcolor)
    StopDrawing()
  FreeImage(Simg)
EndProcedure

CreateImage(0, 250, 350)
StartDrawing(ImageOutput(0))
  For x = 0 To 249
    For y = 0 To 349
      Plot(x, y, RGB(x, y, x*y/15))
    Next
  Next
StopDrawing()

hBrush = CreatePatternBrush_(ImageID(0))
hwnd=OpenWindow(0,0,0,250,350,"Test",#PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar|#PB_Window_ScreenCentered) 
SetClassLongPtr_(WindowID(0), #GCL_HBRBACKGROUND, hBrush)
InvalidateRect_(WindowID(0), 0, 1)

GrabImage(0, 1, 10, 295, 140,20)
ButtonFace(2,1,"Check Box 1",$FFFFFF,-1,255)
ImageGadget(1, 10, 295,140,20,ImageID(2))

GrabImage(0, 1, 10, 320, 140,20)
ButtonFace(3,1,"Check Box 2",$FFFFFF,-1,255)
ImageGadget(2, 10, 320,140,20,ImageID(3))

Repeat 
  
  Select WaitWindowEvent() 
  
   Case #PB_Event_Gadget
    Select EventGadget()
     Case 1
      Checkf = Checkf ! 1
        If Checkf = 1
            GrabImage(2, 1, 0, 0, 140,20)
            StartDrawing(ImageOutput(1))      
              DrawingMode(#PB_2DDrawing_Transparent)
              DrawText(6,1,"x",#White)
            StopDrawing()
            SetGadgetState(1,ImageID(1))
            Debug "Gadget 1 Checked"
        Else
            SetGadgetState(1,ImageID(2))
            Debug "Gadget 1 UnChecked"
        EndIf
        
     Case 2
      Checkf2 = Checkf2 ! 1
        If Checkf2 = 1
            GrabImage(3, 1, 0, 0, 140,20)
            StartDrawing(ImageOutput(1))      
              DrawingMode(#PB_2DDrawing_Transparent)
              DrawText(6,1,"x",#White)
            StopDrawing()
            SetGadgetState(2,ImageID(1))
            Debug "Gadget 2 Checked"
        Else
            SetGadgetState(2,ImageID(3))
            Debug "Gadget 2 UnChecked"
        EndIf
     
     
   EndSelect


   Case #PB_Event_CloseWindow
       Quit = 1
     
 EndSelect
  
Until Quit = 1

Egypt my love
User avatar
Tomi
Enthusiast
Enthusiast
Posts: 270
Joined: Wed Sep 03, 2008 9:29 am

Re: Option Gadget - Checkbox Gadget (Windows)

Post by Tomi »

very cute and useful :D
Thanks rashad for sharing your code whit us :D
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Option Gadget - Checkbox Gadget (Windows)

Post by Kwai chang caine »

Thanks RASHAD
Very nice 8)
ImageThe happiness is a road...
Not a destination
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: Option Gadget - Checkbox Gadget (Windows)

Post by rsts »

Don't know how I missed this when it was posted.

Nice code. Thanks for sharing.

cheers
Post Reply