回复 20楼 吹水佬
感谢!有空研究一下。
以下是引用吹水佬在2021-3-12 12:12:12的发言:
最简单的示例(消息)
** 主进程
** test1.exe
**
cDefPath = ADDBS(JUSTPATH(SYS(16)))
_screen.Visible = .F.
DECLARE LONG SendMessage IN User32 LONG, LONG, LONG, LONG
of = CREATEOBJECT("Form1")
of.show
READ EVENTS
RETURN
DEFINE CLASS Form1 as Form
ShowWindow = 2
hSubpro = 0
ADD OBJECT cmd as CommandButton WITH top=10,left=10,height=22,caption="启动子进程"
ADD OBJECT edt as EditBox WITH top=40,left=10,width=300,height=200
PROCEDURE Init
BINDEVENT(this.hWnd, 0x401, this, "_Message")
ENDPROC
PROCEDURE Destroy
IF this.hSubpro > 0
SendMessage(this.hSubpro, 0x401, 0, 0)
ENDIF
CLEAR EVENTS
ENDPROC
PROCEDURE cmd.Click
oApp = CREATEOBJECT("Shell.Application")
oApp.ShellExecute(cDefPath+"test2.exe", TRANSFORM(thisform.hWnd), "", "", 1)
ENDPROC
PROCEDURE _Message(hWnd, nMsg, wParam, lParam)
DO CASE
CASE wParam == 1
this.edt.SelText = "子进程启动" + 0h0D0A
this.hSubpro = lParam
CASE wParam == 2
this.edt.SelText = "子进程关闭" + 0h0D0A
ENDCASE
ENDPROC
ENDDEFINE
** 子进程
** test2.exe
**
PARAMETERS cParam
_screen.Visible = .F.
DECLARE LONG SendMessage IN User32 LONG, LONG, LONG, LONG
of = CREATEOBJECT("Form1", cParam)
of.show
READ EVENTS
RETURN
DEFINE CLASS Form1 as Form
ShowWindow = 2
AutoCenter = 1
hMain = 0
PROCEDURE Init(cParam)
this.hMain = INT(VAL(cParam))
SendMessage(this.hMain, 0x401, 1, this.hWnd)
BINDEVENT(this.hWnd, 0x401, this, "_Message")
ENDPROC
PROCEDURE Destroy
IF this.hMain> 0
SendMessage(this.hMain, 0x401, 2, 0)
ENDIF
CLEAR EVENTS
ENDPROC
PROCEDURE _Message(hWnd, nMsg, wParam, lParam)
DO CASE
CASE wParam == 0
MESSAGEBOX("主程序关闭")
this.Release
CASE wParam == 1
CASE wParam == 2
ENDCASE
ENDPROC
ENDDEFINE
最简单的示例(消息)
** 主进程
** test1.exe
**
cDefPath = ADDBS(JUSTPATH(SYS(16)))
_screen.Visible = .F.
DECLARE LONG SendMessage IN User32 LONG, LONG, LONG, LONG
of = CREATEOBJECT("Form1")
of.show
READ EVENTS
RETURN
DEFINE CLASS Form1 as Form
ShowWindow = 2
hSubpro = 0
ADD OBJECT cmd as CommandButton WITH top=10,left=10,height=22,caption="启动子进程"
ADD OBJECT edt as EditBox WITH top=40,left=10,width=300,height=200
PROCEDURE Init
BINDEVENT(this.hWnd, 0x401, this, "_Message")
ENDPROC
PROCEDURE Destroy
IF this.hSubpro > 0
SendMessage(this.hSubpro, 0x401, 0, 0)
ENDIF
CLEAR EVENTS
ENDPROC
PROCEDURE cmd.Click
oApp = CREATEOBJECT("Shell.Application")
oApp.ShellExecute(cDefPath+"test2.exe", TRANSFORM(thisform.hWnd), "", "", 1)
ENDPROC
PROCEDURE _Message(hWnd, nMsg, wParam, lParam)
DO CASE
CASE wParam == 1
this.edt.SelText = "子进程启动" + 0h0D0A
this.hSubpro = lParam
CASE wParam == 2
this.edt.SelText = "子进程关闭" + 0h0D0A
ENDCASE
ENDPROC
ENDDEFINE
** 子进程
** test2.exe
**
PARAMETERS cParam
_screen.Visible = .F.
DECLARE LONG SendMessage IN User32 LONG, LONG, LONG, LONG
of = CREATEOBJECT("Form1", cParam)
of.show
READ EVENTS
RETURN
DEFINE CLASS Form1 as Form
ShowWindow = 2
AutoCenter = 1
hMain = 0
PROCEDURE Init(cParam)
this.hMain = INT(VAL(cParam))
SendMessage(this.hMain, 0x401, 1, this.hWnd)
BINDEVENT(this.hWnd, 0x401, this, "_Message")
ENDPROC
PROCEDURE Destroy
IF this.hMain> 0
SendMessage(this.hMain, 0x401, 2, 0)
ENDIF
CLEAR EVENTS
ENDPROC
PROCEDURE _Message(hWnd, nMsg, wParam, lParam)
DO CASE
CASE wParam == 0
MESSAGEBOX("主程序关闭")
this.Release
CASE wParam == 1
CASE wParam == 2
ENDCASE
ENDPROC
ENDDEFINE
在主进程中启动子进程还是要用到timer ……,如果每分钟启动子进程一次!