//调用窗体,以模式窗体的形式显示啦,你试一下面的代码啦!!<br>procedure TformMain.Button1Click(Sender:TObject); <br>var <br> F:TForm; <br> B:TButton; <br>begin <br> F:=TForm.Create(Self); <br> try <br> B:=TButton.Create(F); B.Parent:=F; <br> B.OnClick:=CreateProcessForm; B.ModalResult:=mrCancel; <br> F.Left:=Screen.Width; F.Top:=Screen.Height; //将窗口隐藏起来 <br> F.Width:=0; F.Height:=0; <br> PostMessage(B.Handle, BM_Click, 0, 0); <br> F.ShowModal; //调用模式窗口,由此窗口来创建进程,并等待进程结束。 <br> finally <br> F.Free; <br> end; <br>end; <br><br>procedure TformMain.CreateProcessForm(Sender:TObject); <br>var <br> StartUpInfo:TStartupInfo; <br> ProcessInfo:TProcessInformation; <br> seProcess, seThread: TSecurityAttributes; <br> S:String; <br> exCode
WORD; <br>begin <br> S:=ExtractFilePath(Application.ExeName)+'prjBoardLinker.exe'; <br> if not FileExists(S) then raise Exception.Create('找不到执行文件'+S); <br> FillChar(StartUpInfo, SizeOf(StartUpInfo), 0); <br> FillChar(seProcess, SizeOf(seProcess),0); <br> FillChar(seThread, SizeOf(seThread),0); <br> StartUpInfo.dwFlags:=STARTF_USESHOWWINDOW ; <br> seProcess.nLength := sizeof(seProcess); <br> seProcess.lpSecurityDescriptor := nil; <br> seProcess.bInheritHandle := true; <br> seThread.nLength := sizeof(seThread); <br> seThread.lpSecurityDescriptor := nil; <br> seThread.bInheritHandle := true; <br> if not CreateProcess(nil, PChar(S), @seProcess, @seThread, False, 0 , nil, nil, StartUpInfo, ProcessInfo) then <br> raise Exception.Create('创建进程'+S+'失败'); <br> GetExitCodeProcess(ProcessInfo.hProcess,exCode); <br><br> while(exCode=STILL_ACTIVE) do <br> begin <br> Sleep(10); <br> Application.ProcessMessages; <br> GetExitCodeProcess(ProcessInfo.hProcess,exCode); <br> end; <br>end;