I have a GUI that can be activated up to 6 times, and my goal is that when one of the windows is closed, the numbers in all the other Edit1's change according to the number of windows remaining. Right now I have only achieved that the numbers change in random order, as the array returned by WinGetList() doesn't store the HWNDs in the order the windows are opened. I tried to fix this with Map(), giving each HWND the correct number, but that didn't work for some reason and the for-loop still retrieved the numbers in the wrong order. It is very important for me to change the numbers correctly, as the next step I want to change the positioning of the windows based on these numbers.
Code: Select all
f::{
Static Order := 0, First := 0, Third := 0
if Order > 5 {
return
}
G := Gui('-MinimizeBox +Owner', 'Static Title'), G.SetFont('s15 bold', 'Arial')
G.Add('Edit', 'r1 w35 +Border +Center +Disabled', ++Order)
G.OnEvent('Close', Close), G.OnEvent('Escape', Close)
if !WinExist('ahk_class AutoHotkeyGUI') {
G.Show('w425 h285'), First := 1, Third := 1
}
else {
IDs := WinGetList('ahk_class AutoHotkeyGUI'), WinGetPos(&X, &Y, &W, &H, IDs[1])
(IDs.Length = 1) ? (First ? (WinMove(X-W/2+9,,,, IDs[1]), G.Show('w425 h285 x' X+W/2-9 ' y' Y), First := 0) : G.Show('w425 h285 x' X+W-17 ' y' Y)) :
(IDs.Length = 2) ? (Third ? (WinMove(, Y-H/2+4,,, IDs[1]), WinMove(, Y-H/2+4,,, IDs[2]), G.Show('w425 h285 x' X-W/2-8 ' y' Y+H/2-5), Third := 0) : G.Show('w425 h285 x' X-W/2-8 ' y' Y+H-9)) :
(IDs.Length = 3) ? (WinMove(X-W/2+27,,,, IDs[1]), G.Show('w425 h285 x' X+W/2+9 ' y' Y)) :
(IDs.Length = 4) ? G.Show('w425 h285 x' X-W*2+35 ' y' Y-H/2) :
(IDs.Length = 5) ? G.Show('w425 h285 x' X+W*3-52 ' y' Y) : ''
}
Close(*) {
--Order, G.Destroy()
for This_ID in IDsR := WinGetList('ahk_class AutoHotkeyGUI') { ; <----- Look here!
ControlSetText(IDsR.Length-A_Index+1, 'Edit1', This_ID)
}
}
}