1,183
社区成员
发帖
与我相关
我的任务
分享
var
h1553 : THandle;
h1553 := FindWindow(nil, 'BusTest');
if h1553<>NULL then
ShowMessage(IntToStr(SendMessage(h1553, WM_CLOSE, 0, 0)));
procedure TfrmMain.CreateProcessForm(Sender: TObject);
var
hHandle : THandle;
StartUpInfo:TStartupInfo;
ProcessInfo:TProcessInformation;
seProcess, seThread: TSecurityAttributes;
sPath:String;
exCode:DWORD;
begin
sPath := ExtractFilePath(Application.ExeName)+'BusTest.exe';
if not FileExists(sPath) then begin
MessageBox(Application.Handle, #10#13+'找不到总线测试程序,无法进行总线测试! '+#10#13+#10#13, '提示',
MB_OK+MB_ICONWARNING+MB_APPLMODAL);
Exit;
end;
FillChar(StartUpInfo, SizeOf(StartUpInfo), 0);
FillChar(seProcess, SizeOf(seProcess),0);
FillChar(seThread, SizeOf(seThread),0);
StartUpInfo.dwFlags:=STARTF_USESHOWWINDOW ;
seProcess.nLength := sizeof(seProcess);
seProcess.lpSecurityDescriptor := nil;
seProcess.bInheritHandle := true;
seThread.nLength := sizeof(seThread);
seThread.lpSecurityDescriptor := nil;
seThread.bInheritHandle := true;
if not CreateProcess(nil, PChar(sPath), @seProcess, @seThread, False, 0 ,
nil, nil, StartUpInfo, ProcessInfo) then begin
raise Exception.Create('创建总线测试进程失败');
end;
hHandle := 0;
while (hHandle=0) do
begin
sleep(30);
hHandle:=FindWindow(nil,'BusTest');
end;
Windows.SetParent(hHandle, frmMain.tbs1553b.Handle);
Windows.MoveWindow(hHandle, -4, -29, 1000 , 800 , true);
GetExitCodeProcess(ProcessInfo.hProcess,exCode);
while(exCode=STILL_ACTIVE) do
begin
Sleep(100);
Application.ProcessMessages;
GetExitCodeProcess(ProcessInfo.hProcess,exCode);
end;
end;
PostThreadMessage(ProcessInfo.hProcess