Skip to content

Commit

Permalink
fix +hwnd in gui new
Browse files Browse the repository at this point in the history
see #281
  • Loading branch information
Banaanae committed Aug 19, 2024
1 parent c159227 commit 1cf8bd6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
13 changes: 9 additions & 4 deletions ConvertFuncs.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -1702,6 +1702,7 @@ _Gui(p) {
ControlLabel := ""
ControlName := ""
ControlObject := ""
GuiOpt := ""

if (p[1] = "New" && gGuiList != "") {
if (!InStr(gGuiList, gGuiNameDefault)) {
Expand Down Expand Up @@ -1759,8 +1760,7 @@ _Gui(p) {
}
}
}
if (RegExMatch(Var3, "i)\b\+?\bhwnd[\w]*\b")) {
RegExMatch(Var3, "i)\+?HWND(.*?)(?:\s|$)", &match)
if (RegExMatch(Var3, "i)\+?HWND(.*?)(?:\s|$)", &match)) {
ControlHwnd := match[1]
Var3 := StrReplace(Var3, match[])
if (ControlObject = "" && Var4 != "") {
Expand All @@ -1771,11 +1771,16 @@ _Gui(p) {
}
gmGuiCtrlObj["%" ControlHwnd "%"] := ControlObject
gmGuiCtrlObj["% " ControlHwnd] := ControlObject
} else if (RegExMatch(Var2, "i)\+?HWND(.*?)(?:\s|$)", &match))
&& (RegExMatch(Var1, "i)(?<!\w)New")) {
GuiOpt := Var3
GuiOpt := StrReplace(GuiOpt, match[])
LineSuffix .= gIndentation match[1] " := " GuiNameLine ".Hwnd"
}

if (!InStr(gGuiList, "|" GuiNameLine "|")) {
gGuiList .= GuiNameLine "|"
LineResult := GuiNameLine " := Gui()`r`n" gIndentation
LineResult := GuiNameLine " := Gui(" GuiOpt ")`r`n" gIndentation

; Add the events if they are used.
aEventRename := []
Expand Down Expand Up @@ -1854,7 +1859,7 @@ _Gui(p) {
var1 := "SetFont"
gGuiActiveFont := ToStringExpr(Var2) ", " ToStringExpr(Var3)
} else if (var1 = "New") {
return Trim(LineResult,"`n")
return Trim(LineResult LineSuffix,"`n")
}

LineResult .= GuiNameLine "."
Expand Down
15 changes: 15 additions & 0 deletions tests/Test_Folder/Graphical User Interfaces/Gui-Hwnd_ex4.ah1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Gui, Add, Text,, Gui 1`nNormal
Gui, +HWNDv1
Gui, Show, w100 h100 y0
Gui, New, +hwndv2
Gui, Add, Text,, Gui 2`nNew
Gui, Show, w100 h100 y150
Gui, g2:New, +hwndv3
Gui, g2:Add, Text,, Gui 3`nName:New
Gui, g2:Show, w100 h100 y300
Gui, g3: New, +hwndv4
Gui, g3: Add, Text,, Gui 4`nName: New
Gui, g3: Show, w100 h100 y450
Return

^l::MsgBox % v1 "`n" v2 "`n" v3 "`n" v4
19 changes: 19 additions & 0 deletions tests/Test_Folder/Graphical User Interfaces/Gui-Hwnd_ex4.ah2
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
myGui := Gui()
myGui.Add("Text", , "Gui 1`nNormal")
v1 := myGui.Hwnd
myGui.Show("w100 h100 y0")
myGui1 := Gui()
v2 := myGui1.Hwnd
myGui1.Add("Text", , "Gui 2`nNew")
myGui1.Show("w100 h100 y150")
g2 := Gui()
v3 := g2.Hwnd
g2.Add("Text", , "Gui 3`nName:New")
g2.Show("w100 h100 y300")
g3 := Gui()
v4 := g3.Hwnd
g3.Add("Text", , "Gui 4`nName: New")
g3.Show("w100 h100 y450")
Return

^l::MsgBox(v1 "`n" v2 "`n" v3 "`n" v4)

0 comments on commit 1cf8bd6

Please sign in to comment.