; =================================================================================
; 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 := {}
For i, ctrl in cList {
ctrlID := A_Gui ":" ctrl
If ( cInfo[ctrlID].x = "" ){
GuiControlGet, i, %A_Gui%:Pos, %ctrl%
MMD := InStr(DimSize, "*") ? "MoveDraw" : "Move"
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
} } }
Re: AutoXYWH() - Move control automatically when GUI resized
Posted: 23 Dec 2013, 14:33
by gregster
As far as I know, StrSplit() - as a function - is relatively new to AHK (the corresponding command is older) . You probably need AHK 1.1.13.01, like it is mentioned in the script header. So, update...!
Re: AutoXYWH() - Move control automatically when GUI resized
Posted: 23 Dec 2013, 14:39
by Rindis
Thank. Now updated and its working
Cheers
Re: AutoXYWH() - Move control automatically when GUI resized
Posted: 25 Jun 2014, 13:41
by toralf
Dear tmplinshi,
your code is nice, but it doesn't support fractions of dimensions, e.g. w0.5 = control gets only half of the gui width change.
Have you considered to expend your function in this direction?
Re: AutoXYWH() - Move control automatically when GUI resized
Posted: 25 Jun 2014, 15:03
by joedf
Nice! @toralf true... But then, doesn't anchor do that?
Re: AutoXYWH() - Move control automatically when GUI resized
Posted: 25 Jun 2014, 15:37
by toralf
@joedf
Yes, but much more complicated. The lastest version of Anchor() is very complex code (i assume it got further optimized for speed). This version is simple and uses the latest features of AHK. And it allows to give a list of controls at once.
just before the function is called *not tested*. I assume in most cases this will not be nessecary, because the GuiSize thread will be set it's own Gui as the default. So only in the rare cases that you want to control a second gui size by resizing the first gui you would need to define a different default gui. (do not even know if that would work, since A_GuiWidth and A_GuiHeight would be of the first gui)
Does this makes sense?
Overall, I believe it is not required. Do you agree?
Re: AutoXYWH() - Move control automatically when GUI resized
Posted: 27 Jun 2014, 08:48
by just me
It's permitted to use the same vLabel and control text in different Guis. Also, ClassNNs like Edit1 or Button1 aren't necessarily unique. But only the first of two or more identical control identifiers will be stored, and possibly used for the wrong Gui. That's what I thought about.
Re: AutoXYWH() - Move control automatically when GUI resized
Posted: 28 Jun 2014, 12:11
by toralf
Good point. I'll fix it.
Re: AutoXYWH() - Move control automatically when GUI resized
Posted: 28 Jun 2014, 20:06
by toralf
I hope I fixed both of my two functions above. Could not test it yet, I'm only on my phone.
Re: AutoXYWH() - Move control automatically when GUI resized
Posted: 30 Jun 2014, 03:21
by just me
It's working on A32, U32, and U64.
Re: AutoXYWH() - Move control automatically when GUI resized
Posted: 01 Jul 2014, 14:36
by toralf
This version removes some of the flickering by reducing the MoveDraw to only controls of class 'Button' (since Groupboxes are of class 'Button').