# Desktop Calendar

## Recommended Posts

Desktop Calendar is a calendar that will allow you to open up a dialog for any day of the year and save notes for different times during that day.

I rewrote the program to update it to the new standards, cleaned up the code a lot, and upgraded it to use a database instead of sprawling ini files like mad like it used to. It is still very basic, but it is a lot more stable. I chose to use sqlite3.exe instead of the embedded functions for a few reasons, the main being I'm just more comfortable coding with it this way for now. If you feel like updating it to use the sqlite.au3/sqlite.dll.au3, please post it as an option for download, otherwise I may eventually get to it some day as I'm sure it will aid in the speed of the program.

I'm open to suggestions, criticism, bug reports...

Features:

browse calendar and add notes for any hour of any day of any year

view and edit notes

To Do:

make main window transparent, but controls visable

allow selection of an alarm or notification at chosen date and time, either an audio file or a pop up message box.

allow search for notes

allow import of other calendar information from other formats (ie, ical)

allow icons to depict type of note (new column or beginning of column entry, denoting school, work, entertainment, church, etc)

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#NoTrayIcon
$name = "Desktop Calendar"$version = "1.0"
$author = "Jared Epstein" main() Func main()$winpos = _GuiGetLastPos($name, "", 2)$main = GUICreate($name, 195, 210,$winpos[0], $winpos[1], -1,$WS_EX_TOOLWINDOW)
$contextmenu = GUICtrlCreateContextMenu()$startonboot = GUICtrlCreateMenuItem("Start On Boot", $contextmenu)$reg = _RunReadStd (@ComSpec & " /c " & 'sqlite3 calendar.db "select boot from conf";')
If $reg[1] = 1 Then GUICtrlSetState($startonboot, $GUI_CHECKED) ElseIf$reg[1] = 0 Then
GUICtrlSetState($startonboot,$GUI_UNCHECKED)
EndIf
$alwaysontop = GUICtrlCreateMenuItem("Always On Top",$contextmenu)
$reg = _RunReadStd (@ComSpec & " /c " & 'sqlite3 calendar.db "select ontop from conf";') If$reg[1] = 1 Then
GUICtrlSetState($alwaysontop,$GUI_CHECKED)
WinSetOnTop($name, "", 1) ElseIf$reg[1] = 0 Then
GUICtrlSetState($alwaysontop,$GUI_UNCHECKED)
EndIf
$aboutmenu = GUICtrlCreateMenuItem("About",$contextmenu)
$helpmenu = GUICtrlCreateMenuItem("Help",$contextmenu)
$exitmenu = GUICtrlCreateMenuItem("Exit",$contextmenu)
$cal = GUICtrlCreateMonthCal(@YEAR & "/" & @MON & "/" & @MDAY, 10, 10)$notes = GUICtrlCreateButton("View/Edit Notes", 50, 175, 100, 25)

GUISetState()
Do
$msg = GUIGetMsg() _GuiDockToScreenSide($name, "")

If $msg =$notes Then
_Notes($cal,$main)
EndIf

If $msg =$aboutmenu Then
_AboutInfo ($name,$version, $author,$main, "Icons\cal.ico")
EndIf

If $msg =$helpmenu Then
ShellExecute("dchelp.chm", "", @ScriptDir)
EndIf

If $msg =$exitmenu Then
ExitLoop
EndIf

If $msg =$startonboot Then
If BitAND(GUICtrlRead($startonboot),$GUI_CHECKED) = $GUI_CHECKED Then _RunReadStd(@ComSpec & " /c " & 'sqlite3 Calendar.db "update conf set boot = 0 ;"') RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run",$name)
GUICtrlSetState($startonboot,$GUI_UNCHECKED)
Else
_RunReadStd(@ComSpec & " /c " & 'sqlite3 Calendar.db "update conf set boot = 1 ;"')
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", $name, "REG_SZ", @ScriptFullPath) GUICtrlSetState($startonboot,$GUI_CHECKED) EndIf EndIf If$msg = $alwaysontop Then If BitAND(GUICtrlRead($alwaysontop), $GUI_CHECKED) =$GUI_CHECKED Then
_RunReadStd(@ComSpec & " /c " & 'sqlite3 Calendar.db "update conf set ontop = 0 ;"')
WinSetOnTop($name, "", 0) GUICtrlSetState($alwaysontop,$GUI_UNCHECKED) Else _RunReadStd(@ComSpec & " /c " & 'sqlite3 Calendar.db "update conf set ontop = 1 ;"') WinSetOnTop($name, "", 1)
GUICtrlSetState($alwaysontop,$GUI_CHECKED)

EndIf
EndIf

Until $msg =$GUI_EVENT_CLOSE

_GuiSetLastPos($name, "", 2) GUIDelete() EndFunc ;==>main Func _GuiGetLastPos($s_Title, $s_Text = "",$i_Info = 0)
Local $ai_Pos[2],$i_xPos, $i_yPos,$ai_Read
If $i_Info = 0 Then$i_xPos = IniRead($s_Title & ".ini",$s_Title, "Xpos", -1)
$i_yPos = IniRead($s_Title & ".ini", $s_Title, "Ypos", -1)$ai_Pos[0] = $i_xPos$ai_Pos[1] = $i_yPos ElseIf$i_Info = 1 Then
$i_xPos = RegRead("HKEY_CURRENT_USER\SOFTWARE\" &$s_Title, "Xpos")
If $i_xPos = 1 Or$i_xPos = -32000 Then
RegWrite("HKEY_CURRENT_USER\SOFTWARE\" & $s_Title, "Xpos", "REG_SZ", -1)$i_xPos = RegRead("HKEY_CURRENT_USER\SOFTWARE\" & $s_Title, "Xpos") EndIf$i_yPos = RegRead("HKEY_CURRENT_USER\SOFTWARE\" & $s_Title, "Ypos") If$i_yPos = 1 Or $i_yPos = -32000 Then RegWrite("HKEY_CURRENT_USER\SOFTWARE\" &$s_Title, "Ypos", "REG_SZ", -1)
$i_yPos = RegRead("HKEY_CURRENT_USER\SOFTWARE\" &$s_Title, "Ypos")
EndIf
$ai_Pos[0] =$i_xPos
$ai_Pos[1] =$i_yPos
ElseIf $i_Info = 2 Then$ai_Read = _RunReadStd (@ComSpec & " /c " & 'sqlite3 calendar.db "select x,y from conf";')
$ai_Pos = StringSplit($ai_Read[1], Chr(124), 2)
EndIf
Return $ai_Pos EndFunc ;==>_GuiGetLastPos Func _GuiSetLastPos($s_Title, $s_Text = "",$i_Info = 0)
Local $ai_Pos[2]$ai_Pos = WinGetPos($s_Title,$s_Text)
If $i_Info = 0 Then IniWrite($s_Title & ".ini", $s_Title, "Xpos",$ai_Pos[0])
IniWrite($s_Title & ".ini",$s_Title, "Ypos", $ai_Pos[1]) ElseIf$i_Info = 1 Then
RegWrite("HKEY_CURRENT_USER\SOFTWARE\" & $s_Title, "Xpos", "REG_SZ",$ai_Pos[0])
RegWrite("HKEY_CURRENT_USER\SOFTWARE\" & $s_Title, "Ypos", "REG_SZ",$ai_Pos[1])
ElseIf $i_Info = 2 Then _RunReadStd (@ComSpec & " /c " & 'sqlite3 calendar.db "update conf set x = ' &$ai_Pos[0] & ", y = " & $ai_Pos[1] & ";") EndIf EndFunc ;==>_GuiSetLastPos Func _GuiDockToScreenSide($s_Title, $s_Text = "") Local$ai_Pos[4]
$ai_Pos = WinGetPos($s_Title, $s_Text) If$ai_Pos[0] + $ai_Pos[2] > @DesktopWidth Then WinMove($s_Title, $s_Text, @DesktopWidth -$ai_Pos[2], $ai_Pos[1]) EndIf If$ai_Pos[1] + $ai_Pos[3] > @DesktopHeight Then WinMove($s_Title, $s_Text,$ai_Pos[0], @DesktopHeight - $ai_Pos[3]) EndIf If$ai_Pos[0] < 1 Then
WinMove($s_Title,$s_Text, 1, $ai_Pos[1]) EndIf If$ai_Pos[1] < 1 Then
WinMove($s_Title,$s_Text, $ai_Pos[0], 1) EndIf EndFunc ;==>_GuiDockToScreenSide Func _Notes($cid, $parent) Local$selected, $split,$date, $datefile,$hour[24], $child,$listview, $i,$j, $edit$selected = GUICtrlRead($cid)$split = StringSplit($selected, "/")$date = $split[1] & "-" &$split[2] & "-" & $split[3]$child = GUICreate($date, 540, 420, -1, -1, -1, -1,$parent)
$listview = GUICtrlCreateListView("Hour|Note", 10, 10, 520, 360) For$i = 1 To 24
If $i = 24 Then$j = $i - 12 & " am" ElseIf$i < 12 Then
$j =$i & " am"
ElseIf $i = 12 Then$j = $i & " pm" ElseIf$i > 12 Then
$j =$i - 12 & " pm"
EndIf
GUICtrlCreateListViewItem($j,$listview)
Next
$read = _RunReadStd (@ComSpec & " /c " & 'sqlite3 Calendar.db "select note,time from notes where date = ' & "'" &$date & "';")
$readsplit = StringSplit($read[1], Chr(9))
If @error <> 1 Then
For $i = 1 To$readsplit[0]
$datedata = StringSplit($readsplit[$i], Chr(124)) _GuiCtrlListview_AddSubItem ($listview, $datedata[2] - 1,$datedata[1], 1)
Next
ElseIf @error = 1 And $readsplit[0] = 1 Then If$readsplit[1] <> "" Then
$datedata = StringSplit($readsplit[1], Chr(124))
_GuiCtrlListview_AddSubItem ($listview,$datedata[2] - 1, $datedata[1], 1) EndIf EndIf$edit = GUICtrlCreateButton("View/Edit", 255, 385, 75, 25)
_GUICtrlListView_SetItemFocused ($listview, 0) _GUICtrlListView_SetItemSelected ($listview, 0)
_GUICtrlListView_SetColumnWidth ($listview, 1,$LVSCW_AUTOSIZE)
GUISetState()
Do
$msg1 = GUIGetMsg() If$msg1 = $edit Then _Edit($child, $date,$listview)
EndIf
Until $msg1 =$GUI_EVENT_CLOSE
GUIDelete($child) EndFunc ;==>_Notes Func _Edit($parent, $day,$hwnd)
$selected = _GUICtrlListView_GetSelectionMark ($hwnd)
$time = _GUICtrlListView_GetItemText ($hwnd, $selected)$read = _RunReadStd (@ComSpec & " /c " & 'sqlite3 Calendar.db "select note from notes where date = ' & "'" & $day & "' and time = '" & ($selected + 1) & "';")
If $read[2] <> "" Then$read[1] = ""
EndIf
$grandchild = GUICreate("Edit " &$time & " on " & $day, 340, 120, -1, -1, -1, -1,$parent)
$editbox = GUICtrlCreateEdit($read[1], 10, 10, 320, 80)
$save = GUICtrlCreateButton("Save", 100, 100, 75, 25)$cancel = GUICtrlCreateButton("Cancel", 180, 100, 75, 25)
GUISetState()
Do
$msg1a = GUIGetMsg() If$msg1a = $save Then _RunReadStd (@ComSpec & " /c " & 'sqlite3 Calendar.db "insert or replace into notes values (' & "'" &$day & "','" & ($selected + 1) & "','" & GUICtrlRead($editbox) & "');")
_GUICtrlListView_SetItemText ($hwnd,$selected, GUICtrlRead($editbox), 1) _GUICtrlListView_SetColumnWidth ($hwnd, 1, $LVSCW_AUTOSIZE) ExitLoop EndIf If$msg1a = $cancel Then ExitLoop EndIf Until$msg1a = $GUI_EVENT_CLOSE GUIDelete($grandchild)
EndFunc   ;==>_Edit

Func _AboutInfo($s_Program,$s_Version,$s_Author,$h_Parent,$s_Icon = "") Local$h_Child,$s_Font,$h_Aboutok,$s_Msg1$h_Child = GUICreate("About", 220, 220, -1, -1, -1, -1, $h_Parent)$s_Font = "Ariel"
GUICtrlCreateLabel($s_Program & " " &$s_Version, 50, 30, 150, 30)
GUICtrlSetFont(-1, 10, 400, $s_Font) GUICtrlCreateIcon($s_Icon, -1, 85, 60, 48, 48)
GUICtrlCreateLabel("Written by " & $s_Author, 55, 120, 150, 30) GUICtrlSetFont(-1, 10, 400,$s_Font)
GUICtrlCreateLabel("Copyright " & @YEAR, 55, 140, 150, 30)
GUICtrlSetFont(-1, 10, 400, $s_Font)$h_Aboutok = GUICtrlCreateButton("OK", 75, 175, 75, 25)
GUISetState()
Do
$s_Msg1 = GUIGetMsg() If$s_Msg1 = $h_Aboutok Then ExitLoop EndIf Until$s_Msg1 = $GUI_EVENT_CLOSE GUIDelete($h_Child)

Func _RunReadStd($doscmd,$timeoutSeconds = 0, $workingdir = @ScriptDir,$flag = @SW_HIDE, $nRetVal = -1,$sDelim = @TAB)
Local $aReturn,$i_Pid, $h_Process,$i_ExitCode, $sStdOut,$sStdErr, $runTimer Dim$aReturn[3]

; run process with StdErr and StdOut flags
$runTimer = TimerInit()$i_Pid = Run($doscmd,$workingdir, $flag, 6) ; 6 =$STDERR_CHILD+$STDOUT_CHILD ; Get process handle Sleep(100) ; or DllCall may fail - experimental$h_Process = DllCall('kernel32.dll', 'ptr', 'OpenProcess', 'int', 0x400, 'int', 0, 'int', $i_Pid) ; create tab delimited string containing StdOut text from process$aReturn[1] = ""
$sStdOut = "" While 1$sStdOut &= StdoutRead($i_Pid) If @error Then ExitLoop WEnd$sStdOut = StringReplace($sStdOut, @CR, @TAB)$sStdOut = StringReplace($sStdOut, @LF, @TAB)$aStdOut = StringSplit($sStdOut, @TAB, 1) For$i = 1 To $aStdOut[0]$aStdOut[$i] = StringStripWS($aStdOut[$i], 3) If StringLen($aStdOut[$i]) > 0 Then$aReturn[1] &= $aStdOut[$i] & $sDelim EndIf Next$aReturn[1] = StringTrimRight($aReturn[1], 1) ; create tab delimited string containing StdErr text from process$aReturn[2] = ""
$sStdErr = "" While 1$sStdErr &= StderrRead($i_Pid) If @error Then ExitLoop WEnd$sStdErr = StringReplace($sStdErr, @CR, @TAB)$sStdErr = StringReplace($sStdErr, @LF, @TAB)$aStderr = StringSplit($sStdErr, @TAB, 1) For$i = 1 To $aStderr[0]$aStderr[$i] = StringStripWS($aStderr[$i], 3) If StringLen($aStderr[$i]) > 0 Then$aReturn[2] &= $aStderr[$i] & $sDelim EndIf Next$aReturn[2] = StringTrimRight($aReturn[2], 1) ; kill the process if it exceeds$timeoutSeconds
If $timeoutSeconds > 0 Then If TimerDiff($runTimer) / 1000 > $timeoutSeconds Then ProcessClose($i_Pid)
EndIf
EndIf

; fetch exit code and close process handle
If IsArray($h_Process) Then Sleep(100) ; or DllCall may fail - experimental$i_ExitCode = DllCall('kernel32.dll', 'ptr', 'GetExitCodeProcess', 'ptr', $h_Process[0], 'int*', 0) If IsArray($i_ExitCode) Then
$aReturn[0] =$i_ExitCode[2]
Else
$aReturn[0] = -1 EndIf Sleep(100) ; or DllCall may fail - experimental DllCall('kernel32.dll', 'ptr', 'CloseHandle', 'ptr',$h_Process[0])
Else
$aReturn[0] = -2 EndIf ; return single item if correctly specified with with$nRetVal
If $nRetVal <> -1 And$nRetVal >= 0 And $nRetVal <= 2 Then Return$aReturn[$nRetVal] ; return array with exit code, stdout, and stderr Return$aReturn
EndFunc   ;==>_RunReadStd

Package (sqlite3, prebuilt database, help file, icon and source):

Edited by maqleod

##### Share on other sites

I've not tested it myself, but looking at it, it looks as if to be pretty nice. Basic yes like you said, but for something like this you don't want to go "over the edge" that would be going beside the point of this script.

Nice work

~TK

##### Share on other sites

Checking out that program was surprisingly inspiring.

##### Share on other sites

Nice start, like you said basic but is a start to a great needed script. Good Luck..

##### Share on other sites

updated with new format for saving files, cleaned up code and adopted a more standard format, please let me know what you think.

##### Share on other sites

It kill's my firefox, first time it shrank it to the top left, then I maximized it and it just shook. I moved it to my second monitor and it would jump back. Second time I had firefox already on my second monitor. It was fine till I moved it to the first monitor again and it was shaking again. Other then that the size is a little off, at least on my computer. The month scroller for right is closer to the boarder then the left. and you legend at the bottom is cut off. Other than all that. It gives me some ideas.

Giggity

##### Share on other sites

It kill's my firefox, first time it shrank it to the top left, then I maximized it and it just shook. I moved it to my second monitor and it would jump back. Second time I had firefox already on my second monitor. It was fine till I moved it to the first monitor again and it was shaking again. Other then that the size is a little off, at least on my computer. The month scroller for right is closer to the boarder then the left. and you legend at the bottom is cut off. Other than all that. It gives me some ideas.

well, I'm pretty sure its the docking function that would cause the shaking - just remove it for now if you want to test further, it did that on my system till I tweaked the function a bit so I thought I had fixed it. I'll have to test it on some of my other computers to see what might be causing it to do that (got one running, XP, one with Vista and one with win2k). What OS are you running?

XP SP3

Giggity

## Create an account

Register a new account