Code: Select all
pressed:=MultiBox(obj:={buttonsArray:["YES","NO"],FocusButton:3,x:100,theme:"Grass",EditValues:["Today's theme is Grass"]})
Msgbox,,Which button pressed?,% "Entire Object:`n" Obj2String(pressed)
pressed:=MultiBox(obj:={buttonsArray:["YES","NO","CANCEL"],FocusButton:2,x:200,theme:"Citrus"})
Msgbox,,Which button pressed?,% "Entire Object:`n" Obj2String(pressed)
pressed:=MultiBox(obj:={FocusButton:1,x:300,theme:"Rustic",EditValues:["1st Edit value","","3rd value"]})
MultiBox(obj:="")
{
;https://www.autohotkey.com/boards/viewtopic.php?f=76&t=98120&p=435652#p435652
Static ONLYEDIT1, ONLYEDIT2, ONLYEDIT3
If !IsObject(obj)
obj:={}
defaultO:={buttonsArray:["YES","NO","CANCEL","CHOICE A","CHOICE B","CHOICE C","CHOICE X"] ; Function will have default values determined here, unless specified by user
,title:"Default Title"
,MsgText:"Text to appear in GUI Msgbox"
,x:""
,y:""
,focusButton:1
,GuiName:"Questions"
,fontSize:10
,backgroundC:"548CFF"
,textC:"CFFFDC"
,font:"Calibri"
,Theme:"Sky"
,EditValues:["Bill Clinton","Donald Trump","Joe Biden"]
,EditRows:2
,EditWidth:300
,NumberOfEdits:3}
For key, value in defaultO
{
If (obj[key]="")
obj[key]:=defaultO[key]
}
; Msgbox,% Obj2String(obj) "`n`n`nCode line #:" 93
NumberOfButtons:=obj.buttonsArray.count()
Switch obj.Theme
{
case "sky":
obj.backgroundC:="7900FF"
obj.textC:="93FFD8"
Case "Citrus":
obj.backgroundC:="EA5C2B"
obj.textC:="F6D860"
Case "Grass":
obj.backgroundC:="146356"
obj.textC:="A3DA8D"
Case "Rustic":
obj.backgroundC:="8E806A"
obj.textC:="FFE6BC"
}
Gui,% obj.GuiName ":New", +LastFound +AlwaysOnTop
Gui, color,% obj.backgroundC
Gui, Font,% "s" obj.fontSize " c" obj.textC,% obj.font
Gui, Add, Text,,% obj.MsgText
Gui, Font, cBLACK
Loop,% obj.NumberOfEdits
Gui, Add, Edit,% "vONLYEDIT" A_Index " y+m w" obj.EditWidth " r" obj.EditRows, % obj.EditValues[A_Index]
Loop,% NumberOfButtons
{
If (A_Index=1)
Gui, Add, Button, gPUSHED xm y+m w120, % obj.ButtonsArray[A_Index]
Else
Gui, Add, Button, gPUSHED x+m wp , % obj.ButtonsArray[A_Index]
}
GuiControl, +Default,% "Button" obj.focusButton
GuiControl, Focus,% "Button" obj.focusButton
Gui, Show, % (obj.x > "" ? "x" obj.x : "") (obj.y > "" ? " y" obj.y : ""),% obj.title
WinWaitClose
SetTimer,CloseResultXYZ,300
resultobj:={button:button}
edits:=[]
Loop,% obj.NumberOfEdits
{
edits.push(ONLYEDIT%A_Index%)
}
resultobj["edits"]:=edits
Return resultobj
PUSHED:
Gui,% obj.GuiName ": Submit", NoHide
button := A_GuiControl
EditValue:=ONLYEDIT
Gui,% obj.GuiName ":Destroy"
Return
CloseResultXYZ:
WinClose, Result XYZ
SetTimer,CloseResultXYZ,OFF
Return
}
}
Obj2String(Obj,FullPath:=1,BottomBlank:=0){
static String,Blank
if(FullPath=1)
String:=FullPath:=Blank:=""
if(IsObject(Obj)){
for a,b in Obj{
if(IsObject(b))
Obj2String(b,FullPath "." a,BottomBlank)
else{
if(BottomBlank=0)
String.=FullPath "." a " = " b "`n"
else if(b!="")
String.=FullPath "." a " = " b "`n"
else
Blank.=FullPath "." a " =`n"
}
}}
Else ; returns the value even if not an obj
String:=obj "`n`n`nobj2string: Not an object" ; but says it is not an object
return String Blank
}