did u read how
.Submit() works?
Collects the values from named controls and composes them into an Object. Optionally hides the window
NamedCtrlContents := MyGui.Submit([Hide := true])
not only are u not capturing the return value of the call to
.Submit():
Code: Select all
OK_click(*)
{
gestionnaire.submit()
; ^^ - ????
but even if u had, ud be getting an empty object back - u havent created any
named controls to begin with!
a named control is one with
vTypeTheNameHere in its options during creation
V: Sets the control's Name. Specify the name immediately after the letter V, which is not included in the name. For example, specifying vMyEdit would name the control "MyEdit".
or a created one whose
.Name property has been assigned to
Retrieves or sets the name of the control.
GuiCtrl.Name := NewName
so far all uve done is pass 0 to each checkbox's options(which tries to set a window style corresponding to that number, which effectively doesnt do anything in this case)
Code: Select all
#Requires AutoHotkey v2.0-a137-f6f65742
softwares := [{name: "ccleaner", url: "https www.ccleaner.com /ccleaner/download/standard", ticked: 0}
,{name: "adwcleaner", url: "https downloads.malwarebytes.com /file/adwcleaner", ticked: 0}]
gestionnaire := Gui()
for SW in softwares
gestionnaire.add("Checkbox", 'Checked' SW.ticked ' v' SW.name, SW.name)
; ^^^^^^^^^^ - make it a named control
; gestionnaire.add("Checkbox", 'Checked' SW.ticked, SW.name).Name := SW.Name ; alternative way
okbutton := gestionnaire.add("Button", "Default", "OK")
okbutton.OnEvent("Click", OK_click) ; OnEvent void return type
gestionnaire.show()
gestionnaire.OnEvent('Close', (*) => ExitApp())
OK_click(*)
{
NamedCtrlContents := gestionnaire.submit()
; gestionnaire.hide()
for SW in softwares
if NamedCtrlContents.%SW.name% ; equivalent to, eg: isChecked := NamedCtrlContents['ccleaner']
MsgBox SW.url
}
different way without using
.Submit()
Code: Select all
#Requires AutoHotkey v2.0-a137-f6f65742
gestionnaire := Gui()
softwares := [{name: "ccleaner", url: "https www.ccleaner.com /ccleaner/download/standard", ticked: 0}
,{name: "adwcleaner", url: "https downloads.malwarebytes.com /file/adwcleaner", ticked: 0}]
Checkboxes := []
for SW in softwares
{
CB := gestionnaire.add("Checkbox", 'Checked' SW.ticked, SW.name)
CB.url := SW.url ; attach this value property as extra data to be carried around and used later
CB.DefineProp('ticked', Gui.Control.Prototype.GetOwnPropDesc('Value')) ; alias CB.ticked to CB.Value
CB.DefineProp('name', Gui.Control.Prototype.GetOwnPropDesc('Text')) ; alias CB.name to CB.Text
Checkboxes.Push(CB)
}
okbutton := gestionnaire.add("Button", "Default", "OK")
okbutton.OnEvent("Click", OK_click) ; OnEvent void return type
gestionnaire.show()
gestionnaire.OnEvent('Close', (*) => ExitApp())
OK_click(*)
{
; gestionnaire.hide()
for CB in Checkboxes
if CB.ticked
MsgBox CB.url
}
.OnEvent() doesnt return anything, so writing:
Code: Select all
okbutton := gestionnaire.add("Button", "Default", "OK").OnEvent("Click", OK_click)
and expecting an object of type Gui.Control.Button to be stored in
okbutton is an error. the variable is blank