-
-
Save jasondavis/997deb8da9eeacbb50b775cc9f76a914 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Works for DropDownList/ComboBox/ListBox | |
Class ListBox | |
{ | |
__New(hwnd) { | |
; GuiControl, +AltSubmit, %hwnd% | |
this.hwnd := hwnd | |
} | |
Add(str) { | |
GuiControl,, % this.hwnd, %str% | |
} | |
; RowNumbers - Row number(s). Use non-number to delimit multiple numbers. e.g. 1|2|3 or 1,2,3 | |
; If the parameter is omitted, all rows are deleted. | |
Delete(ByRef RowNumbers := "") { | |
if !RowNumbers | |
return this.DeleteAll() | |
RowNumbers := RegExReplace(RowNumbers, "\D+", "|") | |
RowNumbers := Trim(RowNumbers, "|") | |
Sort, RowNumbers, R D| N ; Reverse numbers | |
Loop, Parse, RowNumbers, | | |
Control, Delete, %A_LoopField%,, % "ahk_id " this.hwnd | |
} | |
DeleteAll() { | |
GuiControl,, % this.hwnd, | | |
} | |
DeleteSelected() { | |
GuiControlGet, RowNumbers,, % this.hwnd | |
if RowNumbers | |
this.Delete(RowNumbers) | |
} | |
ImportFromFile(FileName) { | |
FileRead, s, %FileName% | |
s := RegExReplace(s, "\R+", "|") | |
s := Trim(s) | |
GuiControl,, % this.hwnd, %s% | |
} | |
SaveToFile(FileName) { | |
ControlGet, v, List,,, % "ahk_id " this.hwnd | |
FileOpen(FileName, "w").Write(v) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Include Class_ListBox.ahk | |
Gui, Font, s12 | |
Gui, Add, Button, gAdd, Add | |
Gui, Add, Button, x+50 gDelete, Delete | |
Gui, Add, Button, x+50 gDeleteAll, Delete All | |
Gui, Add, Button, x+50 gSave, Save To File | |
Gui, Add, ListBox, xm r20 w470 AltSubmit Multi HWNDhLB, ; Note the use of AltSubmit | |
Gui, Show | |
LB := New ListBox(hLB) | |
if FileExist("info.txt") | |
LB.ImportFromFile("info.txt") | |
Return | |
Add: | |
Gui, +OwnDialogs | |
InputBox, newItem, Add,,, 387, 105 | |
if (!ErrorLevel && newItem != "") | |
LB.Add(newItem) | |
return | |
Delete: | |
LB.DeleteSelected() | |
return | |
DeleteAll: | |
LB.DeleteAll() | |
return | |
Save: | |
LB.SaveToFile("info.txt") | |
MsgBox, Saved! | |
return | |
GuiClose: | |
ExitApp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment