<?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=12251&amp;type=atom" />
	<updated>2016-12-29T02:09:18Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=12251</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Закрыть окно программы которое сворачивается в трей при закрытии]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=110392#p110392" />
			<content type="html"><![CDATA[<p>Всем огромное спасибо за участие. Подошёл скрипт от <strong>teadrinker</strong> , вам отдельное спасибо .<br />Блин и как же я сам не догадался , всё гениальное просто.<br /></p><div class="codebox"><pre><code>WinWaitClose</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Ядрён]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=30092</uri>
			</author>
			<updated>2016-12-29T02:09:18Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=110392#p110392</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Закрыть окно программы которое сворачивается в трей при закрытии]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=110391#p110391" />
			<content type="html"><![CDATA[<p>Если открытых приложений и процессов может быть одновременно несколько, по типу как у блокнота - тогда этот вариант может не подойти.</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2016-12-29T02:08:12Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=110391#p110391</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Закрыть окно программы которое сворачивается в трей при закрытии]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=110390#p110390" />
			<content type="html"><![CDATA[<p>А, я не понял о чём ты, тогда да, опечатка. Но ещё логичнее так будет:<br /></p><div class="codebox"><pre><code>ExePath := &quot;OscarEditor.exe&quot;  ; здесь прописать полный путь к исполнимому файлу

Run, % ExePath
WinWait, OscareditorForm ahk_class TMainForm
WinWaitClose
Process, Close, OscarEditor.exe</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2016-12-29T01:54:20Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=110390#p110390</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Закрыть окно программы которое сворачивается в трей при закрытии]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=110389#p110389" />
			<content type="html"><![CDATA[<p>Как же он сработает, когда хендл у окна будет другой?<br /></p><div class="quotebox"><blockquote><p>After the Run command retrieves a PID, any windows to be created by the process might not exist yet. To wait for at least one window to be created, use WinWait <strong>ahk_pid</strong> %OutputVarPID%.</p></blockquote></div><p>А у тебя:<br /></p><div class="quotebox"><blockquote><p>WinWait, <strong>ahk_id</strong> %PID%</p></blockquote></div><p><a href="https://autohotkey.com/docs/commands/Run.htm">https://autohotkey.com/docs/commands/Run.htm</a></p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2016-12-29T01:48:58Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=110389#p110389</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Закрыть окно программы которое сворачивается в трей при закрытии]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=110388#p110388" />
			<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>2016-12-29T01:44:22Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=110388#p110388</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Закрыть окно программы которое сворачивается в трей при закрытии]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=110387#p110387" />
			<content type="html"><![CDATA[<p>Может, но у тебя стоит ожидание хендла:<br /></p><div class="codebox"><pre><code>WinWait, ahk_id %PID%</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2016-12-29T01:41:14Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=110387#p110387</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Закрыть окно программы которое сворачивается в трей при закрытии]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=110386#p110386" />
			<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>2016-12-29T01:37:49Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=110386#p110386</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Закрыть окно программы которое сворачивается в трей при закрытии]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=110385#p110385" />
			<content type="html"><![CDATA[<p><strong>teadrinker</strong>, у тебя ошибка. Правильно так:<br /></p><div class="codebox"><pre><code>ExePath := &quot;OscarEditor.exe&quot;  ; здесь прописать полный путь к исполнимому файлу

Run, % ExePath,,, PID
WinWait, ahk_pid %PID%
WinWaitClose
Process, Close, %PID%</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2016-12-29T01:34:23Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=110385#p110385</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Закрыть окно программы которое сворачивается в трей при закрытии]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=110384#p110384" />
			<content type="html"><![CDATA[<p>Можно так попробовать. Запускайте программу таким скриптом:<br /></p><div class="codebox"><pre><code>ExePath := &quot;OscarEditor.exe&quot;  ; здесь прописать полный путь к исполнимому файлу

Run, % ExePath,,, PID
WinWait, ahk_id %PID%
WinWaitClose
Process, Close, OscarEditor.exe</code></pre></div><p>При закрытии окна процесс должен завершиться, но нужно иметь в виду, что без сохранения данных.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2016-12-28T22:30:02Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=110384#p110384</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Закрыть окно программы которое сворачивается в трей при закрытии]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=110383#p110383" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>#IfWinActive OscareditorForm
LButton::
Click Down
IfWinNotActive OscareditorForm
{
   KeyWait LButton
   Click Up
}
return

LButton Up::
CoordMode, Mouse, Screen
MouseGetPos, x, y
SendMessage, 0x84,, (x &amp; 0xFFFF) | (y &amp; 0xFFFF) &lt;&lt; 16  ; WM_NCHITTEST
if (ErrorLevel = 20) ; close button
{
   WinGet, pid, pid, A
   Process, Close, %pid%
   NoTrayOrphans()     ; очистить трей от иконок закрытых приложений
}
Click Up
return
#IfWinActive


NoTrayOrphans()
{
    TrayInfo := TrayIcons(&quot;ahk_class Shell_TrayWnd&quot;, &quot;ToolbarWindow32&quot; . GetTrayBar())  
        . TrayIcons(&quot;ahk_class NotifyIconOverflowWindow&quot;, &quot;ToolbarWindow321&quot;)
 
    Loop, Parse, TrayInfo, `n
    {  
        PID := StrX(A_Loopfield, &quot;| PID: &quot;, &quot; |&quot;) 
        If !PID
            RemoveTrayIcon(StrX(A_Loopfield, &quot;| hWnd: &quot;, &quot; |&quot;), StrX(A_Loopfield, &quot;| uID: &quot;, &quot; |&quot;))   
    }
}

TrayIcons(traywindow, control)  
{
    DetectHiddenWindows, On
    WinGet, pidTaskbar, PID, %traywindow%
    hProc := DllCall(&quot;OpenProcess&quot;, &quot;Uint&quot;, 0x38, &quot;int&quot;, 0, &quot;Uint&quot;, pidTaskbar)
    pProc := DllCall(&quot;VirtualAllocEx&quot;, &quot;Uint&quot;, hProc, &quot;Uint&quot;, 0, &quot;Uint&quot;, 32, &quot;Uint&quot;, 0x1000, &quot;Uint&quot;, 0x4)
    SendMessage, 0x418, 0, 0, %control%, %traywindow%
    Loop, %ErrorLevel%
    {
        SendMessage, 0x417, A_Index - 1, pProc, %control%, %traywindow%
        VarSetCapacity(btn, 32, 0), VarSetCapacity(nfo, 32, 0)
        DllCall(&quot;ReadProcessMemory&quot;, &quot;Uint&quot;, hProc, &quot;Uint&quot;, pProc, &quot;Uint&quot;, &amp;btn, &quot;Uint&quot;, 32, &quot;Uint&quot;, 0)
        iBitmap := NumGet(btn, 0)
        idn := NumGet(btn, 4)
        Statyle := NumGet(btn, 8)
        If dwData := NumGet(btn, 12)
            iString := NumGet(btn, 16)
        Else
        {
            dwData := NumGet(btn, 16, &quot;int64&quot;)
            iString := NumGet(btn, 24, &quot;int64&quot;)
        }
        DllCall(&quot;ReadProcessMemory&quot;, &quot;Uint&quot;, hProc, &quot;Uint&quot;, dwData, &quot;Uint&quot;, &amp;nfo, &quot;Uint&quot;, 32, &quot;Uint&quot;, 0)
        If NumGet(btn,12)
        {
            hWnd := NumGet(nfo, 0)
            uID := NumGet(nfo, 4)
            nMsg := NumGet(nfo, 8)
            hIcon := NumGet(nfo, 20)
        }
        Else
        {
            hWnd := NumGet(nfo, 0, &quot;int64&quot;)
            uID := NumGet(nfo, 8)
            nMsg := NumGet(nfo, 12)
            hIcon := NumGet(nfo, 24)
        }
        WinGet, pid, PID, ahk_id %hWnd%
        WinGet, sProcess, ProcessName, ahk_id %hWnd%
        WinGetClass, sClass, ahk_id %hWnd% 
        VarSetCapacity(sTooltip, 128)
        VarSetCapacity(wTooltip, 128*2)
        DllCall(&quot;ReadProcessMemory&quot;, &quot;Uint&quot;, hProc, &quot;Uint&quot;, iString, &quot;Uint&quot;, &amp;wTooltip, &quot;Uint&quot;, 128*2, &quot;Uint&quot;, 0)
        DllCall(&quot;WideCharToMultiByte&quot;, &quot;Uint&quot;, 0, &quot;Uint&quot;, 0, &quot;str&quot;, wTooltip, &quot;int&quot;, -1, &quot;str&quot;, sTooltip, &quot;int&quot;, 128, &quot;Uint&quot;, 0, &quot;Uint&quot;, 0)
        sTrayIcons .= &quot;| Pid: &quot; pid &quot; | uID: &quot; uID &quot; | hWnd: &quot; hWnd &quot; |`n&quot; 
    }
    DllCall(&quot;VirtualFreeEx&quot;, &quot;Uint&quot;, hProc, &quot;Uint&quot;, pProc, &quot;Uint&quot;, 0, &quot;Uint&quot;, 0x8000)
    DllCall(&quot;CloseHandle&quot;, &quot;Uint&quot;, hProc)
    Return sTrayIcons
}

GetTrayBar()
{
    ControlGet, hParent, hWnd,, TrayNotifyWnd1, ahk_class Shell_TrayWnd
    ControlGet, hChild, hWnd,, ToolbarWindow321, ahk_id %hParent%
    Loop
    {
        ControlGet, hWnd, hWnd,, ToolbarWindow32%A_Index%, ahk_class Shell_TrayWnd
        If (hWnd == hChild)
            idxTB := A_Index
        If !hWnd || (hWnd == hChild)
            Break
    }
    Return idxTB
}

StrX(H, BS = &quot;&quot;, ES = &quot;&quot;, Tr = 1, ByRef OS = 1)
{
    Return (SP := InStr(H, BS, 0, OS)) &amp;&amp; (L := InStr(H, ES, 0, SP + StrLen(BS))) &amp;&amp; (OS := L + StrLen(ES)) ? SubStr(H, SP := Tr ? SP + StrLen(BS) : SP, (Tr ? L : L + StrLen(ES)) -SP) : &quot;&quot;
}

RemoveTrayIcon(hWnd, uID, nMsg = 0, hIcon = 0, nRemove = 2)
{
    NumPut(VarSetCapacity(ni,444,0), ni)
    NumPut(hWnd, ni, 4)
    NumPut(uID, ni, 8)
    NumPut(1|2|4, ni, 12)
    NumPut(nMsg, ni, 16)
    NumPut(hIcon, ni, 20)
    Return DllCall(&quot;shell32\Shell_NotifyIconA&quot;, &quot;Uint&quot;, nRemove, &quot;Uint&quot;, &amp;ni)
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2016-12-28T21:37:09Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=110383#p110383</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Закрыть окно программы которое сворачивается в трей при закрытии]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=110382#p110382" />
			<content type="html"><![CDATA[<p>Оба скрипта не работают . Я не понимаю как можно сделать ожидание нажатия на кнопку (X) .<br />Если только при помощи команды.<br /></p><div class="codebox"><pre><code>MouseGetPos</code></pre></div><p>Но как я непойму ,попав на координаты кнопки внутри окна послдать нужную команду.<br /></p><div class="codebox"><pre><code>WinClose или Process, Close</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Ядрён]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=30092</uri>
			</author>
			<updated>2016-12-28T21:17:48Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=110382#p110382</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Закрыть окно программы которое сворачивается в трей при закрытии]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=110352#p110352" />
			<content type="html"><![CDATA[<p>У меня так с блокнотом работает (при нажатии на крестик минимизирует окно):<br /></p><div class="codebox"><pre><code>#IfWinActive ahk_class Notepad
LButton::
Click Down
IfWinNotActive ahk_class Notepad
{
   KeyWait LButton
   Click Up
}
return

LButton Up::
CoordMode, Mouse, Screen
MouseGetPos, x, y
SendMessage, 0x84,, (x &amp; 0xFFFF) | (y &amp; 0xFFFF) &lt;&lt; 16  ; WM_NCHITTEST
if (ErrorLevel = 20) ; close button
   WinMinimize, A
Click Up
return
#IfWinActive</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2016-12-27T19:23:21Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=110352#p110352</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Закрыть окно программы которое сворачивается в трей при закрытии]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=110318#p110318" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>WinGet, hWnd, ID, ahk_class TMainForm ahk_exe OscarEditor.exe ; получаем хэндл OscarEditor
hSysMenu := DllCall( &quot;GetSystemMenu&quot;, &quot;Uint&quot;, hWnd, &quot;int&quot;, False ) ; получаем хэндл системного меню
DllCall( &quot;GetSystemMenu&quot;, &quot;Uint&quot;, hWnd, &quot;int&quot;, True ) ; восстанавливаем системное меню</code></pre></div>]]></content>
			<author>
				<name><![CDATA[ypppu]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=5974</uri>
			</author>
			<updated>2016-12-27T10:07:17Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=110318#p110318</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Закрыть окно программы которое сворачивается в трей при закрытии]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=110121#p110121" />
			<content type="html"><![CDATA[<p>Ну я из из предоставленной темы ничего непонял. Вот даю папаметры приложения.</p><div class="codebox"><pre><code>
Title - OscareditorForm
Class - ahk_class TMainForm 
ProcessName - ahk_exe OscarEditor.exe
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Ядрён]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=30092</uri>
			</author>
			<updated>2016-12-24T23:09:09Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=110121#p110121</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Закрыть окно программы которое сворачивается в трей при закрытии]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=110115#p110115" />
			<content type="html"><![CDATA[<p>Есть <a href="http://forum.script-coding.com/viewtopic.php?id=363">такая тема </a>в Коллекции. В ней имеется код<br /></p><div class="codebox"><pre><code>DllCall( &quot;GetSystemMenu&quot;, &quot;Uint&quot;, hWnd, &quot;int&quot;, True ) ; восстанавливаем системное меню</code></pre></div><p>У меня есть программа, в которой изначально крестик не закрывает программу. Пробовал в ней восстановить системное меню - не помогло. Может быть у Вас получится.</p>]]></content>
			<author>
				<name><![CDATA[ypppu]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=5974</uri>
			</author>
			<updated>2016-12-24T18:42:42Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=110115#p110115</id>
		</entry>
</feed>
