<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Позиционирование]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=4498&amp;type=atom" />
	<updated>2010-12-28T16:23:41Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=4498</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=43162#p43162" />
			<content type="html"><![CDATA[<p>То что надо. Благодарю.</p>]]></content>
			<author>
				<name><![CDATA[InFlames]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24849</uri>
			</author>
			<updated>2010-12-28T16:23:41Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=43162#p43162</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=43161#p43161" />
			<content type="html"><![CDATA[<p><a href="http://www.autohotkey.com/docs/commands/Gui.htm#Options">Gui, +/-Option1 +/-Option2 ...</a><br /><em>MinSize</em> and <em>MaxSize</em></p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2010-12-28T16:15:06Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=43161#p43161</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=43160#p43160" />
			<content type="html"><![CDATA[<p>Можно ли в данном случае сделать так, что бы окно не сжималось меньше заданного значения.<br />Что бы были видны обе кнопки и хотя бы строк 5 элемента ListView.</p><p>Примерно вот такой размер был бы минимальным.</p><p><span class="postimg"><img src="http://content.screencast.com/users/ktp/folders/Jing/media/20287ac8-9710-411d-8a24-681c1031e30f/2010-12-28_1902.png" alt="http://content.screencast.com/users/ktp/folders/Jing/media/20287ac8-9710-411d-8a24-681c1031e30f/2010-12-28_1902.png" /></span></p><br /><br /><div class="codebox"><pre><code>    gui default
    Gui Add, ListView, x10 y0 vlv AltSubmit grid -LV0x10 r10 NoSort NoSortHdr, 1|2|3
    Gui add, button,  x10 y+10 w100 h35, Удалить выделенные
    Gui add, button,  x+10 yp wp hp, Открыть .INI
    gui +resize
    Gui show, AutoSize
Return

GuiSize:
   Anchor(&quot;lv&quot;, &quot;wh&quot;)
   Anchor(&quot;button1&quot;, &quot;y&quot;, 1)
   Anchor(&quot;button2&quot;, &quot;y&quot;, 1)
Return

buttonУдалитьвыделенные:
Return

guiclose:
ExitApp
Return


Anchor(i, a = &quot;&quot;, r = false) {
    static c, cs = 12, cx = 255, cl = 0, g, gs = 8, gl = 0, gpi, gw, gh, z = 0, k = 0xffff
    If z = 0
        VarSetCapacity(g, gs * 99, 0), VarSetCapacity(c, cs * cx, 0), z := true
    If (!WinExist(&quot;ahk_id&quot; . i)) {
        GuiControlGet, t, Hwnd, %i%
        If ErrorLevel = 0
            i := t
        Else ControlGet, i, Hwnd, , %i%
    }
    VarSetCapacity(gi, 68, 0), DllCall(&quot;GetWindowInfo&quot;, &quot;UInt&quot;, gp := DllCall(&quot;GetParent&quot;, &quot;UInt&quot;, i), &quot;UInt&quot;, &amp;gi)
        , giw := NumGet(gi, 28, &quot;Int&quot;) - NumGet(gi, 20, &quot;Int&quot;), gih := NumGet(gi, 32, &quot;Int&quot;) - NumGet(gi, 24, &quot;Int&quot;)
    If (gp != gpi) {
        gpi := gp
        Loop, %gl%
            If (NumGet(g, cb := gs * (A_Index - 1)) == gp) {
                gw := NumGet(g, cb + 4, &quot;Short&quot;), gh := NumGet(g, cb + 6, &quot;Short&quot;), gf := 1
                Break
            }
        If (!gf)
            NumPut(gp, g, gl), NumPut(gw := giw, g, gl + 4, &quot;Short&quot;), NumPut(gh := gih, g, gl + 6, &quot;Short&quot;), gl += gs
    }
    ControlGetPos, dx, dy, dw, dh, , ahk_id %i%
    Loop, %cl%
        If (NumGet(c, cb := cs * (A_Index - 1)) == i) {
            If a =
            {
                cf = 1
                Break
            }
            giw -= gw, gih -= gh, as := 1, dx := NumGet(c, cb + 4, &quot;Short&quot;), dy := NumGet(c, cb + 6, &quot;Short&quot;)
                , cw := dw, dw := NumGet(c, cb + 8, &quot;Short&quot;), ch := dh, dh := NumGet(c, cb + 10, &quot;Short&quot;)
            Loop, Parse, a, xywh
                If A_Index &gt; 1
                    av := SubStr(a, as, 1), as += 1 + StrLen(A_LoopField)
                        , d%av% += (InStr(&quot;yh&quot;, av) ? gih : giw) * (A_LoopField + 0 ? A_LoopField : 1)
            DllCall(&quot;SetWindowPos&quot;, &quot;UInt&quot;, i, &quot;Int&quot;, 0, &quot;Int&quot;, dx, &quot;Int&quot;, dy
                , &quot;Int&quot;, InStr(a, &quot;w&quot;) ? dw : cw, &quot;Int&quot;, InStr(a, &quot;h&quot;) ? dh : ch, &quot;Int&quot;, 4)
            If r != 0
                DllCall(&quot;RedrawWindow&quot;, &quot;UInt&quot;, i, &quot;UInt&quot;, 0, &quot;UInt&quot;, 0, &quot;UInt&quot;, 0x0101) ; RDW_UPDATENOW | RDW_INVALIDATE
            Return
        }
    If cf != 1
        cb := cl, cl += cs
    bx := NumGet(gi, 48), by := NumGet(gi, 16, &quot;Int&quot;) - NumGet(gi, 8, &quot;Int&quot;) - gih - NumGet(gi, 52)
    If cf = 1
        dw -= giw - gw, dh -= gih - gh
    NumPut(i, c, cb), NumPut(dx - bx, c, cb + 4, &quot;Short&quot;), NumPut(dy - by, c, cb + 6, &quot;Short&quot;)
        , NumPut(dw, c, cb + 8, &quot;Short&quot;), NumPut(dh, c, cb + 10, &quot;Short&quot;)
    Return, true
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[InFlames]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24849</uri>
			</author>
			<updated>2010-12-28T16:04:11Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=43160#p43160</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=35999#p35999" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>YMP пишет:</cite><blockquote><p>А в прошлом примере с Anchor всё-таки не наезжают, а только смыкаются.</p></blockquote></div><p>Да это просто у меня минимально возможная ширина окна меньше, чем у вас. Думаю, она зависит от толщины строки заголовка окон, её можно менять в свойствах экрана.<br /></p><div class="quotebox"><cite>InFlames пишет:</cite><blockquote><p>Не хватает кнопочки копировать весь код, или хотя бы выделения по двойному или тройному клику всего кода. Не очень удобно копировать длинный код.</p></blockquote></div><p><a href="http://forum.script-coding.com/viewtopic.php?pid=19466">Вот</a> решение для Firefox.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2010-05-21T16:53:00Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=35999#p35999</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=35997#p35997" />
			<content type="html"><![CDATA[<p>У меня так же. А в прошлом примере с Anchor всё-таки не наезжают, а только смыкаются. Возможно, тут что-то ещё припутывается.</p><div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>Даже если контролов и много, то 10-15 строчек под одной меткой GuiSize не сильно засорят программу!</p></blockquote></div><p>У меня и 100-150 строчек не засорят, лишь бы работало. Но я подал это в преломлении <strong>Resager</strong>&#039;a. Клиент же всегда прав. Вообще, мысль, что код засоряет программу мне понравилась. Свежая мысль. Действительно, программы должны сами работать, без этого противного кода, от которого рябит в глазах и болит в мозгах. Долой код из программ! <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p><div class="quotebox"><cite>InFlames пишет:</cite><blockquote><p>Не хватает кнопочки копировать весь код, или хотя бы выделения по двойному или тройному клику всего кода. Не очень удобно копировать длинный код.</p></blockquote></div><p>В IE тройной клик работает, а также одиночный при удержании Ctrl. Точнее, в Avant Browser, но он ведь только оболочка, вероятно, это функционал IE.</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2010-05-21T16:27:09Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=35997#p35997</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=35993#p35993" />
			<content type="html"><![CDATA[<p>Теперь в первом случае <a href="http://screencast.com/t/MGIyYzRhYjct">так</a>, а во втором <a href="http://screencast.com/t/ZDA4ODQ1NDgt">так</a>.</p><p>оффтоп:<br />1. Не хватает кнопочки копировать весь код, или хотя бы выделения по двойному или тройному клику всего кода. Не очень удобно копировать длинный код.<br />2. Да и вообще этот холивар про универсальность кода конечно имеет право на существование, но в данном случае я считаю, каждый для себя выбирает более легкий и понятный путь. AHK вообще в некоторых местах не заточен под некоторые фишки, и приходится писать кучу кода ради какой-то мелочи.</p>]]></content>
			<author>
				<name><![CDATA[InFlames]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24849</uri>
			</author>
			<updated>2010-05-21T13:43:40Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=35993#p35993</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=35992#p35992" />
			<content type="html"><![CDATA[<p>А так?<br /></p><div class="codebox"><pre><code>   Gui, +Resize
   Gui, Add, Edit, x0 y0 w200 h170
   Gui, Add, Button, x145 y175 h20 w50, Exit
   Gui, Add, Button, x40 yp hp wp, OK
   Gui, Show, w200 h200
   Return

GuiSize:
   Anchor(&quot;Edit1&quot;, &quot;wh&quot;), Anchor(&quot;Button1&quot;, &quot;xy&quot;, 1), Anchor(&quot;Button2&quot;, &quot;y&quot;, 1)
   Return

GuiClose:
ButtonExit:
   ExitApp

/*
    Function: Anchor
        Defines how controls should be automatically positioned relative to the new dimensions of a window when resized.

    Parameters:
        cl - a control HWND, associated variable name or ClassNN to operate on
        a - (optional) one or more of the anchors: &#039;x&#039;, &#039;y&#039;, &#039;w&#039; (width) and &#039;h&#039; (height),
            optionally followed by a relative factor, e.g. &quot;x h0.5&quot;
        r - (optional) true to redraw controls, recommended for GroupBox and Button types

    Examples:
&gt; &quot;xy&quot; ; bounds a control to the bottom-left edge of the window
&gt; &quot;w0.5&quot; ; any change in the width of the window will resize the width of the control on a 2:1 ratio
&gt; &quot;h&quot; ; similar to above but directrly proportional to height

    Remarks:
        To assume the current window size for the new bounds of a control (i.e. resetting) simply omit the second and third parameters.
        However if the control had been created with DllCall() and has its own parent window,
            the container AutoHotkey created GUI must be made default with the +LastFound option prior to the call.
        For a complete example see anchor-example.ahk.

    License:
        - Version 4.60a &lt;http://www.autohotkey.net/~Titan/#anchor&gt;
        - Simplified BSD License &lt;http://www.autohotkey.net/~Titan/license.txt&gt;
*/
Anchor(i, a = &quot;&quot;, r = false) {
    static c, cs = 12, cx = 255, cl = 0, g, gs = 8, gl = 0, gpi, gw, gh, z = 0, k = 0xffff
    If z = 0
        VarSetCapacity(g, gs * 99, 0), VarSetCapacity(c, cs * cx, 0), z := true
    If (!WinExist(&quot;ahk_id&quot; . i)) {
        GuiControlGet, t, Hwnd, %i%
        If ErrorLevel = 0
            i := t
        Else ControlGet, i, Hwnd, , %i%
    }
    VarSetCapacity(gi, 68, 0), DllCall(&quot;GetWindowInfo&quot;, &quot;UInt&quot;, gp := DllCall(&quot;GetParent&quot;, &quot;UInt&quot;, i), &quot;UInt&quot;, &amp;gi)
        , giw := NumGet(gi, 28, &quot;Int&quot;) - NumGet(gi, 20, &quot;Int&quot;), gih := NumGet(gi, 32, &quot;Int&quot;) - NumGet(gi, 24, &quot;Int&quot;)
    If (gp != gpi) {
        gpi := gp
        Loop, %gl%
            If (NumGet(g, cb := gs * (A_Index - 1)) == gp) {
                gw := NumGet(g, cb + 4, &quot;Short&quot;), gh := NumGet(g, cb + 6, &quot;Short&quot;), gf := 1
                Break
            }
        If (!gf)
            NumPut(gp, g, gl), NumPut(gw := giw, g, gl + 4, &quot;Short&quot;), NumPut(gh := gih, g, gl + 6, &quot;Short&quot;), gl += gs
    }
    ControlGetPos, dx, dy, dw, dh, , ahk_id %i%
    Loop, %cl%
        If (NumGet(c, cb := cs * (A_Index - 1)) == i) {
            If a =
            {
                cf = 1
                Break
            }
            giw -= gw, gih -= gh, as := 1, dx := NumGet(c, cb + 4, &quot;Short&quot;), dy := NumGet(c, cb + 6, &quot;Short&quot;)
                , cw := dw, dw := NumGet(c, cb + 8, &quot;Short&quot;), ch := dh, dh := NumGet(c, cb + 10, &quot;Short&quot;)
            Loop, Parse, a, xywh
                If A_Index &gt; 1
                    av := SubStr(a, as, 1), as += 1 + StrLen(A_LoopField)
                        , d%av% += (InStr(&quot;yh&quot;, av) ? gih : giw) * (A_LoopField + 0 ? A_LoopField : 1)
            DllCall(&quot;SetWindowPos&quot;, &quot;UInt&quot;, i, &quot;Int&quot;, 0, &quot;Int&quot;, dx, &quot;Int&quot;, dy
                , &quot;Int&quot;, InStr(a, &quot;w&quot;) ? dw : cw, &quot;Int&quot;, InStr(a, &quot;h&quot;) ? dh : ch, &quot;Int&quot;, 4)
            If r != 0
                DllCall(&quot;RedrawWindow&quot;, &quot;UInt&quot;, i, &quot;UInt&quot;, 0, &quot;UInt&quot;, 0, &quot;UInt&quot;, 0x0101) ; RDW_UPDATENOW | RDW_INVALIDATE
            Return
        }
    If cf != 1
        cb := cl, cl += cs
    bx := NumGet(gi, 48), by := NumGet(gi, 16, &quot;Int&quot;) - NumGet(gi, 8, &quot;Int&quot;) - gih - NumGet(gi, 52)
    If cf = 1
        dw -= giw - gw, dh -= gih - gh
    NumPut(i, c, cb), NumPut(dx - bx, c, cb + 4, &quot;Short&quot;), NumPut(dy - by, c, cb + 6, &quot;Short&quot;)
        , NumPut(dw, c, cb + 8, &quot;Short&quot;), NumPut(dh, c, cb + 10, &quot;Short&quot;)
    Return, true
}</code></pre></div><div class="codebox"><pre><code>   Gui, +Resize
   Gui, Add, Edit, x0 y0 w200 h170
   Gui, Add, Button, x40 y175 h20 w50, OK
   Gui, Add, Button, x145 yp hp wp, Exit
   Gui, Show, w200 h200
   Return

GuiSize:
   GuiControl, Move, Edit1, % &quot;w&quot; A_GuiWidth &quot; h&quot; A_GuiHeight - 30
   GuiControl, MoveDraw, Button1, % &quot;y&quot; A_GuiHeight - 25
   GuiControl, MoveDraw, Button2, % &quot;x&quot; (A_GuiWidth&gt;150 ? A_GuiWidth - 55 : 95) &quot; y&quot; A_GuiHeight - 25
   Return

GuiClose:
ButtonExit:
   ExitApp</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2010-05-21T13:30:28Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=35992#p35992</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=35991#p35991" />
			<content type="html"><![CDATA[<p>У меня в обоих случаях кнопки ведут себя одинаково. Сталкиваются, но не наезжают друг на друга.</p>]]></content>
			<author>
				<name><![CDATA[InFlames]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24849</uri>
			</author>
			<updated>2010-05-21T13:19:09Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=35991#p35991</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=35987#p35987" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>YMP пишет:</cite><blockquote><p>Нет, не совсем так (© teadrinker), не наезжают на, а именно только сталкиваются.</p></blockquote></div><p>Да нет же, именно <em>наезжают одна на другую</em>, проверь внимательнее.<br /></p><div class="quotebox"><cite>YMP пишет:</cite><blockquote><p>А твой разный код будет засорять программу. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p></blockquote></div><p>Едва ли! <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /> Даже если контролов и много, то 10-15 строчек под одной меткой <strong>GuiSize</strong> не сильно засорят программу!</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2010-05-21T13:06:24Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=35987#p35987</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=35983#p35983" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>При уменьшении ширины окна кнопки &quot;сталкиваются&quot;</p></blockquote></div><div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>В первом случае при уменьшении ширины окна кнопки наезжают одна на другую.</p></blockquote></div><p>Кто-то пытается мухлевать. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /> Нет, не совсем так (© teadrinker), не наезжают на, а именно только сталкиваются. Ну и почему кнопки не могут быть вплотную? Это как-то мешает их работе? Нет. Так в чём кривизна? По крайней мере так экономнее расходуется оконное пространство.</p><div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>Вывод: такие &quot;универсальные&quot; вещи можно использовать ограниченно, если думать лень!</p></blockquote></div><div class="quotebox"><cite>Resager пишет:</cite><blockquote><p>Конечно можно отслеживать, когда человек начинает изменять размер окна, но это для каждого окна будет разный код, куча кода который будет засорять программу...</p></blockquote></div><p>По-моему, ясно, что как раз универсальное решение и запрашивалось. А твой разный код будет засорять программу. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2010-05-21T12:45:36Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=35983#p35983</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=35981#p35981" />
			<content type="html"><![CDATA[<p>В первом случае при уменьшении ширины окна кнопки наезжают одна на другую.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2010-05-21T12:20:49Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=35981#p35981</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=35979#p35979" />
			<content type="html"><![CDATA[<p><strong>teadrinker</strong>, а в чем разница в этих двух примерах? Я не заметил.</p>]]></content>
			<author>
				<name><![CDATA[InFlames]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24849</uri>
			</author>
			<updated>2010-05-21T12:08:05Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=35979#p35979</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=35978#p35978" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>YMP пишет:</cite><blockquote><p>Вроде бы ясно, о какой универсальности я говорил.</p></blockquote></div><p>Да, я не совсем верно тебя понял.<br />Так известно, что универсальность далеко не всегда хороша! Ну вот, например, &quot;универсальный&quot; размер кресел в маршрутках китайского производства. Для китайцев, может, и ничего, а для нас тесновато!<br />Вот тебе конкретный пример.<br />При уменьшении ширины окна кнопки &quot;сталкиваются&quot;:<br /></p><div class="codebox"><pre><code>   Gui, +Resize
   Gui, Add, Edit, x0 y0 w200 h170
   Gui, Add, Button, x145 y175 h20 w50, Exit
   Gui, Add, Button, x5 yp hp wp, OK
   Gui, Show, w200 h200
   Return

GuiSize:
   Anchor(&quot;Edit1&quot;, &quot;wh&quot;), Anchor(&quot;Button1&quot;, &quot;xy&quot;, 1), Anchor(&quot;Button2&quot;, &quot;y&quot;, 1)
   Return

GuiClose:
ButtonExit:
   ExitApp

/*
    Function: Anchor
        Defines how controls should be automatically positioned relative to the new dimensions of a window when resized.

    Parameters:
        cl - a control HWND, associated variable name or ClassNN to operate on
        a - (optional) one or more of the anchors: &#039;x&#039;, &#039;y&#039;, &#039;w&#039; (width) and &#039;h&#039; (height),
            optionally followed by a relative factor, e.g. &quot;x h0.5&quot;
        r - (optional) true to redraw controls, recommended for GroupBox and Button types

    Examples:
&gt; &quot;xy&quot; ; bounds a control to the bottom-left edge of the window
&gt; &quot;w0.5&quot; ; any change in the width of the window will resize the width of the control on a 2:1 ratio
&gt; &quot;h&quot; ; similar to above but directrly proportional to height

    Remarks:
        To assume the current window size for the new bounds of a control (i.e. resetting) simply omit the second and third parameters.
        However if the control had been created with DllCall() and has its own parent window,
            the container AutoHotkey created GUI must be made default with the +LastFound option prior to the call.
        For a complete example see anchor-example.ahk.

    License:
        - Version 4.60a &lt;http://www.autohotkey.net/~Titan/#anchor&gt;
        - Simplified BSD License &lt;http://www.autohotkey.net/~Titan/license.txt&gt;
*/
Anchor(i, a = &quot;&quot;, r = false) {
    static c, cs = 12, cx = 255, cl = 0, g, gs = 8, gl = 0, gpi, gw, gh, z = 0, k = 0xffff
    If z = 0
        VarSetCapacity(g, gs * 99, 0), VarSetCapacity(c, cs * cx, 0), z := true
    If (!WinExist(&quot;ahk_id&quot; . i)) {
        GuiControlGet, t, Hwnd, %i%
        If ErrorLevel = 0
            i := t
        Else ControlGet, i, Hwnd, , %i%
    }
    VarSetCapacity(gi, 68, 0), DllCall(&quot;GetWindowInfo&quot;, &quot;UInt&quot;, gp := DllCall(&quot;GetParent&quot;, &quot;UInt&quot;, i), &quot;UInt&quot;, &amp;gi)
        , giw := NumGet(gi, 28, &quot;Int&quot;) - NumGet(gi, 20, &quot;Int&quot;), gih := NumGet(gi, 32, &quot;Int&quot;) - NumGet(gi, 24, &quot;Int&quot;)
    If (gp != gpi) {
        gpi := gp
        Loop, %gl%
            If (NumGet(g, cb := gs * (A_Index - 1)) == gp) {
                gw := NumGet(g, cb + 4, &quot;Short&quot;), gh := NumGet(g, cb + 6, &quot;Short&quot;), gf := 1
                Break
            }
        If (!gf)
            NumPut(gp, g, gl), NumPut(gw := giw, g, gl + 4, &quot;Short&quot;), NumPut(gh := gih, g, gl + 6, &quot;Short&quot;), gl += gs
    }
    ControlGetPos, dx, dy, dw, dh, , ahk_id %i%
    Loop, %cl%
        If (NumGet(c, cb := cs * (A_Index - 1)) == i) {
            If a =
            {
                cf = 1
                Break
            }
            giw -= gw, gih -= gh, as := 1, dx := NumGet(c, cb + 4, &quot;Short&quot;), dy := NumGet(c, cb + 6, &quot;Short&quot;)
                , cw := dw, dw := NumGet(c, cb + 8, &quot;Short&quot;), ch := dh, dh := NumGet(c, cb + 10, &quot;Short&quot;)
            Loop, Parse, a, xywh
                If A_Index &gt; 1
                    av := SubStr(a, as, 1), as += 1 + StrLen(A_LoopField)
                        , d%av% += (InStr(&quot;yh&quot;, av) ? gih : giw) * (A_LoopField + 0 ? A_LoopField : 1)
            DllCall(&quot;SetWindowPos&quot;, &quot;UInt&quot;, i, &quot;Int&quot;, 0, &quot;Int&quot;, dx, &quot;Int&quot;, dy
                , &quot;Int&quot;, InStr(a, &quot;w&quot;) ? dw : cw, &quot;Int&quot;, InStr(a, &quot;h&quot;) ? dh : ch, &quot;Int&quot;, 4)
            If r != 0
                DllCall(&quot;RedrawWindow&quot;, &quot;UInt&quot;, i, &quot;UInt&quot;, 0, &quot;UInt&quot;, 0, &quot;UInt&quot;, 0x0101) ; RDW_UPDATENOW | RDW_INVALIDATE
            Return
        }
    If cf != 1
        cb := cl, cl += cs
    bx := NumGet(gi, 48), by := NumGet(gi, 16, &quot;Int&quot;) - NumGet(gi, 8, &quot;Int&quot;) - gih - NumGet(gi, 52)
    If cf = 1
        dw -= giw - gw, dh -= gih - gh
    NumPut(i, c, cb), NumPut(dx - bx, c, cb + 4, &quot;Short&quot;), NumPut(dy - by, c, cb + 6, &quot;Short&quot;)
        , NumPut(dw, c, cb + 8, &quot;Short&quot;), NumPut(dh, c, cb + 10, &quot;Short&quot;)
    Return, true
}</code></pre></div><p>Универсально, но криво.<br />А вот так всё в порядке:<br /></p><div class="codebox"><pre><code>   Gui, +Resize
   Gui, Add, Edit, x0 y0 w200 h170
   Gui, Add, Button, x5 y175 h20 w50, OK
   Gui, Add, Button, x145 yp hp wp, Exit
   Gui, Show, w200 h200
   Return

GuiSize:
   GuiControl, Move, Edit1, % &quot;w&quot; A_GuiWidth &quot; h&quot; A_GuiHeight - 30
   GuiControl, MoveDraw, Button1, % &quot;y&quot; A_GuiHeight - 25
   GuiControl, MoveDraw, Button2, % &quot;x&quot; (A_GuiWidth&gt;=115 ? A_GuiWidth - 55 : 60) &quot; y&quot; A_GuiHeight - 25
   Return

GuiClose:
ButtonExit:
   ExitApp</code></pre></div><p>Этот пример — просто первое, что пришло в голову. На практике наверняка можно столкнуться и с другими проблемами.<br />Вывод: такие &quot;универсальные&quot; вещи можно использовать ограниченно, если думать лень! <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2010-05-21T11:52:00Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=35978#p35978</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=35975#p35975" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>Нет, не совсем так. Она сработает, только когда изменение размеров/позиции контролов <em>линейно</em> зависит от изменения размеров окна.</p></blockquote></div><p>А при чём тут это? Вроде бы ясно, о какой универсальности я говорил.<br /></p><div class="quotebox"><cite>YMP пишет:</cite><blockquote><p>Anchor — универсальная функция, а твой код для конкретной пары Edit + Button. Какие контролы нужны сейчас и будут нужны потом <strong>Resager</strong>&#039;у, неизвестно.</p></blockquote></div><p>Ты просто взял и отрезал контекст. Нафига так делать-то?</p><div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>Впрочем, не спорю, наверное, она может быть полезной.</p></blockquote></div><p>Ну так и я об этом не спорю. Ничего банальнее того, что рабочий код может быть (наверное) полезен, и придумать невозможно. Стал бы я спорить о такой ерунде. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2010-05-21T10:12:22Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=35975#p35975</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=35968#p35968" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>YMP пишет:</cite><blockquote><p>Anchor — универсальная функция</p></blockquote></div><p>Нет, не совсем так. Она сработает, только когда изменение размеров/позиции контролов <em>линейно</em> зависит от изменения размеров окна. Впрочем, не спорю, наверное, она может быть полезной.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2010-05-21T09:21:50Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=35968#p35968</id>
		</entry>
</feed>
