I tried
Code: Select all
AutoXYWH("wh", sc.hwnd)
; or
AutoXYWH("wh", "ahk_id " sc.hwnd)
Code: Select all
AutoXYWH("wh", sc.hwnd)
; or
AutoXYWH("wh", "ahk_id " sc.hwnd)
Code: Select all
Gui, +Resize
Gui, Margin , 5, 5
Gui, Add, Button, w90 h30 vBtn1, Button1
Gui, Add, Button, x+ w90 h30 vBtn2, Button2
Gui, Add, Button, x+ w50 h30 vBtn3, Button3
Gui, Add, Button, x+ w90 h30 vBtn4, Button4
Gui, Add, Button, x+ w90 h30 vBtn5, Button5
Gui, Add, Button, x+ w130 h30 vBtn6, Button6
Gui, Show, h50 w550, Buttons in a row
return
GuiClose:
ExitApp
return
Guisize:
;for six buttons
Btns := []
Loop, 6
Btns.Insert("btn" . A_Index)
AutoXYWH("r", Btns*)
;AutoXYWH("r h", Btns*)
;AutoXYWH("r y", Btns*)
;AutoXYWH("r", "Btn1","Btn2","Btn3","Btn4","Btn5","Btn6")
return
; =================================================================================
; Function: AutoXYWH
; Move and resize control automatically when GUI resizes.
; Parameters:
; DimSize - Can be one or more of x/y/w/h optional followed by a fraction
; add a '*' to DimSize to 'MoveDraw' the controls rather then just 'Move', this is recommended for Groupboxes
; cList - variadic list of ControlIDs
; ControlID can be a control HWND, associated variable name, ClassNN or displayed text.
; The later (displayed text) is possible but not recommend since not very reliable
; Examples:
; AutoXYWH("xy", "Btn1", "Btn2")
; AutoXYWH("w0.5 h 0.75", hEdit, "displayed text", "vLabel", "Button1")
; AutoXYWH("*w0.5 h 0.75", hGroupbox1, "GrbChoices")
; ---------------------------------------------------------------------------------
; Version: 2015-5-29 / Added 'reset' option (by tmplinshi)
; 2014-7-03 / toralf
; 2014-1-2 / tmplinshi
; requires AHK version : 1.1.13.01+
; =================================================================================
AutoXYWH(DimSize, cList*){ ; http://ahkscript.org/boards/viewtopic.php?t=1079
static cInfo := {}
;MsgBox, % "dimsize" DimSize
If (DimSize = "reset")
Return cInfo := {}
; ==========
IF (DimSize = "r")
{
MI := cList.MaxIndex()
Row:=[]
Row.Insert("w" . 1/cList.MaxIndex() )
Loop, % cList.MaxIndex()-1
Row.Insert("x" . A_Index/cList.MaxIndex() . " w" . 1/cList.MaxIndex() )
}
; ==========
For i, ctrl in cList {
ctrlID := A_Gui ":" ctrl
If ( cInfo[ctrlID].x = "" ){
GuiControlGet, i, %A_Gui%:Pos, %ctrl%
MMD := InStr(DimSize, "*") ? "MoveDraw" : "Move"
; ==========
DimSize := IsObject(Row) ? Row[i] : DimSize
; ==========
fx := fy := fw := fh := 0
For i, dim in (a := StrSplit(RegExReplace(DimSize, "i)[^xywh]")))
If !RegExMatch(DimSize, "i)" dim "\s*\K[\d.-]+", f%dim%)
f%dim% := 1
cInfo[ctrlID] := { x:ix, fx:fx, y:iy, fy:fy, w:iw, fw:fw, h:ih, fh:fh, gw:A_GuiWidth, gh:A_GuiHeight, a:a , m:MMD}
}Else If ( cInfo[ctrlID].a.1) {
dgx := dgw := A_GuiWidth - cInfo[ctrlID].gw , dgy := dgh := A_GuiHeight - cInfo[ctrlID].gh
For i, dim in cInfo[ctrlID]["a"]
Options .= dim (dg%dim% * cInfo[ctrlID]["f" dim] + cInfo[ctrlID][dim]) A_Space
GuiControl, % A_Gui ":" cInfo[ctrlID].m , % ctrl, % Options
} } }
Code: Select all
Gui, +Resize
Gui, Margin , 5, 5
Gui, Add, Edit, w90 h30 vEdts1, Edits1
Gui, Add, Edit, x+ w90 h30 vEdts2, Edits2
Gui, Add, Edit, x+ w50 h30 vEdts3, Edits3
Gui, Add, Edit, x+ w90 h30 vEdts4, Edits4
Gui, Add, Edit, x+ w90 h30 vEdts5, Edits5
Gui, Add, Edit, x+ w130 h30 vEdts6, Edits6
Gui, Add, Button, x5 y50 w90 h30 vBtn1, Button1
Gui, Add, Button, x+ y50 w90 h30 vBtn2, Button2
Gui, Add, Button, x+ y50 w50 h30 vBtn3, Button3
Gui, Add, Button, x+ y50 w90 h30 vBtn4, Button4
Gui, Add, Button, x+ y50 w90 h30 vBtn5, Button5
Gui, Add, Button, x+ y50 w130 h30 vBtn6, Button6
Gui, Show, h150 w550, Edits in a row
return
GuiClose:
ExitApp
return
Guisize:
;for six Edits
edts := []
Btns := []
Loop, 6
edts.Insert("edts" . A_Index), Btns.Insert("btn" . A_Index)
AutoXYWH("r h", edts*)
AutoXYWH("r y", Btns*)
;AutoXYWH("r h", "edts1","edts2","edts3","edts4","edts5","edts6")
return
; =================================================================================
; Function: AutoXYWH
; Move and resize control automatically when GUI resizes.
; Parameters:
; DimSize - Can be one or more of x/y/w/h optional followed by a fraction
; add a '*' to DimSize to 'MoveDraw' the controls rather then just 'Move', this is recommended for Groupboxes
; cList - variadic list of ControlIDs
; ControlID can be a control HWND, associated variable name, ClassNN or displayed text.
; The later (displayed text) is possible but not recommend since not very reliable
; Examples:
; AutoXYWH("xy", "Btn1", "Btn2")
; AutoXYWH("w0.5 h 0.75", hEdit, "displayed text", "vLabel", "Button1")
; AutoXYWH("*w0.5 h 0.75", hGroupbox1, "GrbChoices")
; ---------------------------------------------------------------------------------
; Version: 2015-5-29 / Added 'reset' option (by tmplinshi)
; 2014-7-03 / toralf
; 2014-1-2 / tmplinshi
; requires AHK version : 1.1.13.01+
; =================================================================================
AutoXYWH(DimSize, cList*){ ; http://ahkscript.org/boards/viewtopic.php?t=1079
static cInfo := {}
If (DimSize = "reset")
Return cInfo := {}
;==========
dms:= strReplace(DimSize,"r","")
;==========
For i, ctrl in cList {
ctrlID := A_Gui ":" ctrl
If ( cInfo[ctrlID].x = "" ){
GuiControlGet, i, %A_Gui%:Pos, %ctrl%
MMD := InStr(DimSize, "*") ? "MoveDraw" : "Move"
; ==========
Row := (i=1) ? "w" . 1/cList.MaxIndex() : "x" . (i-1)/cList.MaxIndex() . " w" . 1/cList.MaxIndex() . " "
IF (InStr(DimSize, "r"))
DimSize:=dms . " " . Row . " r"
; ==========
fx := fy := fw := fh := 0
For i, dim in (a := StrSplit(RegExReplace(DimSize, "i)[^xywh]")))
If !RegExMatch(DimSize, "i)" dim "\s*\K[\d.-]+", f%dim%)
f%dim% := 1
cInfo[ctrlID] := { x:ix, fx:fx, y:iy, fy:fy, w:iw, fw:fw, h:ih, fh:fh, gw:A_GuiWidth, gh:A_GuiHeight, a:a , m:MMD}
}Else If ( cInfo[ctrlID].a.1) {
dgx := dgw := A_GuiWidth - cInfo[ctrlID].gw , dgy := dgh := A_GuiHeight - cInfo[ctrlID].gh
For i, dim in cInfo[ctrlID]["a"]
Options .= dim (dg%dim% * cInfo[ctrlID]["f" dim] + cInfo[ctrlID][dim]) A_Space
GuiControl, % A_Gui ":" cInfo[ctrlID].m , % ctrl, % Options
} } }
Code: Select all
Call to nonexistent function.
For i, dim in (a := StrSplit(RegExReplace(DimSize, "i)[^xywh]")))
Code: Select all
Error: Call to nonexistent function.
Specifically: ACH := StrSplit(CH, "`n"), ACN := StrSplit(CN, "`n")
Code: Select all
#NoEnv
#Persistent
#SingleInstance force
#Include, AutoXYWH.ahk
Gui, +Resize
Gui, Margin, , 20
Gui, Add, GroupBox, x10 y5 w200 h100 Section vGB1, GB1
Gui, Add, Edit, xs+10 ys+21 ve1 w150 h70
Gui, Add, GroupBox, x10 y+m w200 h100 Section vGB2, GB2
Gui, Add, Edit, xs+10 ys+21 ve2 w150 h70
Gui, Show
return
GuiSize:
If (A_EventInfo = 1) ; The window has been minimized.
Return
AutoXYWH("*wh", "GB1")
AutoXYWH("*ywh", "GB2")
AutoXYWH("wh", "e1")
AutoXYWH("ywh", "e2")
return
Code: Select all
GuiSize:
If (A_EventInfo = 1) ; The window has been minimized.
Return
AutoXYWH("*wh0.5", "GB1")
AutoXYWH("*y0.5wh0.5", "GB2")
AutoXYWH("wh0.5", "e1")
AutoXYWH("y0.5wh0.5", "e2")
return
Code: Select all
#Include, AutoXYWH.ahk
Gui, +Resize
Gui, Add, Edit, ve1 w150 h30
Gui, Add, Edit, ve2 x+10 w150 h30
Gui, Add, Edit, ve3 x10 w150 h30
Gui, Add, Button, vb1 gResize, Resize
Gui, Show
return
Resize:
GuiControl, Move, e1, h30
GuiControl, Move, e2, h30
GuiControl, Move, e3, h30
AutoXYWH("reset") ; Needs to reset if you changed the Control size manually.
return
GuiSize:
If (A_EventInfo = 1) ; The window has been minimized.
Return
AutoXYWH("wh", "e1")
AutoXYWH("y", "b1")
AutoXYWH("wh", "e2")
AutoXYWH("y", "b2")
AutoXYWH("wh", "e3")
AutoXYWH("y", "b3")
return
Code: Select all
#NoEnv
#SingleInstance, Force
#Include, AutoXYWH.ahk
Gui, +Resize +MinSize
Gui, Add, Edit, ve1 w150 h30
Gui, Add, Edit, ve2 x+10 w150 h30
Gui, Add, Edit, ve3 x10 w150 h30
Gui, Add, Button, vb1, Test
Gui, Show
return
GuiSize:
If (A_EventInfo = 1) ; The window has been minimized.
Return
AutoXYWH("w0.5h0.5", "e1")
AutoXYWH("x0.5w0.5h0.5", "e2")
AutoXYWH("y0.5w0.5h0.5", "e3")
AutoXYWH("*y", "b1")
return
Wonderingahklearner wrote:but not changing height of 1st and 2nd edit box.
Code: Select all
AutoXYWH("w0.5", "e1")
AutoXYWH("x0.5w0.5", "e2")
AutoXYWH("y+10.5w0.5h0.5", "e3")
AutoXYWH("*y", "b1")
Code: Select all
}Else If ( cInfo[ctrlID].a.1) {
dgx := dgw := A_GuiWidth - cInfo[ctrlID].gw , dgy := dgh := A_GuiHeight - cInfo[ctrlID].gh
For i, dim in cInfo[ctrlID]["a"]
Options .= dim (dg%dim% * cInfo[ctrlID]["f" dim] + cInfo[ctrlID][dim]) A_Space
GuiControl, % A_Gui ":" cInfo[ctrlID].m , % ctrl, % Options
}
Return to “Scripts and Functions (v1)”
Users browsing this forum: tiska and 179 guests