**
** 主进程.exe
**
DECLARE LONG SendMessage IN user32 LONG, LONG, LONG, LONG
#define MY_MSG0x401
_screen.Visible = .F.
SET DEFAULT TO ADDBS(JUSTPATH(SYS(16)))
SET SAFETY OFF
CREATE TABLE tt (f1 I, f2 I)
USE tt ALIAS tt AGAIN SHARED
of = CREATEOBJECT("form1")
of.show
READ EVENTS
CLOSE DATABASES ALL
CLEAR ALL
RETURN
DEFINE CLASS form1 as Form ShowWindow = 2 AutoCenter = .T. Caption = "主进程" hWnd2 = 0 ADD OBJECT cmd as commandbutton WITH left=10,top=10,height=22,caption="开始" ADD OBJECT grid1 as grid WITH left=10,top=40 PROCEDURE Destroy CLEAR EVENTS ENDPROC PROCEDURE init BINDEVENT(this.hWnd, MY_MSG, this, "myMsg") ENDPROC PROCEDURE myMsg(hWnd, uMsg, wParam, lParam) DO CASE CASE wParam==0 this.hWnd2 = lParam CASE wParam==1 this.grid1.refresh GO BOTTOM in "tt" this.grid1.setfocus CASE wParam==2 SendMessage(thisform.hWnd2, MY_MSG, 0, 0) this.cmd.Caption = "开始" ENDCASE ENDPROC PROCEDURE cmd.click DO CASE CASE this.Caption == "开始" this.Caption = "暂停" cmd = "RUN /7N 子进程.exe "+TRANSFORM(thisform.hWnd) EXECSCRIPT(cmd) CASE this.Caption == "暂停" this.Caption = "继续" SendMessage(thisform.hWnd2, MY_MSG, 1, 0) CASE this.Caption == "继续" this.Caption = "停止" SendMessage(thisform.hWnd2, MY_MSG, 2, 0) CASE this.Caption == "停止" this.Caption = "开始" SendMessage(thisform.hWnd2, MY_MSG, 3, 0) ENDCASE ENDPROC
ENDDEFINE
**
** 子进程.exe
**
LPARAMETERS hWnd
DECLARE LONG SendMessage IN user32 LONG, LONG, LONG, LONG
DECLARE LONG PostMessage IN User32 LONG, LONG, LONG, LONG
#DEFINE MY_MSG0x401
_screen.Visible = .F.
SET DEFAULT TO ADDBS(JUSTPATH(SYS(16)))
SET SAFETY OFF
CLOSE DATABASES ALL
USE tt IN 0 ALIAS tj AGAIN SHARED
of = CREATEOBJECT("form1")
of.hWnd1 = INT(VAL(hWnd))
of.show
READ EVENTS
CLOSE DATABASES ALL
CLEAR ALL
RETURN
DEFINE CLASS form1 as Form ShowWindow = 2 Caption = "子进程" hWnd1 = 0 bStop = .F. bPause = .F. ADD OBJECT grid1 as grid WITH left=10,top=10 PROCEDURE Destroy CLEAR EVENTS ENDPROC PROCEDURE init BINDEVENT(this.hWnd, MY_MSG, this, "myMsg") ENDPROC PROCEDURE myMsg(hWnd, uMsg, wParam, lParam) DO CASE CASE wParam == 0 this.Release CASE wParam == 1 this.bPause = .T. CASE wParam == 2 this.bPause = .F. CASE wParam == 3 this.bStop = .T. ENDCASE ENDPROC PROCEDURE Activate SendMessage(this.hWnd1, MY_MSG, 0, this.hWnd) i = 0 DO WHILE !this.bStop AND i<10 IF !this.bPause i = i + 1 INSERT INTO tj VALUES (i, i*2) this.grid1.setfocus PostMessage(this.hWnd1, MY_MSG, 1, 0) ENDIF INKEY(1) ENDDO PostMessage(this.hWnd1, MY_MSG, 2, 0) ENDPROC
ENDDEFINE