Ok I did it
Now the button appears after 2 seconds and stays in perfect position when the window is resized.
Can somebody have a look and potentially improve?
Code: Select all
guiW := 600
guiH := 600
margin := 10
editW := guiW - (margin*2)
editH := guiH - (margin*2)
buttonID := 0
Gui, 1:New, +Resize +MinSize%guiW%x%guiH% +hwndguiID, Insert notes ; hwndID stores the GUI ID into "guiID" variable.
Gui, 1:Add, Edit, r2 vMyEdit hwndeditID VScroll w%editW% h%editH% ; adds the Edit control, and stores it's hwnd into "editID" variable.
Gui, Show, w%guiW% h%guiH%
Sleep, 2000
GetClientSize(guiID, guiW, guiH)
ControlGetPos, , , , editH, , ahk_id %editID%
buttonW := 70
buttonH := 30
buttonX := guiW - buttonW - (margin)
buttonY := guiH - buttonH - (margin)
buttonSpaceH := buttonH + (margin*2)
Gui, 1:Add, Button, Default x%buttonX% y%buttonY% w%buttonW% h%buttonH% hwndbuttonID, OK
GuiControl, Move, %editID%, % "W" . (guiW-(margin*2)) . "H" . (guiH-buttonSpaceH-margin) . "X" . (margin) . "Y" . (margin)
return
GuiSize:
If (A_EventInfo = 1)
return
If (buttonID)
{
GuiControl, 1:Move, %editID%, % "H" . (A_GuiHeight-buttonSpaceH-margin) . " W" . (A_GuiWidth-margin*2)
GuiControl, 1:Move, %buttonID%, % "X" . (A_GuiWidth-buttonW-margin) . " Y" . (A_GuiHeight-buttonH-margin)
return
}
GuiControl, 1:Move, %editID%, % "H" . (A_GuiHeight-margin*2) . " W" . (A_GuiWidth-margin*2)
return
GetClientSize(hwnd, ByRef w, ByRef h) ; by jNizM, https://autohotkey.com/board/topic/91733-command-to-get-gui-client-areas-sizes/
{
VarSetCapacity(rc, 16)
DllCall("GetClientRect", "uint", hwnd, "uint", &rc)
w := NumGet(rc, 8, "int")
h := NumGet(rc, 12, "int")
}