Jump to content
Sign in to follow this  
arts

Using _GUICtrlMonthCal_SetDayState

Recommended Posts

arts

I'm trying to make bold some days of a calendar. I get those days from a SQLite database. Using the _GUICtrlMonthCal_SetDayState function I almost got it working. Please look at the following ugly code and help me to understand why when the variable $finalX is calculated by the script it doesn't work (no bolding days) but, if I declare the value of the same variable manually, it works... I'm sure I'm doing something stupid but can't see it.
 

[...]
;---- BUSY DAYS     
        if _SQLite_GetTable2d(-1,'select A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, ID from mydatabase where DEADLINE like "%' & "-" & $tTeste & "-" & '%" ORDER BY 1 D, C;', $arows, $irows, $icols) = $SQLITE_OK Then
            _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($lvList))
            Local $final[ubound($arows)]
            Local $finalX = ""
            Local $tempDay = ""
            Local $val_hex[ubound($arows)]
            Local $val_pre = ""
            for $1 = 1 to ubound($arows) - 1
                _GUICtrlListView_AddItem($lvList, $arows[$1][0])
                    for $2 = 1 to ubound($arows,2) - 1
                        _GUICtrlListView_AddsubItem($lvList,$1-1, $arows[$1][$2], $2) 
                    next
                $tempDay = StringLeft(($arows[$1][3]), 2)
                $val_pre = Number($tempDay); + 0
                ConsoleWrite("val_pre: " & $val_pre & @CRLF)
                $val_hex[$1] = "BitShift(0x0001,-" & "(" & $val_pre & "-1)" & ")"
                ConsoleWrite("val_hex[$1]: " & $val_hex[$1] & @CRLF)
            next
                ConsoleWrite("===========================" & @CRLF)
                $final = _ArrayUnique($val_hex)
                $finalX = _ArrayToString($final, " + ", 1)              
                $finalX = StringTrimLeft($finalX, 3); <<------ COMPUTED $finalX doesn't work
                ConsoleWrite("FinalX:"&$finalX & @CRLF)
                ;------>> When I declare the same value as the computed above, it WORKS.. --->> $finalX = BitShift(0x0001,-(28-1)) + BitShift(0x0001,-(29-1)) + BitShift(0x0001,-(30-1)) + BitShift(0x0001,-(15-1)) + BitShift(0x0001,-(7-1)) + BitShift(0x0001,-(24-1)) + BitShift(0x0001,-(1-1)) + BitShift(0x0001,-(11-1)) + BitShift(0x0001,-(2-1))
        EndIf       
;---------------    

     Local $aMasks[_GUICtrlMonthCal_GetMonthRangeSpan($idMonthCal, True)]
        $aMasks[1] = $finalX; <<<-------- bold days
       _GUICtrlMonthCal_SetDayState($idMonthCal, $aMasks)

    GUICtrlSetState($tabCalendar, $GUI_SHOW)

EndFunc   ;==>BusyDays

 

Edited by arts

Share this post


Link to post
Share on other sites
Andreik

Try this:

#include <SQLite.au3>
#include <SQLite.dll.au3>
#include <GUIMonthCal.au3>
#include <GUIConstantsEx.au3>
#include <String.au3>

_SQLite_Startup()
$hDB = _SQLite_Open()

_SQLite_Exec($hDB,'CREATE TABLE Days(dt datetime)')
_SQLite_Exec($hDB,"INSERT INTO Days SELECT '2015-06-15'")
_SQLite_Exec($hDB,"INSERT INTO Days SELECT '2015-06-18'")
_SQLite_Exec($hDB,"INSERT INTO Days SELECT '2015-06-21'")
_SQLite_Exec($hDB,"INSERT INTO Days SELECT '2015-06-23'")
_SQLite_Exec($hDB,"INSERT INTO Days SELECT '2015-06-29'")

$hMain = GUICreate('Test')
$hCal = _GUICtrlMonthCal_Create($hMain, 100,100, $MCS_DAYSTATE)
SetBoldDays($hDB,$hCal,"SELECT strftime('%d',dt) AS Day FROM Days")

GUISetState(@SW_SHOW)

Do
    Sleep(10)
Until GUIGetMsg() = $GUI_EVENT_CLOSE

_SQLite_Close($hDB)
_SQLite_Shutdown()

Func SetBoldDays($hDB,$hCal,$sQuery)
    Local $aResult, $iRows, $iColumns
    $iRval = _SQLite_GetTable2d($hDB, $sQuery , $aResult, $iRows, $iColumns)
    If $iRval = $SQLITE_OK Then
        Local $Mask = _StringRepeat('0',31)
        For $Index = 1 To UBound($aResult)-1
            $Mask = StringLeft($Mask,$aResult[$Index][0]-1) & '1' & StringRight($Mask,31-$aResult[$Index][0]-1)
        Next
        Local $aMasks[_GUICtrlMonthCal_GetMonthRangeSpan($hCal, True)]
        $aMasks[1] = Bin2Dec(StringReverse($Mask))
        _GUICtrlMonthCal_SetDayState($hCal, $aMasks)
    Else
        MsgBox(0x10,'Error','Oups!')
    EndIf
EndFunc

Func Bin2Dec($B)
    ; Thanks to kaesereibe
    ;https://www.autoitscript.com/forum/topic/163035-dec2bin-bin2dec/?do=findComment&comment=1186748
    Return BitOr((StringLen($B) > 1 ? BitShift(Bin2Dec(StringTrimRight($B, 1)), -1) : 0), StringRight($B, 1))
EndFunc

 

Edited by Andreik
Additional info
  • Like 1

When the words fail... music speaks

Share this post


Link to post
Share on other sites
arts

This works perfectly. Thank you, Andreik.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

  • Similar Content

    • SorryButImaNewbie
      By SorryButImaNewbie
      Hello
      First, I thank you for all the help I received here with Excel UDFs and COM objects in the last few days/week.
      I would like to "pimp" my output excel a bit, and for that I would like to write some results Bold.
      How do I do that?
      I tried a few things but most return errors, or doesn't do a thing seemingly.
      My code right now, this does run, but doesn't make the inserted results bold. (by inserted I mean what I write with _Excel_RangeWrite)
      _Excel_RangeWrite($ExcelObject, $ExcelObject.Activesheet, "=" & $OSSZEGoszlop & $CellaOlvasoSzamlalo & "*" & String($ArfolyamArray[$DateArrayTimeIndex]) & "", String($sHUFBeszurOszlop) & $CellaOlvasoSzamlalo) $ExcelObject.Activesheet.Range(String($sHUFBeszurOszlop) & $CellaOlvasoSzamlalo).Bold = True Thank you for the help!
      Edit: I leave this here, added the bold tag, maybe someone find it usefull
    • AndyS01
      By AndyS01
      I want to create a menu item and set the text to bold and the color to red, but I cannot find a UDF to do this.
      I want to make calls something like this:
      _GUICtrlMenu_SetItemFont($hMenu, $iIndex, $oFont) _GUICtrlMenu_SetItemColor($hMenu, $iIndex, $iColor) I want to make them UDFs so I don't have to add lots of code to the script that calls them.  I've seen some on-line content, but what I found needed add too much code to support it.
      Here is my test code:
      #include <GuiMenu.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <FontConstants.au3> Opt('MustDeclareVars', 1) Opt("GUICloseOnESC", 1) ; 1 = ESC closes GUI Opt("GUIOnEventMode", 1) ; 1 = OnEvent mode OnAutoItExitRegister("ExitStageLeft") ; The $aMenuItems[] array holds information about each menu item. ; Each element holds items that are separated by a '|'. When each item is split ; into an array, the resulting array has this info: ; [0] = The item's Menu ID (from the '_GUICtrlMenu_AddMenuItem' function call ; [1] = The item's Font Number (0 = no special font; 1 = font #1, etc.)) ; [2] = The Item's Text Color value (0 = no special color, else: $COLOR_RED, $COLOR_BLUE, etc.) ; [3] = The item's menu index value ; [4] = The Item's Handler name Global Enum $__MI_ID, $__MI_FONTNUM, $__MI_COLOR, $__MI_NDX, $__MI_HANDLER, $__MI_CNT Global $aMenuItems Global $iMemo, $aFonts[2] Example() exit Func Example() Local $hGUI, $hFile, $hMain createFonts() $hGUI = GUICreate("Menu", 400, 300); Create the main GUI $aMenuItems = StringSplit("", "") ; Initialize the $aMenuItems[] array $hFile = _GUICtrlMenu_CreateMenu(); Create the File menu _myGUICtrlMenu_AddMenuItem($hFile, "&New", "handle_munuitem_New") _myGUICtrlMenu_AddMenuItem($hFile, "&Open", "handle_munuitem_Open") _myGUICtrlMenu_AddMenuItem($hFile, "") _myGUICtrlMenu_AddMenuItem($hFile, "I want this to be bold 12pt Red text", "handle_MenuItem_test", 0xFF0000, 1) _myGUICtrlMenu_AddMenuItem($hFile, "") _myGUICtrlMenu_AddMenuItem($hFile, "E&xit", "handle_munuitem_Exit") $hMain = _GUICtrlMenu_CreateMenu(); Create the Main menu _GUICtrlMenu_InsertMenuItem($hMain, 0, "&File", 0, $hFile) _GUICtrlMenu_SetMenu($hGUI, $hMain); Set the window menu ; Display the 'menu items' info array For $ndx = 0 To UBound($aMenuItems) - 1 ConsoleWrite("+++: [" & $ndx & "] = " & $aMenuItems[$ndx] & @CRLF) Next $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 276, 0); Create the memo control GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New") GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_CLOSE, "ExitStageLeft") GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") MemoWrite("Click on the File menu and " & @crlf & "select one of the menu items.") ; Loop until the user exits. while(1) sleep(100) WEnd EndFunc ;==>Example ; Add a menu item, then add its info to the $aMenuItems[] array Func _myGUICtrlMenu_AddMenuItem($hMenu, $sTitle = "", $sHandler = "", $iColor = 0, $iFontnum = 0) Local $iIndex, $iCmdID, $ar[1], $fontnum, $str, $color $iIndex = _GUICtrlMenu_GetItemCount($hMenu) If ($sTitle <> "") Then $iCmdID = 1000 + $iIndex $iIndex = _GUICtrlMenu_AddMenuItem($hMenu, $sTitle, $iCmdID) If ($sHandler <> "") Then ; Create then populate a MenuItem info array ReDim $ar[$__MI_CNT] $ar[$__MI_ID] = $iCmdID $ar[$__MI_FONTNUM] = $iFontnum $ar[$__MI_COLOR] = $iColor $ar[$__MI_NDX] = $iIndex $ar[$__MI_HANDLER] = $sHandler $str = _ArrayToString($ar, "|", 0) _ArrayAdd($aMenuItems, $str) $aMenuItems[0] = UBound($aMenuItems) - 1 If ($iFontnum > 0) And ($iFontnum <= UBound($aFonts)) Then _GUICtrlMenu_SetItemFont($hMenu, $iIndex, $aFonts[$iFontnum-1]) EndIf If ($iColor <> 0) Then _GUICtrlMenu_SetItemColor($hMenu, $iIndex, $iColor) EndIf GUICtrlSetOnEvent($iCmdID, $sHandler) EndIf Else _GUICtrlMenu_AddMenuItem($hMenu, "") ; Add just a horizontal bar EndIf EndFunc ;==>_myGUICtrlMenu_AddMenuItem ; Handle menu commands Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $ilParam Local $id, $parts, $handler $id = _WinAPI_LoWord($iwParam) ; See if this ID is in the list of items in the $aMenuItems[] array For $ndx = 1 To UBound($aMenuItems) - 1 $parts = StringSplit($aMenuItems[$ndx], "|", 2) If ($id = $parts[$__MI_ID]) Then MemoWrite("$id = " & $id) ; It is, so call the handler associated with it $handler = $parts[$__MI_HANDLER] Call($handler) ; Call the handler ExitLoop EndIf Next Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Func handle_munuitem_New() MemoWrite("handle_munuitem_New") EndFunc ;==>handle_munuitem_New Func handle_munuitem_Open() MemoWrite("handle_munuitem_Open") EndFunc ;==>handle_munuitem_Open Func handle_MenuItem_test() MemoWrite("handle_MenuItem_test") EndFunc ;==>handle_MenuItem_test Func handle_munuitem_Exit() MemoWrite("handle_munuitem_Exit") EndFunc ;==>handle_munuitem_Exit Func ExitStageLeft() Exit (1) EndFunc ;==>ExitStageLeft ; Write message to memo Func MemoWrite($sMessage) Local Static $cnt = 0 $cnt += 1 GUICtrlSetData($iMemo, $sMessage & @CRLF, 1) ConsoleWrite("+++: " & StringFormat("%2d: %s", $cnt, $sMessage) & @CRLF) EndFunc ;==>MemoWrite Func createFonts() $aFonts[0] = _WinAPI_CreateFont(14, 0, 0, 0, $FW_NORMAL, _ False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, _ $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, "MS Sans Serif") $aFonts[1] = _WinAPI_CreateFont(14, 0, 0, 0, $FW_BOLD) EndFunc ;==>createFonts Here is a skeleton of the UDF functions:
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; _GUICtrlMenu_SetItemColor() - Set the color for the text in a menu item. ; ; PARAMS: $hMenu - The Handle of the menu the item's attached to ; $iIndex - The menu item number ; $iColor - The text color ; ; RETURNS: <nothing> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func _GUICtrlMenu_SetItemColor($hMenu, $iIndex, $iColor) #forceref $hMenu, $iIndex, $iColor ConsoleWrite("+++: _GUICtrlMenu_SetItemColor(" & $hMenu & ", " & $iIndex & ", " & Hex($iColor) & ") entered" & @CRLF) ; TBD ... TBD ... TBD ... EndFunc ;==>_GUICtrlMenu_SetItemColor ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; _GUICtrlMenu_SetItemFont() - Set the font for the text in a menu item. ; ; PARAMS: $hMenu - The Handle of the menu the item's attached to ; $iIndex - The menu item number ; $iColor - The font object (as created by the _WinAPI_CreateFont() function). ; ; RETURNS: <nothing> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func _GUICtrlMenu_SetItemFont($hMenu, $iIndex, $oFont) #forceref $hMenu, $iIndex, $fFont ConsoleWrite("+++: _GUICtrlMenu_SetItemFont(" & $hMenu & ", " & $iIndex & ", $oFont) entered" & @CRLF) ; TBD ... TBD ... TBD ... EndFunc ;==>_GUICtrlMenu_SetItemFont  
    • Chimp
      By Chimp
      This script generates a calendar of 12 pages in pdf format (ready to be printed if you want)
      it include for each month also the previous and the next month on the same page.
      It makes use of the "MPDF_UDF.au3" udf by taietel from >this topic
      you must download that udf and save it in the same folder with this script.
      (it seems that the version modified by bdr529 from post #231 is more updated.
      I used that one with my script.)
      Happy new year
      ; Create a Calendar in pdf ; ; download the "MPDF_UDF.au3" udf from here: http://www.autoitscript.com/forum/topic/118827-create-pdf-from-your-application/?p=1158973 ; it is at the bottom of post #231. Download and save it in the same path of this script. #include "MPDF_UDF.au3" ; #include <date.au3> $sYear = "2015" ; <--- change the year if you need another $sMonths = "January,February,March,April,May,June,July,August,September,October,November,December" $sDaysOfWeek = "Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday" ; --- just change above names to localize (following names are italian for example) --- ; $sMonths = "Gennaio,Febbraio,Marzo,Aprile,Maggio,Giugno,Luglio,Agosto,Settembre,Ottobre,Novembre,Dicembre" ; $sDaysOfWeek = "Lunedì,Martedì,Mercoledì,Giovedì,Venerdì,Sabato,Domenica" ; ------------------------------------------------------------------------------------- Local $aMonths = StringSplit($sMonths, ","), $aDaysOfWeek = StringSplit($sDaysOfWeek, ",") Local $aPreviousMonth, $aNextMonth, $iDayOfWeek, $aColors[2] = ["0x000000", "0xFF0000"], $aDummy ; ;set the properties for the pdf _SetTitle("Calendar " & $sYear) _SetSubject("Calendar made with AutoIt (www.autoitscript.com)") _SetKeywords("calendar, pdf") _OpenAfter(True);open after generation _SetUnit($PDF_UNIT_CM) _SetPaperSize("A4") _SetZoomMode($PDF_ZOOM_FULLPAGE) _SetOrientation($PDF_ORIENTATION_PORTRAIT) _SetLayoutMode($PDF_LAYOUT_CONTINOUS) ;initialize the pdf _InitPDF(@ScriptDir & "\Calendar_" & $sYear & ".pdf") ;=== load used font(s) === _LoadFontTT("_TimesNR", $PDF_FONT_TIMES) _LoadFontTT("_TimesNRB", $PDF_FONT_TIMES, $PDF_FONT_BOLD) ; For $Month = 1 To 12 ; Generate 12 months _BeginPage() ; begin page ; --- create areas that will contains days ----------------------------------------------- _InsertTable(00.50, 00.50, 20.00, 28.50, 1, 1, 0xB0B0B0, 0xB0B0B0) ; background _InsertTable(00.80, 26.10, 19.40, 02.60, 1, 1, 0xFF0000, 0x000000, 0.03) ; main month title _InsertTable(00.80, 00.80, 02.70, 25.00, 1, 1, 0xFFFFFF, 0x000000, 0.03) ; previous month (the little on the left) _InsertTable(00.80, 25.01875, 02.70, 00.78125, 1, 1, 0xFF0000, 0x000000, 0.03) ; title of previous month _InsertTable(03.80, 00.80, 13.40, 25.00, 2, 16, 0xFFFFFF, 0x000000) ; this month _DrawLine(03.80, 00.80, 17.20, 00.80, "0X2", 0, 0.03, 0x000000, 0, 0) ; border of this month _DrawLine(17.20, 00.80, 17.20, 25.80, "0X2", 0, 0.03, 0x000000, 0, 0) _DrawLine(17.20, 25.80, 03.80, 25.80, "0X2", 0, 0.03, 0x000000, 0, 0) _DrawLine(03.80, 25.80, 03.80, 00.80, "0X2", 0, 0.03, 0x000000, 0, 0) _InsertTable(17.50, 00.80, 02.70, 25.00, 1, 1, 0xFFFFFF, 0x000000, 0.03) ; next month (the little on the right) _InsertTable(17.50, 25.01875, 02.70, 00.78125, 1, 1, 0xFF0000, 0x000000, 0.03) ; title of next month ; --- now fill the areas with the dates -------------------------------------------------- _InsertRenderedText(10.5, 27, StringUpper($aMonths[$Month]) & " " & $sYear, "_TimesNR", 50, 100, $PDF_ALIGN_CENTER, 0xffffff, 0xffffff) ; Main Month _DateTimeSplit(_DateAdd("M", -1, $sYear & "/" & $Month & "/1"), $aPreviousMonth, $aDummy) ; Previous Month _InsertRenderedText(2.15, 25.28, StringUpper($aMonths[$aPreviousMonth[2]]) & " " & $aPreviousMonth[1], "_TimesNRB", 8.5, 100, $PDF_ALIGN_CENTER, 0xffffff, 0xffffff) ; Previous Month _DateTimeSplit(_DateAdd("M", 1, $sYear & "/" & $Month & "/1"), $aNextMonth, $aDummy) ; Next Month _InsertRenderedText(18.85, 25.28, StringUpper($aMonths[$aNextMonth[2]]) & " " & $aNextMonth[1], "_TimesNRB", 8.5, 100, $PDF_ALIGN_CENTER, 0xffffff, 0xffffff) ; Next Month For $i = 1 To 31 If _DateIsValid($aPreviousMonth[1] & "/" & $aPreviousMonth[2] & "/" & $i) Then ; previous month $iDayOfWeek = _DateToDayOfWeekISO($aPreviousMonth[1], $aPreviousMonth[2], $i) _InsertRenderedText(01.80, 24.4 - 0.78125 * ($i - 1), $i, "_TimesNR", 12, 100, $PDF_ALIGN_RIGHT, $aColors[$iDayOfWeek = 7], $aColors[$iDayOfWeek = 7]) ; Previous Month's days _InsertRenderedText(02.00, 24.4 - 0.78125 * ($i - 1), StringLeft($aDaysOfWeek[$iDayOfWeek], 3), "_TimesNR", 10, 100, $PDF_ALIGN_LEFT, $aColors[$iDayOfWeek = 7], $aColors[$iDayOfWeek = 7]) EndIf If _DateIsValid($aNextMonth[1] & "/" & $aNextMonth[2] & "/" & $i) Then ; next month $iDayOfWeek = _DateToDayOfWeekISO($aNextMonth[1], $aNextMonth[2], $i) _InsertRenderedText(18.50, 24.4 - 0.78125 * ($i - 1), $i, "_TimesNR", 12, 100, $PDF_ALIGN_RIGHT, $aColors[$iDayOfWeek = 7], $aColors[$iDayOfWeek = 7]) ; Next Month's days _InsertRenderedText(18.70, 24.4 - 0.78125 * ($i - 1), StringLeft($aDaysOfWeek[$iDayOfWeek], 3), "_TimesNR", 10, 100, $PDF_ALIGN_LEFT, $aColors[$iDayOfWeek = 7], $aColors[$iDayOfWeek = 7]) EndIf If _DateIsValid($sYear & "/" & $Month & "/" & $i) Then ; main month $iDayOfWeek = _DateToDayOfWeekISO($sYear, $Month, $i) _InsertRenderedText(05.30 + (06.70 * Int($i / 17)), 26.30 - 1.5625 * ($i - (16 * Int($i / 17))), $i, "_TimesNRB", 24, 100, $PDF_ALIGN_RIGHT, $aColors[$iDayOfWeek = 7], $aColors[$iDayOfWeek = 7]) _InsertRenderedText(05.60 + (06.70 * Int($i / 17)), 26.30 - 1.5625 * ($i - (16 * Int($i / 17))), $aDaysOfWeek[$iDayOfWeek], "_TimesNR", 22, 100, $PDF_ALIGN_LEFT, $aColors[$iDayOfWeek = 7], $aColors[$iDayOfWeek = 7]) EndIf If $i < 31 Then ; separator line between days in previous and next month _DrawLine(01.00, 25 - 0.78125 * $i, 03.30, 25 - 0.78125 * $i, 2, 10, 0.02, 0x000000, 0, 0) _DrawLine(17.70, 25 - 0.78125 * $i, 20.00, 25 - 0.78125 * $i, 2, 10, 0.02, 0x000000, 0, 0) EndIf Next _EndPage() ; next month will be in a new page Next ; next month ;write the buffer to disk _ClosePDFFile() ; --- Functions --- Func _InsertTable($iX, $iY, $iW = 0, $iH = 0, $iCols = 0, $iRows = 0, $lFillColor = 0xFFFFFF, $lBorderColor = 0x000000, $fThickness = 0.01) Local $iPgW = Round(_GetPageWidth() / _GetUnit(), 1) Local $iPgH = Round(_GetPageHeight() / _GetUnit(), 1) If $iW = 0 Then $iW = $iPgW - $iX - 2 If $iH = 0 Then $iH = $iPgH - $iY - 2 Local $iColW = $iW / $iCols Local $iRowH = $iH / $iRows _SetColourStroke($lBorderColor) For $i = 0 To $iRows - 1 For $j = 0 To $iCols - 1 _Draw_Rectangle($iX + $j * $iColW, $iY + $iH - ($i + 1) * $iRowH, $iColW, $iRowH, $PDF_STYLE_STROKED, 0, $lFillColor, $fThickness) Next Next _SetColourStroke(0) EndFunc ;==>_InsertTable Func _Iif($fTest, $vTrueVal, $vFalseVal) If $fTest Then Return $vTrueVal Else Return $vFalseVal EndIf EndFunc ;==>_Iif edit:
      p.s. if you get this error: ERROR: _Iif() already defined.
      then just remove the _Iif() function from the bottom of this script
      this occurs with older AutoIt versions
    • Kanashius
      By Kanashius
      This program can be used to create simple alarms (msgbox or soundfile can be added to every alarm).
      The program is just running in background, if you close it. (Use Tooltip to exit.)
      I translated the Programm in english to post it here. If you like it, please leave me a comment, also if you have any suggestions to make it better or if you found bugs.
      For more information and direct executables, please visit my website: http://kanashius.de/?page=kalender
      kalenderfenster_source.zip
    • jmon
      By jmon
      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:


      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
×