; ; AutoHotkey Version: 1.x ; Language: English ; Platform: Win9x/NT ; Author: Jack Dunning ; https://jacksautohotkeyblog.wordpress.com/about/contact-jack/ ; Script Function: Track Todo List in the Windows Registry ; This is the third version of ToDoList.ahk dated Deceber 17, 2019 ; /* Acting as a demonstration of how the INI commands (IniWrite and IniRead) work, this version of the ToDoList script (ToDoListINI.ahk) saves entries in ToDoList.ini file. This takes advantage of the record-level access provided by the INI commands. You'll find the GUI ListView functions and various discussed in nine chapters of the book "AutoHotkey Applications": https://www.computoredgebooks.com/AutoHotkey-Applications-All-File-Formats_c31.htm?sourceCode=ToDoListReg December 28, 2019 Added menu bar with accelerators. */ TodoAutoExec: OnExit, SavePosition Gui, 1:default Gui +AlwaysOnTop +Resize Gui, Add, ListView, sort r10 checked -readonly vMyListView gMyListView , Items To Do | RegRec Gui, Add, Button, section gAddItem,Add to list Gui, Add, Edit, ys vNewItem w180 , SelectedRow := 0 Loop { ItemName := "Item" . A_Index IniRead, Value, ToDoList.ini, Items, %ItemName% If (Value = "ERROR") Break ; RegRead, value, HKCU\Software\ToDoListItem , %A_LoopRegName% If (value != "§") If SubStr(value, 1, 1) = "√" { StringTrimLeft, CheckedText, value, 1 LV_Add("Check", CheckedText, ItemName) } Else LV_Add("", value, ItemName) } LV_ModifyCol(1,"AutoHdr") LV_ModifyCol(2, 0) Menu, FileMenu, Add, E&xit`tCtrl+X, SavePosition Menu, HelpMenu, Add, &Toggle Help ToolTips`tCtrl+T, ShowToolTip Menu, MyMenuBar, Add, &File, :FileMenu Menu, MyMenuBar, Add, &Help, :HelpMenu Gui, Menu, MyMenuBar Menu, MyContextMenu, Add, Edit, EditText Menu, MyContextMenu, Add, Delete, DeleteItem Menu, Tray, Add, Show To Do List, ShowTodo IniRead, Pos, ToDoList.ini, Position, WinPos ; RegRead, WinPos, HKCU\Software\ToDoList , Position Hotkey, ^#!t, ShowTodo ; MsgBox %WinPos% If (Pos = "ERROR") { IniWrite, x500 y150 w300 h300, ToDoList.ini, Position, WinPos Gui, Show, x500 y150 w300 h300, To Do List } Else Gui, Show, %Pos% , To Do List GuiControl, Focus, NewItem SendInput, ^a ; OnMessage(0x200, "CheckControl") Return ShowToolTip: If (Toggle := !Toggle) { OnMessage(0x200, "CheckControl") Menu, HelpMenu, Check, &Toggle Help ToolTips`tCtrl+T } Else { OnMessage(0x200, "") Menu, HelpMenu, Uncheck, &Toggle Help ToolTips`tCtrl+T } Return ShowTodo: Gui, Show,, To Do List Return MyListView: If A_GuiEvent = e { LV_GetText(ItemText, A_EventInfo) LV_GetText(ItemNumber, A_EventInfo, 2) LV_ModifyCol(1, "Sort") LV_ModifyCol(1,"AutoHdr") IniWrite, %ItemText%, ToDoList.ini, Items, %ItemNumber% ; RegWrite, REG_SZ, HKCU\Software\ToDoListItem, %ItemNumber%, %ItemText% } Return GuiContextMenu: ; Launched in response to a right-click or press of the Apps key. If A_GuiControl <> MyListView ; Display the menu only for clicks inside the ListView. return LV_GetText(EditText, A_EventInfo) ; Show the menu at the provided coordinates, A_GuiX and A_GuiY. These should be used ; because they provide correct coordinates even if the user pressed the Apps key: Menu, MyContextMenu, Show , %A_GuiX%, %A_GuiY% Return DeleteItem: ; The user selected "Delete" in the context menu. SelectedRow := LV_GetNext() ItemText := "§" LV_GetText(ItemNumber, SelectedRow, 2) IniWrite, %ItemText%, ToDoList.ini, Items, %ItemNumber% ; RegWrite, REG_SZ, HKCU\Software\ToDoListItem, %ItemNumber%, %ItemText% LV_Delete(SelectedRow) Return AddItem: Gui, Submit, NoHide NextItem := "" Count := 1 Loop { ItemName := "Item" . A_Index IniRead, Value, ToDoList.ini, Items, %ItemName% If (Value = "§") { NextItem := ItemName Break } If (value = "ERROR") Break Count++ } If (NextItem = "") { ; Next := A_Index+1 NextItem := "Item" . Count } IniWrite, %NewItem%, ToDoList.ini, Items, %NextItem% ; RegWrite, REG_SZ, HKCU\Software\ToDoListItem, %NextItem%, %NewItem% LV_Add("", NewItem, NextItem) LV_ModifyCol(1, "Sort") LV_ModifyCol(1,"AutoHdr") Return EditText: ; SelectedRow := LV_GetNext() SendInput, {F2} Return SavePosition: DetectHiddenWindows On WinGetPos, X, Y, Width, Height, To Do List If (x > 0) IniWrite, % " x" X " y" Y " w" Width-16 " h" Height-39, ToDoList.ini, Position, WinPos ; RegWrite, REG_SZ, HKCU\Software\ToDoList, Position, % " x" X " y" Y " w" Width-16 " h" Height-39 GoSub, Cleanup ExitApp Return GuiSize: ; Expand or shrink the ListView in response to the user's resizing of the window. if A_EventInfo = 1 ; The window has been minimized. No action needed. return ; Otherwise, the window has been resized or maximized. Resize the ListView to match. GuiControl, Move, MyListView, % "W" . (A_GuiWidth - 20) . " H" . (A_GuiHeight - 40) GuiControl, Move, Button1, % "y" . (A_GuiHeight - 30) GuiControl, Move, Edit1, % "y" . (A_GuiHeight - 30) . " W" . (A_GuiWidth - 90) Return GuiClose: GoSub, Cleanup WinMinimize Return Cleanup: IniRead, Value, ToDoList.ini, Items ; MsgBox, % Value Loop, Parse, Value, `n { ItemName := "Item" . A_Index RegExMatch(A_LoopField,"Item(\d+)?=",ItemNumber) ; MsgBox, % ItemNumber1 A_LoopField If (ItemNumber1 > MaxNumber) MaxNumber := ItemNumber1 ; MsgBox, % MaxNumber } ItemText := "§" ; MsgBox Loop, %MaxNumber% { ; MsgBox ItemNumber := "Item" . A_Index IniRead, Value, ToDoList.ini, Items, %ItemNumber% ; RegRead, value, HKCU\Software\ToDoListItem , %ItemNumber% ; MsgBox, % value if (Value = "ERROR") { IniWrite, %ItemText%, ToDoList.ini, Items, %ItemNumber% MaxNumber := 0 } ; RegWrite, REG_SZ, HKCU\Software\ToDoListItem, %ItemNumber% } ; This causes the first loop iteration to start the search at the top of the list. Loop, % LV_GetCount() { LV_Modify(A_Index, "Focus") ; MsgBox LV_GetText(ItemText, A_Index) LV_GetText(ItemNumber, A_Index, 2) Gui, +LastFound SendMessage, 4140, A_Index - 1, 0xF000, SysListView321 IsChecked := (ErrorLevel >> 12) - 1 If IsChecked and InStr(ItemNumber,"Item") { ItemText := "√" . ItemText ; MsgBox, % ItemText ItemNumber A_Index ErrorLevel IniWrite, %ItemText%, ToDoList.ini, Items, %ItemNumber% ; RegWrite, REG_SZ, HKCU\Software\ToDoListItem, %ItemNumber%, *%ItemText% } else { ItemText := StrReplace(ItemText,"√") IniWrite, %ItemText%, ToDoList.ini, Items, %ItemNumber% ; RegWrite, REG_SZ, HKCU\Software\ToDoListItem, %ItemNumber%, % StrReplace(ItemText,"*") } } Return #IfWinActive, To Do List ^a::LV_Modify(0,"Select") ^!e::GoSub, EditText ^#!o::GoSub, Cleanup #IfWinActive CheckControl() { MouseGetPos,,,, VarControl IfEqual, VarControl, Button1 Message := "Click to add new item" Else IfEqual, VarControl, SysListView321 Message := "Right-click to`nEdit or Delete" Else IfEqual, VarControl, Edit1 Message := "Enter new item here" ToolTip % Message Sleep 2000 ToolTip }