AHK-v2-script-converter
AHK-v2-script-converter copied to clipboard
Assumed automatic g-labels not converted with multiple GUIs
From docs:
If a button lacks an explicit g-label, an automatic label is assumed. For example, if the first GUI window contains an OK button, the ButtonOK label (if it exists) will be launched when the button is pressed. For GUI windows other than the first, the window number is included in front of the button's automatic label; for example: 2ButtonOK.
Needs to handle both labels and functions, and multiple guis
Example 1
V1:
Gui1Pos := A_ScreenHeight // 2 * 0.7
Gui, Add, Button,, Button 1
Gui, Add, Button, ys, Button 2
Gui, Show, y%Gui1Pos%
Gui, New
Gui, Add, Button,, Button 3
Gui, Add, Button, ys, Button 4
Gui, Add, Button, ys, Button 5
Gui, Show
Return
ButtonButton1() {
MsgBox, First Button Pressed
Return
}
ButtonButton2:
MsgBox, Second Button Pressed
Return
ButtonButton3:
MsgBox, Third Button Pressed
Return
ButtonButton4() {
MsgBox, Fourth Button Pressed via %A_GuiEvent%
Return
}
V2 (Converted):
Gui1Pos := A_ScreenHeight // 2 * 0.7
myGui := Gui()
ogcButtonButton1 := myGui.Add("Button", , "Button 1")
ogcButtonButton1.OnEvent("Click", ButtonButton1.Bind("Normal"))
ogcButtonButton2 := myGui.Add("Button", "ys", "Button 2")
ogcButtonButton2.OnEvent("Click", ButtonButton2.Bind("Normal"))
myGui.Show("y" . Gui1Pos)
myGui1 := Gui()
ogcButtonButton3 := myGui1.Add("Button", , "Button 3")
ogcButtonButton3.OnEvent("Click", myGui1ButtonButton3.Bind("Normal"))
ogcButtonButton4 := myGui1.Add("Button", "ys", "Button 4")
ogcButtonButton4.OnEvent("Click", myGui1ButtonButton4.Bind("Normal"))
ogcButtonButton5 := myGui1.Add("Button", "ys", "Button 5")
ogcButtonButton5.OnEvent("Click", myGui1ButtonButton5.Bind("Normal"))
myGui1.Show()
Return
ButtonButton1() {
MsgBox("First Button Pressed")
Return
}
ButtonButton2(A_GuiEvent := "", GuiCtrlObj := "", Info := "", *)
{ ; V1toV2: Added bracket
global ; V1toV2: Made function global
MsgBox("Second Button Pressed")
Return
} ; V1toV2: Added Bracket before label
ButtonButton3:
MsgBox("Third Button Pressed")
Return
ButtonButton4() {
MsgBox("Fourth Button Pressed via " A_GuiEvent)
Return
}
V2 (Expected):
Gui1Pos := A_ScreenHeight // 2 * 0.7
myGui := Gui()
ogcButtonButton1 := myGui.Add("Button", , "Button 1")
ogcButtonButton1.OnEvent("Click", ButtonButton1.Bind("Normal"))
ogcButtonButton2 := myGui.Add("Button", "ys", "Button 2")
ogcButtonButton2.OnEvent("Click", ButtonButton2.Bind("Normal"))
myGui.Show("y" . Gui1Pos)
myGui1 := Gui()
ogcButtonButton3 := myGui1.Add("Button", , "Button 3")
ogcButtonButton3.OnEvent("Click", ButtonButton3.Bind("Normal"))
ogcButtonButton4 := myGui1.Add("Button", "ys", "Button 4")
ogcButtonButton4.OnEvent("Click", ButtonButton4.Bind("Normal"))
ogcButtonButton5 := myGui1.Add("Button", "ys", "Button 5")
myGui1.Show()
Return
ButtonButton1(A_GuiEvent := "", GuiCtrlObj := "", Info := "", *) {
MsgBox("First Button Pressed")
Return
}
ButtonButton2(A_GuiEvent := "", GuiCtrlObj := "", Info := "", *)
{ ; V1toV2: Added bracket
global ; V1toV2: Made function global
MsgBox("Second Button Pressed")
Return
} ; V1toV2: Added Bracket before label
ButtonButton3(A_GuiEvent := "", GuiCtrlObj := "", Info := "", *)
{ ; V1toV2: Added bracket
global ; V1toV2: Made function global
MsgBox("Third Button Pressed")
Return
} ; V1toV2: Added Bracket before label
ButtonButton4(A_GuiEvent := "", GuiCtrlObj := "", Info := "", *) {
MsgBox("Fourth Button Pressed via " A_GuiEvent)
Return
}