//Start a DOS program from Delphi 1 and wait for it to finish
//The following Delphi1 procedure executes a DOS program and waits until it finished. Parameter HWindow is the window handle of the calling application, typically you would pass Application.MainForm.Handle there.
//The key function is GetModuleUsage to determine whether the DOS module is still in memory - this function is not available in in Delphi 2/3.
//执行一个dos程序并等待他结束
procedure ExecAndWait(HWindow:HWnd; ExecStr: PChar; CmdShow: word);
var
M : TMsg;
Erg : word;
ErgStr,
MsgStr : array[0..128] of char;
begin
Erg:=WinExec(ExecStr,CmdShow);
if Erg < 32 then
begin
str(erg, ergstr);
strcopy(msgstr,'Could not execute program. Error #: ');
strcat (msgstr, ergstr);
MessageBox(hwindow, ergstr, execstr, mb_ok or mb_iconstop);
end
else
begin { exec waits! }
ShowWindow(hwindow, sw_hide);
repeat
while PeekMessage(m,0,0,0,pm_remove) do
begin
if m.Message=wm_quit then
begin
PostQuitMessage(m.wparam);
exit;
end
else
begin
translatemessage(m);
dispatchmessage(m);
end;
end;
until GetModuleUsage(erg)=0;
ShowWindow(hwindow, sw_shownormal);
end;
end;