<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: Эмуляция множественных потоков]]></title>
		<link>http://forum.script-coding.com/viewtopic.php?id=8584</link>
		<atom:link href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=8584&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Эмуляция множественных потоков».]]></description>
		<lastBuildDate>Sat, 17 Aug 2013 17:39:27 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: Эмуляция множественных потоков]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=74670#p74670</link>
			<description><![CDATA[<div class="quotebox"><cite>Irbis пишет:</cite><blockquote><p>Вопрос - для реализации двухстороннего обмена нужно передавать в &quot;дочку&quot; PID родителя, или обмен можно сделать по-другому?</p></blockquote></div><p>Но быстрее всего, конечно, передавать родительский PID в текст скрипта на этапе формирования через переменную.</p><p>Выяснилось, что &quot;хакерский&quot; способ передачи текста через WM_SETTEXT работает не совсем надёжно, т. к. это сообщение иногда проскакивает мимо OnMessage() и в таком случае обрабатывается окном, что приводит к смене заголовка на присланный текст. Поэтому посылать строку текста лучше по старинке через <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms649011%28v=vs.85%29.aspx">WM_COPYDATA</a>, как показано <a href="http://l.autohotkey.net/docs/commands/OnMessage.htm#SendString">здесь</a>. Если же нужно послать, например, максимум 2 числа в пределах 4Б (на 64-битных интерпретаторах — 8Б) каждое, можно воспользоваться <em>wParam</em> и <em>lParam</em> своего собственного сообщения, зарегистрированного через <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms644947%28v=vs.85%29.aspx">RegisterWindowMessage()</a>. В каждом из параметров можно послать также и сразу несколько чисел меньшего размера, используя для записи и чтения поразрядный сдвиг.</p><p>В примере ниже родительский скрипт посылает строку текста дочернему через WM_COPYDATA. Дочерний скрипт перед завершением посылает родительскому зарегистрированное сообщение WM_INFO, где в <em>wParam</em> единица, в <em>lParam</em> — PID.<br /></p><div class="codebox"><pre><code>ScriptManage := {}                           ; создаём объект для управления скриптами
ScriptManage.GetScript := Func(&quot;GetScript&quot;)  ; создаём несколько методов
ScriptManage.Run := Func(&quot;RunScript&quot;)    
ScriptManage.Terminate := Func(&quot;TerminateScript&quot;)
ScriptManage.Send := Func(&quot;SendStringToScript&quot;)

Gui, +LastFound +AlwaysOnTop
Gui, Add, Edit, x10 y12 vEdit, Эту строчку можно передать дочернему скрипту кнопкой Send.
Gui, Add, Button, x+-79 y+10 w80 gButton, Send
Gui, Add, Button, gButton x10 yp wp Default, Run
GuiControl, Focus, Run
Gui, Show, % &quot;y&quot; A_ScreenHeight//3, % &quot;Мой PID: &quot; ScriptManage.ParentID := DllCall(&quot;GetCurrentProcessId&quot;)

OnMessage(DllCall(&quot;RegisterWindowMessage&quot;, Str, &quot;WM_INFO&quot;), &quot;WM_INFO_RECEIVER&quot;)  ; регистрируем сообщение
OnExit, OnExit               ; которое будем использовать для принятия информации от дочернего скрипта

Loop
{
   WinSetTitle,,, % &quot;Мой PID: &quot; ScriptManage.ParentID &quot; Время: &quot; A_Hour &quot;:&quot; A_Min &quot;:&quot; A_Sec &quot;:&quot; A_MSec//100
   Sleep, 50
}
return

GuiClose:
   ExitApp
   
OnExit:
   for k in ScriptManage
      if k is integer
         ScriptManage.Terminate(k)
   ExitApp

Button:   
   if (A_GuiControl = &quot;Run&quot;)
   {
      ScriptManage.Run(1)   ; единица означает, что запускаем первый скрипт
                            ; у нас он один, но может быть сколько угодно
      GuiControl,, Edit1, Эту строчку можно передать дочернему скрипту кнопкой Send.
      GuiControl,, % A_GuiControl, Terminate
   }
   else if (A_GuiControl = &quot;Terminate&quot;)
      ScriptManage.Terminate(1)
   else
      ScriptManage.Send(1)
   return

RunScript(this, n)   ; здесь this — вызывающий объект, n — номер скрипта, который будем запускать
{
   FilePath := A_Temp &quot;\_MyScript_&quot; A_TickCount &quot;.ahk&quot;
   FileAppend, % this.GetScript(n), % FilePath
   Run, % FilePath,,, PID
   DetectHiddenWindows, On
   WinWait, % &quot;ahk_pid&quot; PID
   FileDelete, % FilePath
   this[n] := {PID: PID}  ; сохраняем PID дочернего скрипта в соответствующем ключе вызывающего объекта
}

TerminateScript(this, n)
{
   if !this[n].PID
      return
   WinClose, % &quot;ahk_pid&quot; this[n].PID
   this[n].PID := &quot;&quot;
}

SendStringToScript(this, n)
{
   DetectHiddenWindows, On
   if (this[n].PID = &quot;&quot;)
   {
      MsgBox, 0x2000,, Запустите дочерний скрипт кнопкой Run!
      return
   }
   
   GuiControlGet, Edit1
   VarSetCapacity(COPYDATASTRUCT, A_PtrSize*3)
   DataSize := (StrLen(Edit1) + 1)*(A_IsUnicode ? 2 : 1)
   NumPut(DataSize, COPYDATASTRUCT, A_PtrSize, &quot;UInt&quot;)
   NumPut(&amp;Edit1, COPYDATASTRUCT, A_PtrSize*2)
   
   Loop % Fail := 10
      SendMessage, WM_COPYDATA := 0x4A,, &amp;COPYDATASTRUCT,, % &quot;ahk_pid&quot; this[n].PID
   until ErrorLevel = 1 &amp;&amp; !Fail := &quot;&quot;
   
   if Fail
      MsgBox, 0x1010, Ошибка передачи данных, Передача текста не удалась!
}

WM_INFO_RECEIVER(wp, lp)
{
   global ScriptManage
   Command := wp, PID := lp
   if (Command = 1)
   {
      for k,v in ScriptManage
         if (v.PID = PID)
            v.PID := &quot;&quot;
         
      GuiControl,, Edit1, Дочерний процесс PID %PID% завершён!
      GuiControl,, Terminate, Run
   }
}
   
GetScript(this, n)
{
   ParentID := this.ParentID
   Script1 =
   (
      #NoTrayIcon
      SetBatchLines, -1
      PID := DllCall(&quot;GetCurrentProcessId&quot;), ParentID := %ParentID%
      OnExit, OnExit
      
      Gui, +AlwaysOnTop +Owner +LastFound
      Gui, Color, Gray
      Gui, Add, Progress, hwndhControl Border Background606060 x20 y20 w350 h50  
      Gui, Show, `% &quot;NA w390 h90 Hide&quot;, Мой PID: `%PID`%``, мой ParentID: `%ParentID`%
      WinGetPos, Xp, Yp, Wp,, `% &quot;ahk_pid&quot; ParentID
      WinGetPos, X,, W
      WinMove,,, Xp + (Wp - W)//2, Yp + 120
      WinShow

      Gui, 2:+Parent`%hControl`% -Caption +Lastfound
      Gui, 2:Color, 606060
      Gui, 2:Font, s20 cFFAA00, Verdana
      Gui, 2:Add, Text, x350 y6, Можно отправить сюда текст из главного скрипта!
      Gui, 2:Show, `% &quot;NA y0 x&quot; i := 0
      WinGetPos,,, Width 

      OnMessage(0x4A, &quot;WM_COPYDATA_READ&quot;)
      Loop
      { 
          Gui, 2:Show, `% &quot;NA y0 x&quot; -mod(++i, Width)
          Sleep 10
      }
      return

      GuiClose:
         ExitApp
         
      OnExit:
         PostMessage, DllCall(&quot;RegisterWindowMessage&quot;, Str, &quot;WM_INFO&quot;), 1, PID,, `% &quot;ahk_pid&quot; ParentID
         ExitApp

      WM_COPYDATA_READ(wp, lp)
      {
         global
         Text := StrGet(NumGet(lp + A_PtrSize*2))
         Gui, 2:New, +Parent`%hControl`% -Caption +Lastfound
         Gui, 2:Color, 606060
         Gui, 2:Font, s20 cFFAA00, Verdana
         Gui, 2:Add, Text, x350 y6, `% Text
         Gui, 2:Show, `% &quot;NA y0 x&quot; i := 0
         WinGetPos,,, Width
         return 1
      }
   )
   return Script%n%
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sat, 17 Aug 2013 17:39:27 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=74670#p74670</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Эмуляция множественных потоков]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=74651#p74651</link>
			<description><![CDATA[<p>А по-моему, без разницы <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" />. Можно передать текстом, можно узнать из дочернего скрипта PID родительского:<br /></p><div class="codebox"><pre><code>ScriptManage := {}                       ; создаём объект для управления скриптами
ScriptManage.Run := Func(&quot;RunScript&quot;)    ; создаём несколько методов
ScriptManage.Terminate := Func(&quot;TerminateScript&quot;)
ScriptManage.Send := Func(&quot;SendStringToScript&quot;)
OnExit, OnExit

Gui, +LastFound
Gui, Add, Edit, x10 vEdit, Это строчка, которая будет передана дочернему скрипту.
Gui, Add, Button, x+-79 y+10 w80 gButton, Send
Gui, Add, Button, gButton x10 yp wp Default, Run
GuiControl, Focus, Run
Gui, Show, % &quot;y&quot; A_ScreenHeight//3, % &quot;Мой PID: &quot; DllCall(&quot;GetCurrentProcessId&quot;)
return

GuiClose:
OnExit:
   for k, v in ScriptManage
      if k is integer
         ScriptManage.Terminate(k)
   ExitApp

Button:
   if (A_GuiControl = &quot;Run&quot;)
      ScriptManage.Run(1)   ; единица означает, что запускаем первый скрипт
                            ; у нас он один, но может быть сколько угодно
   if (A_GuiControl = &quot;Terminate&quot;)
      ScriptManage.Terminate(1)
   
   if (A_GuiControl = &quot;Send&quot;)
      ScriptManage.Send(1)
   
   if (A_GuiControl != &quot;Send&quot;)
      GuiControl,, % A_GuiControl, % A_GuiControl = &quot;Run&quot; ? &quot;Terminate&quot; : &quot;Run&quot;
   return

RunScript(this, n)   ; здесь this — вызывающий объект, n — номер скрипта, который будем запускать
{
   ;*********************** это текст скрипта, который будем запускать ************************
   Text1 =  
   (
      #NoTrayIcon 
      
      ParentID := ComObjGet(&quot;winmgmts:&quot;).Get(&quot;Win32_Process.Handle=&quot; DllCall(&quot;GetCurrentProcessId&quot;)).ParentProcessId
      
      Gui, +AlwaysOnTop +ToolWindow
      Gui, Color, Gray
      Gui, Add, Progress, hwndhControl Border Background606060 x20 y20 w350 h50  
      Gui, Show, `% &quot;NA w390 h90 y&quot; A_ScreenHeight//3 + 120, Мой родительский процесс: `%ParentID`%

      Gui, 2:+Parent`%hControl`% -Caption +Lastfound
      Gui, 2:Color, 606060
      Gui, 2:Font, s21 cFFAA00, Verdana
      Gui, 2:Add, Text, x350 y6, Можно отправить сюда текст из главного скрипта!
      Gui, 2:Show, NA x0 y0
      WinGetPos,,, Width 

      OnMessage(0xC, &quot;WM_SETTEXT&quot;)
      Loop
      { 
          Gui, 2:Show, `% &quot;NA y0 x&quot; i := i &lt; -Width ? 0 : i - 1 
          Sleep 10
      }
      return

      GuiClose:
         ExitApp

      WM_SETTEXT(wp, lp)
      {
         global
         Text := StrGet(lp)
         Gui, 2:New, +Parent`%hControl`% -Caption +Lastfound
         Gui, 2:Color, 606060
         Gui, 2:Font, s21 cFFAA00, Verdana
         Gui, 2:Add, Text, x350 y6, `% Text
         Gui, 2:Show, NA x0 y0
         i := 0
         WinGetPos,,, Width
         return 0
      }
   )
   ;******************************** ; конец текста скрипта ***********************************
   
   FilePath := A_Temp &quot;\_MyScript_&quot; A_TickCount &quot;.ahk&quot;
   FileAppend, % Text%n%, % FilePath
   Run, % FilePath,,, PID
   DetectHiddenWindows, On
   WinWait, % &quot;ahk_pid&quot; PID
   FileDelete, % FilePath
   this[n] := {PID: PID}  ; сохраняем PID дочернего скрипта в соответствующем ключе вызывающего объекта
}

TerminateScript(this, n)
{
   Process, Close, % this[n].PID
}

SendStringToScript(this, n)
{
   GuiControlGet, Text,, Edit1
   SendMessage, WM_SETTEXT := 0xC,, &amp;Text,, % &quot;ahk_pid &quot; this[n].PID
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Fri, 16 Aug 2013 16:25:05 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=74651#p74651</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Эмуляция множественных потоков]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=74650#p74650</link>
			<description><![CDATA[<p><strong>teadrinker</strong>, спасибо за красивый и полезный код!<br />Но порожденный процесс тоже ведь может передать информацию в процессе работы или вернуть код возврата в родительский.<br />Вопрос - для реализации двухстороннего обмена нужно передавать в &quot;дочку&quot; PID родителя, или обмен можно сделать по-другому?</p>]]></description>
			<author><![CDATA[null@example.com (Irbis)]]></author>
			<pubDate>Fri, 16 Aug 2013 15:52:06 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=74650#p74650</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Эмуляция множественных потоков]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=74647#p74647</link>
			<description><![CDATA[<p>Кстати, удалять файл дочернего скрипта можно сразу после появления его главного (скрытого) окна. Тогда код будет таким:<br /></p><div class="codebox"><pre><code>ScriptManage := {}                       ; создаём объект для управления скриптами
ScriptManage.Run := Func(&quot;RunScript&quot;)    ; создаём несколько методов
ScriptManage.Terminate := Func(&quot;TerminateScript&quot;)
ScriptManage.Send := Func(&quot;SendStringToScript&quot;)
OnExit, OnExit

Gui, +LastFound
Gui, Add, Edit, x10 vEdit, Это строчка, которая будет передана дочернему скрипту.
Gui, Add, Button, x+-79 y+10 w80 gButton, Send
Gui, Add, Button, gButton x10 yp wp Default, Run
GuiControl, Focus, Run
Gui, Show, % &quot;y&quot; A_ScreenHeight//3, Это главный скрипт:

Loop
{
   WinSetTitle, % &quot;Это главный скрипт: &quot; mod(A_Index, 100)
   Sleep, 100
}
return


GuiClose:
OnExit:
   for k, v in ScriptManage
      if k is integer
         ScriptManage.Terminate(k)
   ExitApp

Button:
   if (A_GuiControl = &quot;Run&quot;)
      ScriptManage.Run(1)   ; единица означает, что запускаем первый скрипт
                            ; у нас он один, но может быть сколько угодно
   if (A_GuiControl = &quot;Terminate&quot;)
      ScriptManage.Terminate(1)
   
   if (A_GuiControl = &quot;Send&quot;)
      ScriptManage.Send(1)
   
   if (A_GuiControl != &quot;Send&quot;)
      GuiControl,, % A_GuiControl, % A_GuiControl = &quot;Run&quot; ? &quot;Terminate&quot; : &quot;Run&quot;
   return

RunScript(this, n)   ; здесь this — вызывающий объект, n — номер скрипта, который будем запускать
{
   ;*********************** это текст скрипта, который будем запускать ************************
   Text1 =  
   (
      #NoTrayIcon 
      Gui, +AlwaysOnTop +ToolWindow
      Gui, Color, Gray
      Gui, Add, Progress, hwndhControl Border Background606060 x20 y20 w350 h50  
      Gui, Show, `% &quot;NA w390 h90 y&quot; A_ScreenHeight//3 + 120

      Gui, 2:+Parent`%hControl`% -Caption +Lastfound
      Gui, 2:Color, 606060
      Gui, 2:Font, s21 cFFAA00, Verdana
      Gui, 2:Add, Text, x350 y6, Можно отправить сюда текст из главного скрипта!
      Gui, 2:Show, NA x0 y0
      WinGetPos,,, Width 

      OnMessage(0xC, &quot;WM_SETTEXT&quot;)
      Loop
      { 
          Gui, 2:Show, `% &quot;NA y0 x&quot; i := i &lt; -Width ? 0 : i - 1 
          Sleep 10
      }
      return

      GuiClose:
         ExitApp

      WM_SETTEXT(wp, lp)
      {
         global
         Text := StrGet(lp)
         Gui, 2:New, +Parent`%hControl`% -Caption +Lastfound
         Gui, 2:Color, 606060
         Gui, 2:Font, s21 cFFAA00, Verdana
         Gui, 2:Add, Text, x350 y6, `% Text
         Gui, 2:Show, NA x0 y0
         i := 0
         WinGetPos,,, Width
         return 0
      }
   )
   ;******************************** ; конец текста скрипта ***********************************
   
   FilePath := A_Temp &quot;\_MyScript_&quot; A_TickCount &quot;.ahk&quot;
   FileAppend, % Text%n%, % FilePath
   Run, % FilePath,,, PID
   DetectHiddenWindows, On
   WinWait, % &quot;ahk_pid&quot; PID  ; ожидаем появления главного окна скрипта
   FileDelete, % FilePath
   this[n] := {PID: PID}  ; сохраняем PID дочернего скрипта в соответствующем ключе вызывающего объекта
}

TerminateScript(this, n)
{
   Process, Close, % this[n].PID
}

SendStringToScript(this, n)
{
   GuiControlGet, Text,, Edit1
   SendMessage, WM_SETTEXT := 0xC,, &amp;Text,, % &quot;ahk_pid &quot; this[n].PID
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Fri, 16 Aug 2013 15:13:50 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=74647#p74647</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Эмуляция множественных потоков]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=74630#p74630</link>
			<description><![CDATA[<p>Это реально гениально! То что надо! Огромное спасибо!</p>]]></description>
			<author><![CDATA[null@example.com (Strongest)]]></author>
			<pubDate>Fri, 16 Aug 2013 12:52:12 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=74630#p74630</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Эмуляция множественных потоков]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=74627#p74627</link>
			<description><![CDATA[<div class="quotebox"><cite>Strongest пишет:</cite><blockquote><p>Проблема в том, что не хочется для выполнения 1 задачи использовать много скриптов.</p></blockquote></div><p>Главный скрипт может формировать вспомогательный динамически просто из текста переменной, т. е. изначально будет всего один скрипт. Вот пример создания дочернего скрипта и передачи ему информации с помощью сообщений:<br /></p><div class="codebox"><pre><code>ScriptManage := {}                       ; создаём объект для управления скриптами
ScriptManage.Run := Func(&quot;RunScript&quot;)    ; создаём несколько методов
ScriptManage.Terminate := Func(&quot;TerminateScript&quot;)
ScriptManage.Send := Func(&quot;SendStringToScript&quot;)
OnExit, OnExit

Gui, +LastFound
Gui, Add, Edit, x10 vEdit, Это строчка, которая будет передана дочернему скрипту.
Gui, Add, Button, x+-79 y+10 w80 gButton, Send
Gui, Add, Button, gButton x10 yp wp Default, Run
GuiControl, Focus, Run
Gui, Show, % &quot;y&quot; A_ScreenHeight//3, Это главный скрипт:

Loop
{
   WinSetTitle, % &quot;Это главный скрипт: &quot; mod(A_Index, 100)
   Sleep, 100
}
return


GuiClose:
OnExit:
   for k, v in ScriptManage
      if k is integer
         ScriptManage.Terminate(k)
   ExitApp

Button:
   if (A_GuiControl = &quot;Run&quot;)
      ScriptManage.Run(1)   ; единица означает, что запускаем первый скрипт
                            ; у нас он один, но может быть сколько угодно
   if (A_GuiControl = &quot;Terminate&quot;)
      ScriptManage.Terminate(1)
   
   if (A_GuiControl = &quot;Send&quot;)
      ScriptManage.Send(1)
   
   if (A_GuiControl != &quot;Send&quot;)
      GuiControl,, % A_GuiControl, % A_GuiControl = &quot;Run&quot; ? &quot;Terminate&quot; : &quot;Run&quot;
   return

RunScript(this, n)   ; здесь this — вызывающий объект, n — номер скрипта, который будем запускать
{
   ;*********************** это текст скрипта, который будем запускать ************************
   Text1 =  
   (%    ; опция &quot;%&quot;, чтобы процент читался как литерал
      #NoTrayIcon 
      Gui, +AlwaysOnTop +ToolWindow
      Gui, Color, Gray
      Gui, Add, Progress, hwndhControl Border Background606060 x20 y20 w350 h50  
      Gui, Show, % &quot;NA w390 h90 y&quot; A_ScreenHeight//3 + 120

      Gui, 2:+Parent%hControl% -Caption +Lastfound
      Gui, 2:Color, 606060
      Gui, 2:Font, s21 cFFAA00, Verdana
      Gui, 2:Add, Text, x350 y6, Можно отправить сюда текст из главного скрипта!
      Gui, 2:Show, NA x0 y0
      WinGetPos,,, Width 

      OnMessage(0xC, &quot;WM_SETTEXT&quot;)
      Loop
      { 
          Gui, 2:Show, % &quot;NA y0 x&quot; i := i &lt; -Width ? 0 : i - 1 
          Sleep 10
      }
      return

      GuiClose:
         FileDelete, % A_ScriptFullPath
         ExitApp

      WM_SETTEXT(wp, lp)
      {
         global
         Text := StrGet(lp)
         Gui, 2:New, +Parent%hControl% -Caption +Lastfound
         Gui, 2:Color, 606060
         Gui, 2:Font, s21 cFFAA00, Verdana
         Gui, 2:Add, Text, x350 y6, % Text
         Gui, 2:Show, NA x0 y0
         i := 0
         WinGetPos,,, Width
         return 0
      }
   )
   ;******************************** ; конец текста скрипта ***********************************

   FilePath := A_Temp &quot;\_MyScript_&quot; A_TickCount &quot;.ahk&quot;
   FileAppend, % Text%n%, % FilePath
   Run, % FilePath,,, PID
   this[n] := {Path: FilePath, PID: PID}  ; сохраняем путь к файлу дочернего скрипта и его PID
}                                         ; в соответствующих ключах вызывающего объекта

TerminateScript(this, n)
{
   Critical
   Process, Close, % this[n].PID
   Process, WaitClose, % this[n].PID
   FileDelete, % this[n].Path
}

SendStringToScript(this, n)
{
   GuiControlGet, Text,, Edit1
   SendMessage, WM_SETTEXT := 0xC,, &amp;Text,, % &quot;ahk_pid &quot; this[n].PID
}</code></pre></div><p>Запускаем скрипт, нажимаем Run.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Fri, 16 Aug 2013 11:49:01 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=74627#p74627</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Эмуляция множественных потоков]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=74620#p74620</link>
			<description><![CDATA[<p>У AHK есть много плюсов относительно C++, то что тут делается в 1 строку, в C++ нужно писать целую функцию.</p>]]></description>
			<author><![CDATA[null@example.com (Strongest)]]></author>
			<pubDate>Fri, 16 Aug 2013 00:57:06 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=74620#p74620</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Эмуляция множественных потоков]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=74618#p74618</link>
			<description><![CDATA[<p>Проблема в том, что не хочется для выполнения 1 задачи использовать много скриптов.<br />Вот в этом и вопрос, возможно ли сделать как то без лишних запущенных процессов (скриптов).</p>]]></description>
			<author><![CDATA[null@example.com (Strongest)]]></author>
			<pubDate>Fri, 16 Aug 2013 00:03:23 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=74618#p74618</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Эмуляция множественных потоков]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=74617#p74617</link>
			<description><![CDATA[<p>Используйте сообщения. <br />Естественно скрипты останутся автономны.</p>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Thu, 15 Aug 2013 23:59:14 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=74617#p74617</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Эмуляция множественных потоков]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=74615#p74615</link>
			<description><![CDATA[<p>Задача такая, нужно что бы выполнялось несколько операций одновременно, и что бы они не мешали друг другу. Так как в скрипте нельзя запустить несколько потоков типа</p><div class="codebox"><pre><code>
SetTime, Lable1, 1000
SetTime, Lable2, 1000
SetTime, Lable3, 1000
</code></pre></div><p>Я сделал 4 скрипта: Главный скрипт анализирует работу, и производит манипуляцию с полученных данных от остальных 3 скриптов&nbsp; которые работают “Одновременно”.<br />Главный скрипт у меня получает сумму чисел сгенерированных в одно время случайных чисел в 3 остальных скриптах.</p>]]></description>
			<author><![CDATA[null@example.com (Strongest)]]></author>
			<pubDate>Thu, 15 Aug 2013 23:50:40 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=74615#p74615</guid>
		</item>
		<item>
			<title><![CDATA[AHK: Эмуляция множественных потоков]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=74610#p74610</link>
			<description><![CDATA[<p>Так как AHK не поддерживает много потоков одновременно, это очень сужает горизонты.<br />Хочется выслушать идеи, наработки людей как все таки с эмулировать множественные потоки под управлением «main» скрипта.<br />Приведу свой пример реализации, но он очень громоздкий, и не удобный.<br />Хочется выслушать экспертов…</p><p>MinScript<br /></p><div class="codebox"><pre><code>
Gui, Add, Text, h20 w100 vText, wiat
Gui, Add, Button, Default, Exit
Gui Show    
A := 0
B := 0
C := 0
Sum := 0
IniWrite, 0, test.ini, Script1, A
IniWrite, 0, test.ini, Script2, B
IniWrite, 0, test.ini, Script3, C
Run, Script1.ahk
Run, Script2.ahk
Run, Script3.ahk
Loop
{
    IniRead, A, test.ini, Script1, A, 0
    IniRead, B, test.ini, Script2, B, 0
    IniRead, C, test.ini, Script3, C, 0
    
    Sum := A+B+C
    
    GuiControl,,Text, %A% + %B% + %C% = %Sum%
}
    
ButtonExit:
IniRead, PID1, test.ini, Script1, PID
IniRead, PID2, test.ini, Script2, PID
IniRead, PID3, test.ini, Script3, PID
Process, Close, %PID1%
Process, Close, %PID2%
Process, Close, %PID3%
ExitApp
</code></pre></div><p>Script1<br /></p><div class="codebox"><pre><code>
Process, Exist
MyPID := ErrorLevel
IniWrite, %MyPid%, test.ini, Script1, PID
SetTimer Start, 2000

Loop
{

}

Start:
Random, A, 0, 100
IniWrite, %A%, test.ini, Script1, A
Return

</code></pre></div><p>Script2<br /></p><div class="codebox"><pre><code>
SetTimer Start, 2000
Process, Exist
MyPID := ErrorLevel
IniWrite, %myPid%, test.ini, Script2, PID
Loop
{

}

Start:
Random, B, 0, 100
IniWrite, %B%, test.ini, Script2, B
Return

</code></pre></div><p>Script3<br /></p><div class="codebox"><pre><code>
SetTimer Start, 2000
Process, Exist
MyPID := ErrorLevel
IniWrite, %myPid%, test.ini, Script3, PID
Loop
{

}

Start:
Random, C, 0, 100
IniWrite, %C%, test.ini, Script3, C
Return

</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Strongest)]]></author>
			<pubDate>Thu, 15 Aug 2013 23:01:40 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=74610#p74610</guid>
		</item>
	</channel>
</rss>
