400 Year Calendar

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by wayne1.

Code: Select all

 
;requires DateAndTime and StringLibraryEx Libraries 
;Download from [url]http://www.reelmediaproductions.com/pb[/url]

;will load current calendar date on start up then you may select any date to view
;a much nicer color calender with a better layout could be made and put in a function
;to draw on any window or whatever if you have time

;(replace the extra spaces at TextGadget(#TXT_WEEK_DAYS.... if they are lost at copy & paste )


If OpenWindow(0, 100, 100, 205, 260, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget , "Multi-Year Calendar")
       
    #CBO_MONTH=1:#CBO_YEAR=3:#TXT_STATIC_MONTH=4:#TXT_STATIC_YEAR=6:#CMD_UPDATE_CALENDER=7:
    #TXT_CALENDAR=8:#TXT_WEEK_DAYS=9:#TXT_CALENDAR_MONTH=10:#FRA_CALENDAR=11:#FRA_MONTH=12
    
    If CreateMenu(0)
      MenuTitle("Help")
      MenuItem( 1, "&About...")
    EndIf
     
    AttachMenu(0, WindowID())
    InitGadget(18)
    CreateGadgetList(WindowID())
    ComboBoxGadget(#CBO_MONTH, 57, 5, 40, 2000) 
    ComboBoxGadget(#CBO_YEAR, 97, 5, 60, 200) 
    TextGadget(#TXT_STATIC_MONTH, 58, 30, 30, 20, "Month")
    TextGadget(#TXT_STATIC_YEAR, 108, 30, 40, 15, "Year")
    ButtonGadget(#CMD_UPDATE_CALENDER, 58, 48, 90, 25, "Update Calender")
    TextGadget(#TXT_CALENDAR, 21, 125, 169, 80, "")
    TextGadget(#TXT_WEEK_DAYS, 27, 108, 180, 15, "S     M     T      W     T     F      S")
    TextGadget(#TXT_CALENDAR_MONTH, 58, 86, 90, 13, "")
    Frame3DGadget(#FRA_CALENDAR, 5, 72, 190, 137, "", 0)
    Frame3DGadget(#FRA_MONTH, 43, 77, 115, 25, "", 0) 
    GadgetToolTip(#CBO_MONTH, "Select Month")
    GadgetToolTip(#CBO_YEAR, "Select Year")
    GadgetToolTip(#CMD_UPDATE_CALENDER, "Create a new calendar") 
     
    For i=1 To 12
     AddGadgetItem(1, -1, Str(i));load months 
    Next
     
    For i=1800 To 2200
    AddGadgetItem(3, -1, Str(i));load years 
    Next

    Year$=Str(Year_());get current year
    Month$=Str(Month_());get current month
    SetGadgetText(#CBO_MONTH,Month$);set to current month  
    SetGadgetText(#CBO_YEAR,Year$);set to current year  

    Gosub CreateCalender ;create the calendar for current date
   
    Repeat
    
     EventID.l = WaitWindowEvent()
       
     If EventID = #PB_EventCloseWindow  
      Quit = 1
     EndIf
     
      If EventID =#PB_EventMenu
        Select EventMenuID()  
          Case 1
          j$=""
          MessageRequester("About Multi-Year Calendar", "Created by Wayne Haas " + Chr(169)+"2001", 0)
       EndSelect
      EndIf
      
        If EventID = #PB_EventGadget
         Select EventGadgetID()
          Case 7 
          Gosub CreateCalender 
         EndSelect
        EndIf
        
    Until Quit = 1
  
EndIf

End   
  
  
CreateCalender:
          m$= GetGadgetText(#CBO_MONTH)
          y$= GetGadgetText(#CBO_YEAR)
          SetGadgetText(#TXT_CALENDAR,"")
          Temp$=""
          HowMany=HowManyDays_(Val(m$),Val(y$))
          WeekDay=GetWeekDay_(Val(m$),1,Val(y$));set to the first day of the month (mon or tue...)
          j=1
          For i=1 To 7;set text for first week pad empty days
            If i 7;wrap line if one week
              Temp$=Temp$+Chr(10)
              k=1;reset count
             EndIf
              j=j+1
           Wend 
            SetGadgetText(#TXT_CALENDAR,Temp$);display calendar
            Heading$=MonthName$(Val(GetGadgetText(#CBO_MONTH)),0)+Space$(2)+GetGadgetText(#CBO_YEAR)
            SetGadgetText(#TXT_CALENDAR_MONTH,RSet$(Heading$,15));set month and year text for calendar
           
          Return





Edited by - wayne1 on 24 December 2001 07:37:29
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.

Great work Wayne!
Here is the thread version of your code. It works perfectly.
Also implemented: the colorized window for WinXP

Code: Select all

; Franco's thread version of Wayne's calendar
; Great job Wayne!
;
; requires DateAndTime and StringLibraryEx Libraries 
; Download from [url]http://www.reelmediaproductions.com/pb[/url]
;
; will load current calendar date on start up then you may select any date to view
; a much nicer color calender with a better layout could be made and put in a function
; to draw on any window or whatever if you have time
;
; (replace the extra spaces at TextGadget(#TXT_WEEK_DAYS.... if they are lost at copy & paste )


#CBO_MONTH=1:#CBO_YEAR=3:#TXT_STATIC_MONTH=4:#TXT_STATIC_YEAR=6
#TXT_CALENDAR=8:#TXT_WEEK_DAYS=9:#TXT_CALENDAR_MONTH=10:#FRA_CALENDAR=11:#FRA_MONTH=12
 
Procedure ColorizeWindow(Color) ;Adapt colors for WinXP
  Brush.LOGBRUSH\lbColor = GetSysColor_(Color)
  SetClassLong_(WindowID(),#GCL_HBRBACKGROUND,CreateBrushIndirect_(Brush))
  RedrawWindow_(WindowID(),0,0,7)
EndProcedure
  
Procedure CreateCalender(NotUsed)
  Repeat
    m$= GetGadgetText(#CBO_MONTH)
    y$= GetGadgetText(#CBO_YEAR)
    SetGadgetText(#TXT_CALENDAR,"")
    Temp$=""
    HowMany=HowManyDays_(Val(m$),Val(y$))
    WeekDay=GetWeekDay_(Val(m$),1,Val(y$));set to the first day of the month (mon or tue...)
    j=1
    For i=1 To 7;set text for first week pad empty days
      If i 7;wrap line if one week
        Temp$=Temp$+Chr(10)
        k=1;reset count
      EndIf
        j=j+1
    Wend 
    SetGadgetText(#TXT_CALENDAR,Temp$);display calendar
    Heading$=MonthName$(Val(GetGadgetText(#CBO_MONTH)),0)+Space$(2)+GetGadgetText(#CBO_YEAR)
    SetGadgetText(#TXT_CALENDAR_MONTH,RSet$(Heading$,15));set month and year text for calendar
    Delay(250) ; Adapt the time if you want...
  ForEver
EndProcedure
 
If OpenWindow(0, 100, 100, 205, 260, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget , "Multi-Year Calendar")
 
  ColorizeWindow(#COLOR_BTNFACE)
 
  If CreateMenu(0)
    MenuTitle("Help")
    MenuItem( 1, "&About...")
  EndIf
     
  AttachMenu(0, WindowID())
  InitGadget(18)
  CreateGadgetList(WindowID())
  ComboBoxGadget(#CBO_MONTH, 57, 25, 40, 2000) 
  ComboBoxGadget(#CBO_YEAR, 97, 25, 60, 200) 
  TextGadget(#TXT_STATIC_MONTH, 58, 50, 30, 20, "Month")
  TextGadget(#TXT_STATIC_YEAR, 108, 50, 40, 15, "Year")
  TextGadget(#TXT_CALENDAR, 21, 125, 169, 80, "")
  TextGadget(#TXT_WEEK_DAYS, 27, 108, 180, 15, "S     M     T      W     T     F      S")
  TextGadget(#TXT_CALENDAR_MONTH, 58, 86, 90, 13, "")
  Frame3DGadget(#FRA_CALENDAR, 5, 72, 190, 137, "", 0)
  Frame3DGadget(#FRA_MONTH, 43, 77, 115, 25, "", 0) 
  GadgetToolTip(#CBO_MONTH, "Select Month")
  GadgetToolTip(#CBO_YEAR, "Select Year")
     
  For i=1 To 12
    AddGadgetItem(1, -1, Str(i));load months 
  Next
     
  For i=1800 To 2200
    AddGadgetItem(3, -1, Str(i));load years 
  Next
 
  Year$=Str(Year_());get current year
  Month$=Str(Month_());get current month
  SetGadgetText(#CBO_MONTH,Month$);set to current month  
  SetGadgetText(#CBO_YEAR,Year$);set to current year  
   
  CreateThread(@CreateCalender(), NotUsed)
    
  Repeat
    
    EventID.l = WaitWindowEvent()
       
    If EventID = #PB_EventCloseWindow  
      Quit = 1
    EndIf
     
    If EventID =#PB_EventMenu
      Select EventMenuID()  
        Case 1
          j$=""
          MessageRequester("About Multi-Year Calendar", "Created by Wayne Haas " + Chr(169)+"2001", 0)
      EndSelect
    EndIf
      
  Until Quit = 1
 
EndIf
 
End   
 

Have a nice day...
Franco

Edited by - franco on 25 December 2001 20:27:53
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.
Here is the thread version of your code. It works perfectly.
WARNING ! The Thread procedure MUST have a a paramater (even if you don't car about it). Else it could have stack problem if you call the thread several time. To have really perfect code, just change your procedure declaration to:

Procedure CreateCalender(Parameter)

About the WinXP color problem, it will be fixed for the next version. Thanks to have found how do it (I've searched sometimes ago, but not tried the BTNFACE constant.. Grrrrrr).

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.

Thanks for the advice Fred.

Yesterday I added two buttons for MonthUp/MonthDown and it worked well.
But I also wanted to add some Mouse functions for a 'hotspot' and it didn't work.
Everytime I add:

InitMouse()

the PBCompiler can't compile. The error message is:
"Can't create the 'PureBasic.exe' file (already running?)"

and after hours spend I can't figure out what's wrong.
Can you check this, please?



Have a nice day...
Franco

PS. Forgot to mention that I'm working with WinXP.

Edited by - franco on 25 December 2001 20:25:51
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

Heya Franco !!

Thats a hard one... :wink:

You need to include InitSprite()
if you want to use InitMouse()
or InitKeyboard(), because this
functions use another function
in the SpriteLibrary.

If you dont use commands that are
in the Sprite-Lib, PB doesnt
include the Sprite-Lib for linking.
NASM generates a output file with
the Error message.

cya,
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.

Thanks Danilo,
well I didn't think that InitSprite() must be called before InitMouse().
(there are no sprites in this application...)
Anyway, I suppose that InitSprite()initializes DirectX in general and InitMouse() only the mouse functions.
The Mouse functions of PureBasic depend on DirectX so it would make sense.

But it would make more sense if InitSprite() would be renamed in InitDirectInterface() or something like that (InitDirectX() is not so good because of Linux. The SDL thingie is used for it...)



Have a nice day...
Franco
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Rings.

Franco wrote:
But it would make more sense if InitSprite() would be renamed in InitDirectInterface() or something like that (InitDirectX() is not so good because of Linux. The SDL thingie is used for it...)


Yes Franco, beware the compatibility of Pure WindowsLinux

Siggi
Post Reply