if cancelled, the return value will be "Cancel".
The same concept can be used for every control, or multiple controls (it that case, I would return an object containing the values.)
If somebody has a different approach, please share it, I use an object to be able to modify the return value when cancelling, but maybe there is a more proper way.
Code: Select all
#Requires AutoHotkey v2.0
InputBoxDropDownList(Prompt,Title?,Options?,aChoices?, VarDefault?){
oValues := Object() ; allows to return
DDLGui := Gui(Options ?? Unset, Title ?? Unset)
(IsSet(Prompt)) ? DDLGui.AddText(,Prompt) : ""
ogDDL := DDLGui.AddDropDownList("w160 vNewValue", aChoices ?? [] )
(IsSet(VarDefault)) ? ogDDL.Text := VarDefault : ""
DDLGui.AddButton("w75","OK").OnEvent("Click", (*)=>(oValues := DDLGui.Submit()))
DDLGui.AddButton("yp x+10 w75","Cancel").OnEvent("Click", (*)=>(oValues.NewValue:="Cancel", DDLGui.Destroy()))
DDLGui.OnEvent("Close", (*)=>(oValues.NewValue:="Cancel", DDLGui.Destroy()))
DDLGui.Show()
WinWaitClose(DDLGui)
return oValues.NewValue
}