calendargadget version 0.000001

Share your advanced PureBasic knowledge/code with the community.
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

calendargadget version 0.000001

Post by localmotion34 »

Code updated for 5.20+ (same as CalendarGadget())

here is my inital attempt now at a calendargadget. other programming languages have them, and i am trying to make one here. its not a date time picker, but an actual calendar type object. try out the code and see how you like it.

Code: Select all

; PureBasic Visual Designer v3.82 build 1344

Global buttonpushed,GadgetID
;- Window Constants
Enumeration
  #Window_0
EndEnumeration
Global Dim calendargadgetbuttons(12)
Global Dim calendargadgetbuttons1(12)

Procedure myCalendarGadget(calendarnumber,calx,caly,width,height,month$)
  number=37*calendarnumber
  calendargadgetbuttons(calendarnumber)=number+2
  calendargadgetbuttons1(calendarnumber)=number+36
  FrameGadget(number, calx, caly, 160, 160, "")
  TextGadget(number+1, calx+10, caly+20,140, 20, Month$, #PB_Text_Center | #PB_Text_Border)
  ButtonGadget(number+2, calx+10, caly+50, 20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+3, calx+30, caly+50,  20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+4, calx+50, caly+50,  20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+5, calx+70, caly+50,  20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+6, calx+90, caly+50, 20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+7, calx+110, caly+50, 20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+8, calx+130, caly+50,  20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+9, calx+10, caly+70, 20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+10, calx+30, caly+70,  20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+11, calx+50, caly+70,  20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+12, calx+70, caly+70,  20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+13, calx+90, caly+70, 20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+14, calx+110, caly+70, 20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+15, calx+130, caly+70,  20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+16, calx+10, caly+90, 20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+17, calx+30, caly+90,  20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+18, calx+50, caly+90,  20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+19, calx+70, caly+90,  20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+20, calx+90, caly+90, 20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+21, calx+110, caly+90, 20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+22, calx+130, caly+90,  20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+23, calx+10, caly+110, 20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+24, calx+30, caly+110,  20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+25, calx+50, caly+110,  20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+26, calx+70, caly+110,  20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+27, calx+90, caly+110, 20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+28, calx+110, caly+110, 20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+29, calx+130, caly+110,  20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+30, calx+10, caly+130, 20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+31, calx+30, caly+130,  20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+32, calx+50, caly+130,  20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+33, calx+70, caly+130,  20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+34, calx+90, caly+130, 20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+35, calx+110, caly+130, 20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  ButtonGadget(number+36, calx+130, caly+130,  20,20, "", #PB_Button_Default | #PB_Button_Toggle)
EndProcedure 

Procedure ActivateCalendarGadget(NumberCalendargadget)
  buttonpushed=GadgetID 
  For a=NumberCalendargadget*37+2 To buttonpushed-1
    If GetGadgetState(a)=#True
      SetGadgetState(a,#False)
    Else
      Continue
    EndIf 
  Next 
  For a=buttonpushed+1 To NumberCalendargadget*37+36
    If GetGadgetState(a)=#True
      SetGadgetState(a,#False)
    Else
      Continue
    EndIf 
  Next 
EndProcedure

Procedure Open_Window_0()
  If OpenWindow(#Window_0, 0, 0, 400, 300, "CalendarGadget version 0.000001",  
                #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    myCalendarGadget(0,30,60,160,160,"January")
    myCalendarGadget(1,210,60,160,160,"February")
  EndIf
EndProcedure

Open_Window_0()
Repeat
  Event = WaitWindowEvent()
  If Event = #PB_Event_Gadget
    GadgetID = EventGadget()
    buttonpushed=GadgetID
    If GadgetID >= calendargadgetbuttons(0) And GadgetID<=calendargadgetbuttons1(0)
      ActivateCalendarGadget(0)
      For a=calendargadgetbuttons(1) To calendargadgetbuttons1(1)
        SetGadgetState(a,#False)
      Next 
    ElseIf GadgetID >= calendargadgetbuttons(1) And GadgetID<=calendargadgetbuttons1(1)
      ActivateCalendarGadget(1)
      For a=calendargadgetbuttons(0) To calendargadgetbuttons1(0)
        SetGadgetState(a,#False)
      Next 
    EndIf
  EndIf
Until Event = #PB_Event_CloseWindow
any suggestion or comments are welcome.

Regards,

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: calendargadget version 0.000001

Post by PB »

> here is my inital attempt now at a calendargadget

No need to re-invent the wheel:
viewtopic.php?t=4475
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

Or:

Code: Select all

CommonControl.INIT_COMMON_CONTROLSEX
CommonControl\dwSize = SizeOf(INIT_COMMON_CONTROLSEX)
CommonControl\dwICC = #ICC_DATE_CLASSES
InitCommonControlsEx_(@CommonControl)
OpenWindow(1, 0, 0, 200, 200, #PB_Window_ScreenCentered | #PB_Window_SystemMenu, "")
hGadget.l = CreateWindowEx_(0, "SysMonthCal32", "", #WS_CHILD | #WS_VISIBLE | #WS_BORDER, 0, 0, 200, 200, WindowID(1), 0, GetModuleHandle_(#NULL), 0)
Repeat
Until WaitWindowEvent() = #PB_EventCloseWindow
Edit: damn, PB got there first! :)
--Kale

Image
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

:lol:
User avatar
Inner
PureBasic Expert
PureBasic Expert
Posts: 714
Joined: Fri Apr 25, 2003 4:47 pm
Location: New Zealand

Post by Inner »

Code: Select all

; This chunk of code isn't needed.

;CommonControl.INIT_COMMON_CONTROLSEX 
;CommonControl\dwSize = SizeOf(INIT_COMMON_CONTROLSEX) 
;CommonControl\dwICC = #ICC_DATE_CLASSES 
;InitCommonControlsEx_(@CommonControl) 

;---^

OpenWindow(1, 0, 0, 200, 200, #PB_Window_ScreenCentered | #PB_Window_SystemMenu, "") 
hGadget.l = CreateWindowEx_(0, "SysMonthCal32", "", #WS_CHILD | #WS_VISIBLE | #WS_BORDER, 0, 0, 200, 200, WindowID(1), 0, GetModuleHandle_(#NULL), 0) 
Repeat 
Until WaitWindowEvent() = #PB_EventCloseWindow 

PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> This chunk of code isn't needed.

Yes it is -- it won't run on Win 98 or 2000 without it, as you'll see if you
look at my link (above). I just re-tested it to make sure and it doesn't
work on W2K with the chunk removed.
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

Post by localmotion34 »

i didnt reinvent the wheel, i have Delphi 7 and it has a gridlike boxlike generic calendar. it allows you to manually set what month you want, and provides generated events for each click of each date box. thats what i am trying to emulate here, not using the API, and creating it straight from PB gadgets. i like the control delphi has apart from the month/calandar-and datepick. i just tried to make a calendar control like delphi has with all the same properties. some people might not want to use the datepick or syscalendar, and this may provide a better more flexible and customizeable option.

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> i just tried to make a calendar control like delphi has with all the same properties

Ah, I understand... I thought you weren't aware of the API versions, and
I was just trying to save you some typing, that's all. :)
User avatar
Inner
PureBasic Expert
PureBasic Expert
Posts: 714
Joined: Fri Apr 25, 2003 4:47 pm
Location: New Zealand

Post by Inner »

Umm, okay.. well that chunk of code isn't needed under "Windows XP" I didn't think people still lived the dark ages anymore :p
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> that chunk of code isn't needed under "Windows XP"

I just tested and it doesn't work on Win XP Pro... I don't have any Service
Packs on XP, though, which could be the reason. But on a clean XP Pro
it definitely doesn't work without the chunk...

> I didn't think people still lived the dark ages anymore :p

The latest ain't always the greatest. ;)
User avatar
Inner
PureBasic Expert
PureBasic Expert
Posts: 714
Joined: Fri Apr 25, 2003 4:47 pm
Location: New Zealand

Post by Inner »

oook. well it's not needed, under "my" windows xp - sp1, althought you'd think wouldn't you that this "chunk" should be there over all operating systems, but then this is after all "MICROSOFT"
techjunkie
Addict
Addict
Posts: 1126
Joined: Wed Oct 15, 2003 12:40 am
Location: Sweden
Contact:

Re: calendargadget version 0.000001

Post by techjunkie »

localmotion34 wrote:any suggestion or comments are welcome.
Well, you could simplify the Gadget creation... but that's a matter of taste I guess... :-)

Code: Select all

calcx_num = 10
calcy_num = 50
For i = 2 To 36
  ButtonGadget(number+i, calx+calcx_num, caly+calcy_num, 20,20, "", #PB_Button_Default | #PB_Button_Toggle)
  calcx_num + 20
  If calcx_num > 130
    calcx_num = 10
    calcy_num + 20
  EndIf
Next
Image
(\__/)
(='.'=) This is Bunny. Copy and paste Bunny into your
(")_(") signature to help him gain world domination.
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

i didnt reinvent the wheel, i have Delphi 7 and it has a gridlike boxlike generic calendar. it allows you to manually set what month you want, and provides generated events for each click of each date box.
The WinAPI version coded above has an interface to handle events and such.
--Kale

Image
Jon
User
User
Posts: 20
Joined: Sat Apr 26, 2003 9:12 am
Location: New Zealand
Contact:

Post by Jon »

The WinAPI version coded above has an interface to handle events and such
Perhaps some pointers on how to use the interface ?
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> Perhaps some pointers on how to use the interface ?

For examples, see the bottom of this URL:
viewtopic.php?t=4475
Post Reply