Attach( hCtrl = "", aDef = "" )
Determines how a control is resized with its parent.
Attach definition string. Space separated list of attach options. If omitted, function working depends on hCtrl parameter. You can use following elements in the definition string:
Function monitors WM_SIZE message to detect parent changes. That means that it can be used with other eventual container controls and not only top level windows.
You should reset the function when you programmatically change the position of the controls in the parent control. Depending on how you created your GUI, you might need to put “autosize” when showing it, otherwise resetting the Gui before its placement is changed will not work as intented. Autosize will make sure that WM_SIZE handler fires. Sometimes, however, WM_SIZE message isn’t sent to the window. One example is for instance when some control requires Gui size to be set in advance in which case you would first have “Gui, Show, w100 h100 Hide” line prior to adding controls, and only Gui, Show after controls are added. This case will not trigger WM_SIZE message unless AutoSize is added.
Attach(h, "w.5 h1/3 r2") ;Attach control's w, h and redraw it with delay. Attach(h, "-") ;Disable function for control h but keep its definition. To enable it latter use "+". Attach(h, "- w.5") ;Make attach definition for control but do not attach it until you call Attach(h, "+"). Attach() ;Reset first parent. Use when you have only 1 parent. Attach(hGui2) ;Reset Gui2. Attach("Win_Redraw") ;Use Win_Redraw function as a Handler. Attach will call it with parent's handle as argument. Attach(h, "p r2") ;Pin control with delayed refreshing. ; This is how to do delayed refresh of entire window. ; To prevent redraw spam which can be annoying in some cases, ; you can choose to redraw entire window only when user has finished resizing it. ; This is similar to r2 option for controls, except it works with entire parent. Attach("OnAttach") ;Set Handler to OnAttach function ... OnAttach( Hwnd ) { global hGuiToRedraw := hwnd SetTimer, Redraw, -100 } Redraw: Win_Redraw(hGuiToRedraw) return
Working sample:
#SingleInstance, force Gui, +Resize Gui, Add, Edit, HWNDhe1 w150 h100 Gui, Add, Picture, HWNDhe2 w100 x+5 h100, pic.bmp Gui, Add, Edit, HWNDhe3 w100 xm h100 Gui, Add, Edit, HWNDhe4 w100 x+5 h100 Gui, Add, Edit, HWNDhe5 w100 yp x+5 h100 gosub SetAttach ;comment this line to disable Attach Gui, Show, autosize return SetAttach: Attach(he1, "w.5 h") Attach(he2, "x.5 w.5 h r") Attach(he3, "y w1/3") Attach(he4, "y x1/3 w1/3") Attach(he5, "y x2/3 w1/3") return