本帖最后由 cihren 于 2014-12-1 09:34 编辑
近日研究多进程,发现子进程可以母进程发送消息,但母进程却无法向子进程发送消息,不得其解,晒晒:#include "CoProc.au3"
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 354, 118)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$Button1 = GUICtrlCreateButton("Button1", 16, 32, 97, 49)
GUICtrlSetOnEvent(-1, "Button1Click")
$Button2 = GUICtrlCreateButton("Button1", 128, 32, 97, 49)
GUICtrlSetOnEvent(-1, "Button2Click")
$Button3 = GUICtrlCreateButton("Button1", 240, 32, 97, 49)
GUICtrlSetOnEvent(-1, "Button3Click")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
_CoProcReciver("Receiver")
$hA = _CoProc("A")
$hB = _CoProc("B")
$hC = _CoProc("C")
While 1
Sleep(100)
WEnd
Func Button1Click()
MsgBox(0,"","btn1")
_CoProcSend($hA,"AAA") ;按下Button1后向子进程发送消息,无反应!!!
_CloseHandle($hA) ;按下Button1后关闭子进程,无反应!!!
EndFunc
Func Button2Click()
_CoProcSend($hB,"BBB")
EndFunc
Func Button3Click()
_CoProcSend($hC,"CCC")
EndFunc
Func Form1Close()
Exit
EndFunc
Func Receiver($sParama)
MsgBox(0,"Receive Msg",$sParama)
EndFunc
Func A()
While ProcessExists($gi_CoProcParent)
Sleep(5000)
;MsgBox(0,"A","AAAAA",1)
;_CoProcSend($gi_CoProcParent,"From AAA!!") ;这条语句向母进程发送消息,母进行能够收到并显示
WEnd
EndFunc
Func B()
While ProcessExists($gi_CoProcParent)
Sleep(5000)
;MsgBox(0,"B","BBBBB",1)
WEnd
EndFunc
Func C()
While ProcessExists($gi_CoProcParent)
Sleep(5000)
;MsgBox(0,"C","CCCCC",1)
WEnd
EndFunc
|