<?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="http://forum.script-coding.com/extern.php?action=feed&amp;tid=8247&amp;type=atom" />
	<updated>2015-09-17T19:45:25Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=8247</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование окна, в зависимости от позиции мыши]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=97539#p97539" />
			<content type="html"><![CDATA[<p>Всё таки оно как то некорректно работает с двумя мониторами, или я что то не понял. В принципе стандартный тултип тоже в таких случаях ошибается. Пытался например сделать, чтобы от исходной точки окно было слева и по высоте посередине, но при приближении к краям окно уходит за какой нибудь край (при разных попытках реализации). </p><p>Желаемое, оказалось было не сложно сделать встроенными методами, вроде ошибок нет:<br /></p><div class="codebox"><pre><code>
#SingleInstance Force       
DetectHiddenWindows, On

Gui, Margin, 5, 5
Gui, Font, Italic s54 cWhite, Times New Roman
Gui, +AlwaysOnTop +ToolWindow -0x00400000 +E0x08000020 -DPIScale +Lastfound +HWNDhGui +Owner
Gui, Color, 2F4F4F 
WinSet, TransParent, 200

1::   
    DllCall(&quot;DestroyWindow&quot;, &quot;Ptr&quot;, hStatic) 
    Gui Add, Text, hwndhStatic x5 y5, % &quot; TickCount: `n &quot; A_TickCount &quot; &quot;
    Gui, Show, % &quot;NA AutoSize &quot; (DllCall(&quot;IsWindowVisible&quot;, &quot;uint&quot;, hGui) ? &quot;&quot; : &quot;Hide&quot;)  
    WinGetPos, , , WinWidth, WinHeight, % &quot;ahk_id&quot; hGui 
    If CalculatePopupWindowPosition(X, Y, WinWidth, WinHeight, -WinWidth-45, -WinHeight//2) 
        Gui, Show, NA x%X% y%Y%
    Return

2:: Gui, Hide

CalculatePopupWindowPosition(byref left, byref top, w, h, offsetx = 0, offsety = 0, x = &quot;&quot;, y = &quot;&quot;)  {
    If (x = &quot;&quot; || y = &quot;&quot;)
        DllCall(&quot;GetCursorPos&quot;, &quot;int64P&quot;, pt), x := pt &lt;&lt; 32 &gt;&gt; 32, y := pt &gt;&gt; 32
    SysGet, MonCount, MonitorCount
    Loop % MonCount
    {
        SysGet, m, Monitor, %A_Index%
        If (x &gt;= mLeft &amp;&amp; x &lt;= mRight &amp;&amp; y &gt;= mTop &amp;&amp; y &lt;= mBottom)
            Break
        If (A_Index = MonCount)
            Return 0
    }
    left := x + offsetx + (offsetx &gt; 0) * w &lt; mLeft ? mLeft : x + offsetx + w &gt; mRight ? mRight - w : x + offsetx
    top := y + offsety + (offsety &gt; 0) * h &lt; mTop ? mTop : y + offsety + h &gt; mBottom ? mBottom - h : y + offsety
    Return 1
}
</code></pre></div><p>Но только стоит учитывать, что если указываются свои координаты показа, то они должны находится в пределах монитора.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2015-09-17T19:45:25Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=97539#p97539</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование окна, в зависимости от позиции мыши]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=90418#p90418" />
			<content type="html"><![CDATA[<p>Небольшой пример. Под локальную переменную <em>Test</em> место в памяти выделяется вслед за <em>structs</em>. При многократном нажатии &#039;1&#039; и случайном перемещении курсора Test портится &quot;лишними&quot; данными. (win8.1 x86)<br /></p><div class="codebox"><pre><code>Gui, Margin, 5, 5
Gui, Font, Italic s34 cWhite, Times New Roman
Gui, +AlwaysOnTop +ToolWindow -0x00400000 +E0x08000020 -DPIScale +Lastfound +HWNDhGui  +Owner
Gui, Color, 2F4F4F 
WinSet, TransParent, 200

1:: 
    DllCall(&quot;DestroyWindow&quot;, &quot;Ptr&quot;, hStatic)
    Gui Add, Text, hwndhStatic x5 y5, % &quot;TickCount:`n&quot; A_TickCount
    Gui, Show, % &quot;NA AutoSize &quot; (DllCall(&quot;IsWindowVisible&quot;, &quot;uint&quot;, hGui) ? &quot;&quot; : &quot;Hide&quot;) 
    If CalculatePopupWindowPosition(x, y, hGui, 25)
        Gui, Show, NA x%x% y%y% 
    Return 
    
2:: Gui, Hide

CalculatePopupWindowPosition(byref left, byref top, hwnd, offset = 0, x = &quot;&quot;, y = &quot;&quot;)  { 
    VarSetCapacity(POINT, 8, 0), VarSetCapacity(structs, 16, 0), VarSetCapacity(Test, 8, 0)
    If (x = &quot;&quot; || y = &quot;&quot;)
        DllCall(&quot;GetCursorPos&quot;, &quot;ptr&quot;, &amp;POINT)
    Else
        NumPut(x, POINT, 0, &quot;int&quot;), NumPut(y, POINT, 4, &quot;int&quot;)  
    DHW := A_DetectHiddenWindows
    DetectHiddenWindows, On
    WinGetPos, , , w, h, ahk_id %hwnd% 
    DetectHiddenWindows, %DHW%
    NumPut(w + offset, structs, 0, &quot;int&quot;), NumPut(h + offset, structs, 4, &quot;int&quot;) ; SIZE   
    Loop 2
    {
        If !DllCall(&quot;CalculatePopupWindowPosition&quot;
            , &quot;ptr&quot;, &amp;POINT
            , &quot;ptr&quot;, &amp;structs
            , &quot;int&quot;, [0, 0x0008][A_Index]
            , &quot;ptr&quot;, 0
            , &quot;ptr&quot;, &amp;structs + 8)
            Return 0 
        _left := NumGet(structs, 8, &quot;int&quot;), _top := NumGet(structs, 12, &quot;int&quot;) 
        If !(_left &lt; NumGet(POINT, 0, &quot;int&quot;) &amp;&amp; _top &lt; NumGet(POINT, 4, &quot;int&quot;)  &amp;&amp; (out := 1))    
            Break 
    }
    left := _left + (out ? 0 : offset)  
    top := _top + (out ? 0 : offset)
    ListVars
    Return 1
}
  
Esc:: ExitApp   </code></pre></div>]]></content>
			<author>
				<name><![CDATA[Irbis]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27384</uri>
			</author>
			<updated>2015-01-13T10:24:25Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=90418#p90418</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование окна, в зависимости от позиции мыши]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=90416#p90416" />
			<content type="html"><![CDATA[<p>Конечно. Функция ждёт указатель на 16 байт. И вы никак ей не скажете, что там для неё только 8.</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2015-01-13T08:58:22Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=90416#p90416</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование окна, в зависимости от позиции мыши]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=90415#p90415" />
			<content type="html"><![CDATA[<p>То есть в таком варианте,&nbsp; изменяются следующие 8 байт адресного пространства процесса,&nbsp; отвечающих уже неизвестно за что?</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2015-01-13T08:53:20Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=90415#p90415</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование окна, в зависимости от позиции мыши]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=90407#p90407" />
			<content type="html"><![CDATA[<p>Да, это ведь не AutoHotkey, где можно опускать ненужное. С WinAPI такие фокусы не пройдут.</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2015-01-13T07:02:00Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=90407#p90407</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование окна, в зависимости от позиции мыши]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=90406#p90406" />
			<content type="html"><![CDATA[<p>Нам - не интересны. Но <em>CalculatePopupWindowPosition</em> об этом &quot;не знает&quot; и честно заполнит все 4 выходных параметра, выехав за пределы выделенной области. Какие данные при этом могут затереться, кто знает?</p>]]></content>
			<author>
				<name><![CDATA[Irbis]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27384</uri>
			</author>
			<updated>2015-01-13T06:54:38Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=90406#p90406</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование окна, в зависимости от позиции мыши]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=90404#p90404" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>typedef struct tagRECT
{
    LONG    left;
    LONG    top;
    LONG    right;
    LONG    bottom;
} RECT</code></pre></div><p>Знаю, но какой смысл, если right и bottom нам не интересны.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2015-01-13T06:36:56Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=90404#p90404</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование окна, в зависимости от позиции мыши]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=90401#p90401" />
			<content type="html"><![CDATA[<p>SIZE + RECT = 24 байта, а не 16.</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2015-01-13T03:01:46Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=90401#p90401</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование окна, в зависимости от позиции мыши]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=90387#p90387" />
			<content type="html"><![CDATA[<p>Или лучше так, чтобы мышь не наезжала на ToolTip.<br /></p><div class="codebox"><pre><code>
Gui, Margin, 5, 5
Gui, Font, Italic s34 cWhite, Times New Roman
Gui, +AlwaysOnTop +ToolWindow -0x00400000 +E0x08000020 -DPIScale +Lastfound +HWNDhGui  +Owner
Gui, Color, 2F4F4F 
WinSet, TransParent, 200

1:: 
    DllCall(&quot;DestroyWindow&quot;, &quot;Ptr&quot;, hStatic)
    Gui Add, Text, hwndhStatic x5 y5, % &quot;TickCount:`n&quot; A_TickCount
    Gui, Show, % &quot;NA AutoSize &quot; (DllCall(&quot;IsWindowVisible&quot;, &quot;uint&quot;, hGui) ? &quot;&quot; : &quot;Hide&quot;) 
    If CalculatePopupWindowPosition(x, y, hGui, 25)
        Gui, Show, NA x%x% y%y% 
    Return 
    
2:: Gui, Hide

CalculatePopupWindowPosition(byref left, byref top, hwnd, offset = 0, x = &quot;&quot;, y = &quot;&quot;)  { 
    VarSetCapacity(POINT, 8, 0), VarSetCapacity(structs, 24, 0)
    If (x = &quot;&quot; || y = &quot;&quot;)
        DllCall(&quot;GetCursorPos&quot;, &quot;ptr&quot;, &amp;POINT)
    Else
        NumPut(x, POINT, 0, &quot;int&quot;), NumPut(y, POINT, 4, &quot;int&quot;)  
    DHW := A_DetectHiddenWindows
    DetectHiddenWindows, On
    WinGetPos, , , w, h, ahk_id %hwnd% 
    DetectHiddenWindows, %DHW%
    NumPut(w + offset, structs, 0, &quot;int&quot;), NumPut(h + offset, structs, 4, &quot;int&quot;) ; SIZE   
    Loop 2
    {
        If !DllCall(&quot;CalculatePopupWindowPosition&quot;
            , &quot;ptr&quot;, &amp;POINT
            , &quot;ptr&quot;, &amp;structs
            , &quot;int&quot;, [0, 0x0008][A_Index]
            , &quot;ptr&quot;, 0
            , &quot;ptr&quot;, &amp;structs + 8)
            Return 0 
        _left := NumGet(structs, 8, &quot;int&quot;), _top := NumGet(structs, 12, &quot;int&quot;) 
        If !(_left &lt; NumGet(POINT, 0, &quot;int&quot;) &amp;&amp; _top &lt; NumGet(POINT, 4, &quot;int&quot;)  &amp;&amp; (out := 1))    
            Break 
    }
    left := _left + (out ? 0 : offset)  
    top := _top + (out ? 0 : offset)
    Return 1
}
  
Esc:: ExitApp   
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2015-01-12T22:19:55Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=90387#p90387</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование окна, в зависимости от позиции мыши]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=90373#p90373" />
			<content type="html"><![CDATA[<p>Сделал такой вариант:<br /></p><div class="codebox"><pre><code>
Gui, Margin, 5, 5
Gui, Font, Italic s54 cWhite, Times New Roman
Gui, +AlwaysOnTop +ToolWindow -0x00400000 +E0x08000020 -DPIScale +Lastfound +HWNDhGui  +Owner
Gui, Color, 2F4F4F 
WinSet, TransParent, 200

1::   
    DllCall(&quot;DestroyWindow&quot;, &quot;Ptr&quot;, hStatic)
    Gui Add, Text, hwndhStatic x5 y5, % &quot;TickCount:`n&quot; A_TickCount
    Gui, Show, % &quot;NA AutoSize &quot; (DllCall(&quot;IsWindowVisible&quot;, &quot;uint&quot;, hGui) ? &quot;&quot; : &quot;Hide&quot;) 
    If CalculatePopupWindowPosition(x, y, hGui, 15)
        Gui, Show, NA x%x% y%y%
    Return 
    
2:: Gui, Hide

CalculatePopupWindowPosition(byref left, byref top, hwnd, offset = 0, x = &quot;&quot;, y = &quot;&quot;)  { 
    VarSetCapacity(POINT, 8, 0), VarSetCapacity(structs, 24, 0)
    If (x = &quot;&quot; || y = &quot;&quot;)
        DllCall(&quot;GetCursorPos&quot;, &quot;ptr&quot;, &amp;POINT)
    Else
        NumPut(x, POINT, 0, &quot;int&quot;), NumPut(y, POINT, 4, &quot;int&quot;)  
    DHW := A_DetectHiddenWindows
    DetectHiddenWindows, On
    WinGetPos, , , w, h, ahk_id %hwnd% 
    DetectHiddenWindows, %DHW%
    NumPut(w + offset, structs, 0, &quot;int&quot;), NumPut(h + offset, structs, 4, &quot;int&quot;) ; SIZE  
    If !DllCall(&quot;CalculatePopupWindowPosition&quot;
        , &quot;ptr&quot;, &amp;POINT
        , &quot;ptr&quot;, &amp;structs
        , &quot;int&quot;, 0x0040        ; TPM_VERTICAL
        , &quot;ptr&quot;, 0
        , &quot;ptr&quot;, &amp;structs + 8)
        Return 0
    left  := NumGet(structs, 8, &quot;int&quot;) + offset
    top := NumGet(structs, 12, &quot;int&quot;) + offset 
    Return 1
}
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2015-01-12T21:04:43Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=90373#p90373</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование окна, в зависимости от позиции мыши]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=90358#p90358" />
			<content type="html"><![CDATA[<p><strong>YMP</strong><br />Большое спасибо за пример! Может не обращал нигде внимание до этого, но интересен также пример использования одной структуры под &quot;всё&quot;.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2015-01-12T09:12:07Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=90358#p90358</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование окна, в зависимости от позиции мыши]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=90356#p90356" />
			<content type="html"><![CDATA[<p>Нет, там указатели на структуры.<br /></p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header"><strong>+</strong>&nbsp;Вот их определения</div><div class="fancy_spoiler"><div class="codebox"><pre><code>
typedef struct tagPOINT
{
    LONG  x;
    LONG  y;
} POINT

typedef struct tagSIZE
{
    LONG        cx;
    LONG        cy;
} SIZE

typedef struct tagRECT
{
    LONG    left;
    LONG    top;
    LONG    right;
    LONG    bottom;
} RECT
</code></pre></div></div></div><p>Т.е. вот так можно, например.<br /></p><div class="codebox"><pre><code>
x := A_ScreenWidth
y := A_ScreenHeight  
w := 222
h := 222

VarSetCapacity( structs, 32, 0 )
NumPut( x, structs, 0, &quot;int&quot; ), NumPut( y, structs, 4, &quot;int&quot; )  ; POINT
NumPut( w, structs, 8, &quot;int&quot; ), NumPut( h, structs, 12, &quot;int&quot; ) ; SIZE

If !DllCall( &quot;CalculatePopupWindowPosition&quot;
    , &quot;ptr&quot;, &amp;structs
    , &quot;ptr&quot;, &amp;structs + 8
    , &quot;uint&quot;, 0x10000        ; TPM_WORKAREA
    , &quot;ptr&quot;, 0
    , &quot;ptr&quot;, &amp;structs + 16 )
{
    MsgBox, Ошибка.
    ExitApp
}
; Выходной RECT
left  := NumGet( structs, 16, &quot;int&quot; ), top    := NumGet( structs, 20, &quot;int&quot; )
right := NumGet( structs, 24, &quot;int&quot; ), bottom := NumGet( structs, 28, &quot;int&quot; )

MsgBox, %left% %top%`n%right% %bottom%
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2015-01-12T08:52:09Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=90356#p90356</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование окна, в зависимости от позиции мыши]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=90353#p90353" />
			<content type="html"><![CDATA[<p>Писал я. Везде добавил звёздочки, ничего. Делал по аналогии с другими функциями, &quot;int64&quot; - входящий параметр в виде структуры, &quot;int64*&quot; - исходящий параметр в виде структуры.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2015-01-12T08:29:06Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=90353#p90353</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование окна, в зависимости от позиции мыши]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=90351#p90351" />
			<content type="html"><![CDATA[<p>Не знаете, что такое указатель? Однако в 5-м параметре вы его используете. Или это не вы код писали?</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2015-01-12T08:11:57Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=90351#p90351</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Позиционирование окна, в зависимости от позиции мыши]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=90350#p90350" />
			<content type="html"><![CDATA[<p>Не наводит на мысли, я в этом ровным счётом ничего не понимаю.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2015-01-12T07:58:37Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=90350#p90350</id>
		</entry>
</feed>
