Jump to content

Recommended Posts

Posted (edited)

Hello everyone,

I started working on this calendar control for my company. It's still a work in progress, and there are some bugs and some features missing, but I still wanted to share it with you guys, to get some comments and ideas for future development.

My question would be: "Would you have done it this way?", meaning, would you have built it with labels as I did, or would it be better using GDI+ or other methods?

Screenshot:

post-66935-0-59860100-1354694498_thumb.j

Here is an example (Try double-clicking on a date):

#include <GUIConstantsEx.au3>

#include "_CalendarUDF.au3"
Opt("GUIOnEventMode", 1)


Global $GUI, $fStartMonday = False, $iGridSize = 1, $sTheme = "Blue"

_Main()

Func _Main()
    Local $GUI = GUICreate("Calendar example", 800, 600, -1, -1, BitOR($WS_SYSMENU, $WS_SIZEBOX))
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    GUISetState()

    GUICtrlCreateButton("Toggle grid", 20, 10, 150, 20)
    GUICtrlSetOnEvent(-1, "Btn_ToggleGrid")
    GUICtrlCreateButton("Toggle Start Mon/Sun", 170, 10, 150, 20)
    GUICtrlSetOnEvent(-1, "Btn_ToggleMondaySunday")
    GUICtrlCreateButton("Go to Date", 320, 10, 150, 20)
    GUICtrlSetOnEvent(-1, "Btn_GoToDate")
    GUICtrlCreateButton("Add Event", 470, 10, 150, 20)
    GUICtrlSetOnEvent(-1, "Btn_AddEvent")
    GUICtrlCreateButton("Switch theme", 620, 10, 150, 20)
    GUICtrlSetOnEvent(-1, "Btn_SwitchTheme")

    ;Create the calendar control:
    _GuiCtrlCal_Create("My Calendar", 20, 40, 760, 520, @MON, @YEAR, 30, $fStartMonday, $iGridSize)

    ;Register my function, called when I double click a date:
    _GuiCtrlCal_OnDateDblClickRegister("_MyFunction")

    ;Add some Events:
    _GuiCtrlCal_EventAdd("2012/12/01", "World AIDS Day")
    _GuiCtrlCal_EventAdd("2012/12/25", "Christmas")
    _GuiCtrlCal_EventAdd("2012/12/21", "Winter Solstice")
    _GuiCtrlCal_EventAdd("2012/12/10", "Human Rights day")
    _GuiCtrlCal_EventAdd("2012/12/31", "Happy new year")
    _GuiCtrlCal_EventAdd("2013/01/11", "Human Trafficking Awareness")
    _GuiCtrlCal_EventAdd("2013/01/26", "Australia Day")

    ;Loop:
    While 1
        Sleep(50)
    WEnd

EndFunc


;This function will now be called when I doubleclick on a date.
;This function has to have one parameter that will contain
;the selected date:
Func _MyFunction($sDate)
    ;The selected date is $sDate
    ConsoleWrite("Selected date is: " & $sDate & @CRLF)

    ;Create a small gui to input a text for the event:
    Local $mousePos = MouseGetPos()
    Local $GUIAddEvent = GUICreate("Add Event", 250, 50, $mousePos[0] - 125, $mousePos[1] - 15, $WS_POPUP, $WS_EX_TOPMOST, $GUI)
    GUISetState(@SW_SHOW, $GUIAddEvent)
    Local $Info = GUICtrlCreateLabel("Enter a text and press enter to add the event", 0, 0, 250, 15)
    Local $GUIAddEvent_Input = GUICtrlCreateInput("", 0, 15, 250, 35)
    GUICtrlSetState($GUIAddEvent_Input, $GUI_FOCUS)

    ;Wait for the user to press enter:
    While 1
        If _IsPressed("0D") Then
            Do
                Sleep(10)
            Until Not _IsPressed("0D")
            ExitLoop
        EndIf
        Sleep(50)
    WEnd

    ;Read the text:
    Local $sText = GUICtrlRead($GUIAddEvent_Input)
    If $sText = "" Then Return
    GUIDelete($GUIAddEvent)

    ;Add the event:
    _GuiCtrlCal_EventAdd($sDate, $sText)

EndFunc

Func _Exit()
    _GuiCtrlCal_Destroy()
    Exit
EndFunc

Func Btn_ToggleGrid()
    If $iGridSize = 0 Then
        $iGridSize = 1
    Else
        $iGridSize = 0
    EndIf
    _GuiCtrlCal_SetGridSize($iGridSize)
    _GuiCtrlCal_Refresh()
EndFunc

Func Btn_ToggleMondaySunday()
    $fStartMonday = Not $fStartMonday
    _GuiCtrlCal_SetStartMonday($fStartMonday)
    _GuiCtrlCal_Refresh()
EndFunc

Func Btn_GoToDate()
    Local $sDate = InputBox("Go to Date", "Input the year, month and day : YYYY/MM/DD", @YEAR & "/" & @MON & "/" & @MDAY)
    If $sDate <> "" Then
        Local $aDate = StringSplit($sDate, "/")
        If Not @error Then
            _GuiCtrlCal_GoToMonth($aDate[1], $aDate[2])
            _GuiCtrlCal_SetSelectedDate($sDate)
        EndIf
    EndIf
EndFunc

Func Btn_AddEvent()
    Local $sDateEvent = InputBox("Event Date", "Input the year, month and day (YYYY/MM/DD) for your event", @YEAR & "/" & @MON & "/" & @MDAY)
    If $sDateEvent = "" Then Return
    Local $sText = InputBox("Event Text", "Input the Text for your event", "My Event")
    If $sText = "" Then Return
    _GuiCtrlCal_EventAdd($sDateEvent, $sText)
EndFunc

Func Btn_SwitchTheme()
    Switch $sTheme
        Case "Blue"
            $sTheme = "Dark"
            _GuiCtrlCal_SetThemeDark()
        Case "Dark"
            $sTheme = "Blue"
            _GuiCtrlCal_SetThemeBlue()
    EndSwitch
EndFunc

And here is the UDF:

_CalendarUDF.au3

Edited by jmon
Posted

Nice! And a few bugs, but useful.

I had to use

_GuiCtrlCal_EventAdd("2013/01/11", "Human Trafficking Awareness")

instead of

_GuiCtrlCal_EventAdd("2013/1/11", "Human Trafficking Awareness")

;)

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Posted (edited)

  On 12/5/2012 at 8:17 AM, 'funkey said:

Nice! And a few bugs, but useful.

I had to use

_GuiCtrlCal_EventAdd("2013/01/11", "Human Trafficking Awareness")

instead of

_GuiCtrlCal_EventAdd("2013/1/11", "Human Trafficking Awareness")

;)

Thanks, I fixed the first post.

[edit] Actually this is one of the issues I'm working on, I want to be more flexible on the date, and "2013/01/11" would be equal to "2013/1/11"

Edited by jmon
  • 2 years later...
Posted

i tried using this but i get the following erro just on loading up 
 

(657) : ==> Unknown function name.:
$__aCALDAYS[$i][0] = GUICtrlCreateLabel("", $iDayPosX + _Iif($iDayOfWeek = 7, 0, $iGridSize), $iDayPosY + $iGridSize, $iDayWidth - $iGridSize, $iDayHeight - $iGridSize)
$__aCALDAYS[$i][0] = GUICtrlCreateLabel("", $iDayPosX + ^ ERROR
  • Moderators
Posted

dynamitemedia,

The _Iif function no longer exists - you need to replace it with a ternary expression. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

Awesome UDF.

mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • 5 months later...
  • 3 months later...
Posted

On line 657 in the UDF you need to change to the following in what is now autoit version 3.3.14.2:

 

$__aCALDAYS[$i][0] = GUICtrlCreateLabel("", $iDayPosX + ($iDayOfWeek = 7 ? 0 : $iGridSize), $iDayPosY + $iGridSize, $iDayWidth - $iGridSize, $iDayHeight - $iGridSize)

 

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

  • 1 year later...
  • 1 year later...
Posted
  On 4/12/2017 at 2:03 AM, RangaNathan said:

could you post latest calendar UDF, if have any?

Expand  

 

_CalendarUDF.zip

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

 

  On 10/31/2018 at 4:55 PM, Stan099 said:

Now being both a newbie and French

Expand  

I'm Polish. Does it change anything ?

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

As @dmob said:

change 
 

_DateDayOfWeek($i)

to:
 

_DateDayOfWeek($i, $DMW_LOCALE_LONGNAME)

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Thanks to you both dmob and mLipok :)

@ mLipok : I do apologize if I hurted your feeling with my statement about being French, it was just to explain why I needed French days name.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...