<?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=7516&amp;type=atom" />
	<updated>2012-12-06T22:33:29Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=7516</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Ожидание нескольких окон]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=66760#p66760" />
			<content type="html"><![CDATA[<p>Вроде нашёл решение после OnWindowActivated пропишу Return, а подним метку к которой переходить из WaitForExplorerWindowActivated</p><div class="codebox"><pre><code>OnWindowActivated(&quot;ahk_class CabinetWClass&quot;, &quot;WaitForExplorerWindowActivated&quot;, &quot;имя_метки&quot;, &quot;секунды&quot;)
return
метка:
MsgBox Теперь активно
return

WaitForExplorerWindowActivated(hwnd, имя_метки) {
    Goto, %имя_метки%
}</code></pre></div><p>Интересно, если в один момент произойдёт окончание ожидания нескольких окон, то будет ли осуществлён переход по всем меткам?</p><p>И возможно-ли переделать Ваш код под ожидание - Существования, Активности, Неактивности, Закрытия окон с указанием времени ожидания, и передачей имени метки?</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2012-12-06T22:33:29Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=66760#p66760</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Ожидание нескольких окон]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=66732#p66732" />
			<content type="html"><![CDATA[<p>А если после строки WinWait() возможно поместить ещё &quot;пару&quot; своих строк перед MsgBox?</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2012-12-06T12:22:44Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=66732#p66732</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Ожидание нескольких окон]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=66727#p66727" />
			<content type="html"><![CDATA[<p>Не подскажу, увы.<br />Кажется, проблема в:<br /></p><div class="quotebox"><blockquote><p>Необходим именно приведённый мною синтаксис.</p></blockquote></div>]]></content>
			<author>
				<name><![CDATA[creature.ws]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26105</uri>
			</author>
			<updated>2012-12-06T11:21:06Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=66727#p66727</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Ожидание нескольких окон]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=66726#p66726" />
			<content type="html"><![CDATA[<p>Это понятно.</p><p>Необходим именно приведённый мною синтаксис.<br />Ибо другой скрипт в зависимости от действий юзверя, создаёт файл ввиде скрипта, вот кусок:<br /></p><div class="codebox"><pre><code>***
#IF Config = &quot;2 режим&quot;
vk31:: ;§startkey¶1 кнопка§2 режим§
WinWait(&quot;ahk_class OperaWindowClass&quot;, &quot;§¶Delimiter1§¶&quot;, &quot;5§1§&quot;) ;¤¤1¤¤¶¶2 режим¶¶1 кнопка¶¶Ждать окно¶¶
 MsgBox Теперь активно ;¤¤2¤¤¶¶2 режим¶¶1 кнопка¶¶Скрипт AutoHotkey¶¶
Return ;§2 режим§endkey¶1 кнопка§
#IF ;end§2 режим§Config
***
</code></pre></div><p>И функция:<br /></p><div class="codebox"><pre><code>WinWait(WinWait, Delimiter1, Seconds)
{
StringTrimRight, Sec, Seconds, 3
if Sec = 0
Sec =
ifinString, Seconds, §1§
WinWait %WinWait%, , %Sec%
ifinString, Seconds, §2§
WinWaitActive %WinWait%, , %Sec%
ifinString, Seconds, §3§
WinWaitNotActive %WinWait%, , %Sec%
ifinString, Seconds, §4§
WinWaitClose %WinWait%, , %Sec%
}</code></pre></div><p>Тут MsgBox выполняется после ожидания. Естественно что если юзер запустит несколько разных потоков ожидания, то будет выполнятся только последний из них.<br />А хочется чтоб все.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2012-12-06T10:58:46Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=66726#p66726</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Ожидание нескольких окон]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=66722#p66722" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>Space::OnWindowActivated(&quot;ahk_class CabinetWClass&quot;, &quot;WaitForExplorerWindowActivated&quot;)

WaitForExplorerWindowActivated(hwnd) {
    MsgBox Теперь активно 
}</code></pre></div><p>Замечательный диалог.</p>]]></content>
			<author>
				<name><![CDATA[creature.ws]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26105</uri>
			</author>
			<updated>2012-12-06T10:40:51Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=66722#p66722</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Ожидание нескольких окон]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=66720#p66720" />
			<content type="html"><![CDATA[<div class="quotebox"><blockquote><p>Поток сознания.</p></blockquote></div><p><img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /><br />OnWindowActivated((&quot;ahk_class CabinetWClass&quot;, &quot;&quot;) отключает дальнейшее ожидание, это понятно.</p><p>Но как реализовать это:<br /></p><div class="codebox"><pre><code>
Space::
OnWindowActivated(&quot;ahk_class CabinetWClass&quot;, &quot;WaitForExplorerWindowActivated&quot;)
MsgBox Теперь активно 
return
</code></pre></div><p>непонятно.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2012-12-06T10:11:31Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=66720#p66720</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Ожидание нескольких окон]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=66716#p66716" />
			<content type="html"><![CDATA[<p>Не эквивалентно.</p><div class="quotebox"><blockquote><p>чтоб следующая строка […] выполнялась после окончания ожидания,</p></blockquote></div><div class="codebox"><pre><code>OnWindowActivated(&quot;ahk_class CabinetWClass&quot;, &quot;WaitForExplorerWindowActivated&quot;)
return

WaitForExplorerWindowActivated(hwnd) {
    OnWindowActivated(&quot;ahk_class CabinetWClass&quot;, &quot;&quot;)
    MsgBox окно проводника было активно, это событие более не будет обрабатываться
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[creature.ws]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26105</uri>
			</author>
			<updated>2012-12-06T09:52:11Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=66716#p66716</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Ожидание нескольких окон]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=66707#p66707" />
			<content type="html"><![CDATA[<p>Спасибо. Хороший код, настоящая многопоточность.<br />Но у меня к сожалению потребность заключается в том чтоб следующая строка после вызова функции выполнялась после окончания ожидания, типа:<br /></p><div class="codebox"><pre><code>OnWindowActivated(&quot;ahk_class CabinetWClass&quot;, &quot;WaitForExplorerWindowActivated&quot;)
MsgBox Теперь активно </code></pre></div><p>Эквивалентно<br /></p><div class="codebox"><pre><code>WinWaitActive ahk_class CabinetWClass
MsgBox Теперь активно</code></pre></div><div class="quotebox"><blockquote><p><strong>#6</strong><br />с помощью RunWait чтоб далее выполнялись действие 1 и действие 2 по окончанию ожидания.</p></blockquote></div>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2012-12-06T08:56:51Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=66707#p66707</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Ожидание нескольких окон]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=66689#p66689" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>#Include OnWindow.ahk

; при запуске скрипта начинаем ждать факт создания окна проводника
OnWindowCreated(&quot;ahk_class CabinetWClass&quot;, &quot;WaitForExplorerWindowCreated&quot;)
; при запуске скрипта начинаем ждать факт активации окна проводника
OnWindowActivated(&quot;ahk_class CabinetWClass&quot;, &quot;WaitForExplorerWindowActivated&quot;)

; при нажатии F2 переключаем ожидание активации окна проводника
F2::OnWindowActivated(&quot;ahk_class CabinetWClass&quot;,  OnWindowActivated(&quot;ahk_class CabinetWClass&quot;)? &quot;&quot;:&quot;WaitForExplorerWindowActivated&quot;)

WaitForExplorerWindowCreated(hWnd) {
    MsgBox,, %A_ThisFunc%:`n hWnd = %hWnd%, Действие 1
}

WaitForExplorerWindowActivated(hWnd) {
    MsgBox,, %A_ThisFunc%:`n hWnd = %hWnd%, Действие 2
}</code></pre></div><p>Содержимое файла OnWindow.ahk:<br /></p><div class="codebox"><pre><code>
OnWindowCreated(winTitle, procName = -1, maxThreads = 1) {
    return ManageShellHookEventListeners(&quot;HSHELL_WINDOWCREATED&quot;, winTitle, procName, maxThreads)
}

OnWindowActivated(winTitle, procName = -1, maxThreads = 1) {
    return ManageShellHookEventListeners(&quot;HSHELL_WINDOWACTIVATED&quot;, winTitle, procName, maxThreads)
}

ManageShellHookEventListeners(hookCode, ByRef winTitle, ByRef procName, ByRef maxThreads) {
    static ShellHookEventList
    static HookCodeList := {HSHELL_WINDOWCREATED: 1, HSHELL_WINDOWACTIVATED: 4}

    if !hookCode := HookCodeList[hookCode]
        return false

    IsObject(ShellHookEventList) || ShellHookEventList := ShellProc(-1, 0) ; здесь копируем ссылку
    IsObject(ShellHookEventList[hookCode]) || ShellHookEventList[hookCode] := Object()

    if (procName = -1)
        return ShellHookEventList[hookCode][winTitle].Name

    else if (procName = &quot;&quot;)
        return ShellHookEventList[hookCode].Remove(winTitle).Name

    else if IsFunc(procName) {
        shellhookWM := DllCall(&quot;RegisterWindowMessage&quot;, &quot;Str&quot;, &quot;SHELLHOOK&quot;, &quot;UInt&quot;)

        if !OnMessage(shellhookWM) {
            DllCall(&quot;RegisterShellHookWindow&quot;, &quot;Ptr&quot;, A_ScriptHwnd, &quot;Int&quot;)
            OnMessage(shellhookWM, &quot;ShellProc&quot;, maxThreads)
        }

        if !priorProcName := ShellHookEventList[hookCode].Remove(winTitle).Name
            priorProcName := procName

        ShellHookEventList[hookCode][winTitle] := Func(procName)
        return priorProcName
    }

    else return false
}

ShellProc(wParam, lParam) {
    static ShellHookEventList := {} ; здесь инициализируем

    if ShellHookEventList.HasKey(wParam) {
        for winTitle, Proc in ShellHookEventList[wParam]
            if WinExist(winTitle . &quot; ahk_id&quot; . lParam)
                %Proc%(lParam)
    }
    else if (wParam = -1)
        return ShellHookEventList
    else Sleep 0
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[creature.ws]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26105</uri>
			</author>
			<updated>2012-12-05T23:04:14Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=66689#p66689</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Ожидание нескольких окон]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=66687#p66687" />
			<content type="html"><![CDATA[<p>Что то я неподумал о том что RunWait тоже поток на ожидание <img src="//forum.script-coding.com/img/smilies/sad.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2012-12-05T21:12:59Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=66687#p66687</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Ожидание нескольких окон]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=66686#p66686" />
			<content type="html"><![CDATA[<p>Господа, есть скрипт в котором при запуске стартует цикл ожидания окон.<br />При работе скрипта хоткеями могут быть запущены ещё несколько потоков на ожидание с разными интервалами ожидания:<br /></p><div class="codebox"><pre><code>
запуск функции на ожидание
действие 1
действие 2
</code></pre></div><p>Почитал эту тему <a href="http://forum.script-coding.com/viewtopic.php?id=6739">http://forum.script-coding.com/viewtopic.php?id=6739</a> не понял, даже того относится ли оно как-то к сабжу.</p><p>Так понимаю что единственный выход это создавать файлы скриптов, и запускать их отдельным процессом с помощью RunWait чтоб далее выполнялись действие 1 и действие 2 по окончанию ожидания.</p><p>Есть какие-то другие варианты?<br />И каковы могут быть недостатки предложенного?</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2012-12-05T20:28:43Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=66686#p66686</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Ожидание нескольких окон]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=63398#p63398" />
			<content type="html"><![CDATA[<p>Понял. Спасибо за помощь.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2012-09-01T09:46:59Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=63398#p63398</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Ожидание нескольких окон]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=63397#p63397" />
			<content type="html"><![CDATA[<p>Так — работает, не работает — так, как пример пытаетесь использовать вы.</p><div class="codebox"><pre><code>List := {&quot;Безымянный — Блокнот&quot;: &quot;Блокнот&quot;, &quot;Program Manager&quot;: &quot;Раб. стол&quot;}
for key in List
    GroupAdd, MyGroup, %key%

Gui, +AlwaysOnTop -Border +ToolWindow
Gui, Color, Blue
Gui, font, s22
Gui, Add, Text, cWhite, Ждём Блокнот
Gui, Show, NoActivate x5 y5, §©?«®µ¶

WinWaitActive, ahk_group MyGroup
WinGetTitle, t, A
MsgBox % List[t]
Return</code></pre></div><p>А вообще, о чем речь то? Чем вас не устраивает собственный вариант из сообщения #1?</p>]]></content>
			<author>
				<name><![CDATA[creature.ws]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26105</uri>
			</author>
			<updated>2012-09-01T09:41:21Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=63397#p63397</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Ожидание нескольких окон]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=63396#p63396" />
			<content type="html"><![CDATA[<div class="quotebox"><blockquote><p>нужно чтоб выполнялся скрипт, и при этом ожидал несколько окон</p></blockquote></div><p>Так не работает, и на выходе нужно не &quot;Безымянный — Блокнот&quot; а &quot;Блокнот&quot;.</p><div class="codebox"><pre><code>Gui, +AlwaysOnTop -Border +ToolWindow
Gui, Color, Blue
Gui, font, s22
Gui, Add, Text, cWhite, Ждём Блокнот
Gui, Show, NoActivate x5 y5, §©?«®µ¶
Return

List := {&quot;Безымянный — Блокнот&quot;: &quot;Блокнот&quot;, &quot;Program Manager&quot;: &quot;Раб. стол&quot;}
for key in List
GroupAdd, MyGroup, %key%
WinWaitActive, ahk_group MyGroup
WinGetTitle, t, A
MsgBox % t
Return</code></pre></div>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2012-09-01T09:09:09Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=63396#p63396</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Ожидание нескольких окон]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=63379#p63379" />
			<content type="html"><![CDATA[<p>Скрипт, ожидающий окна из списка:<br /></p><div class="codebox"><pre><code>List := {&quot;Безымянный — Блокнот&quot;: &quot;Блокнот&quot;, &quot;Program Manager&quot;: &quot;Раб. стол&quot;}
for key in List
   GroupAdd, MyGroup, %key%
WinWaitActive, ahk_group MyGroup
WinGetTitle, t, A
MsgBox % t</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Irbis]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27384</uri>
			</author>
			<updated>2012-08-31T17:54:35Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=63379#p63379</id>
		</entry>
</feed>
