ورود

View Full Version : اجرای یک file و منتظر ماندن تا بسته شدن آن



ahmad_n80
یک شنبه 21 تیر 1388, 17:19 عصر
سلام
من کد زیر رو برای این کار انجام دادم :

function TForm1.ExecAndWait(const ExecuteFile,
ParamString: string): boolean;
var
SEInfo: TShellExecuteInfo;
ExitCode: DWORD;
begin
FillChar(SEInfo, SizeOf(SEInfo), 0);
SEInfo.cbSize := SizeOf(TShellExecuteInfo);
with SEInfo do
begin
fMask := SEE_MASK_NOCLOSEPROCESS;
//fMask :=SEE_MASK_NO_CONSOLE;

Wnd := Application.Handle;
lpFile := PChar(ExecuteFile);
//lpParameters := PChar(ParamString);
lpParameters := nil;
lpDirectory:=nil;
nShow := SW_SHOW;
end;

if not (ShellExecuteEx(@SEInfo)) then
begin
Result:=False;
end
else
begin
repeat
Application.ProcessMessages;
GetExitCodeProcess(SEInfo.hProcess, ExitCode);
until (ExitCode <> STILL_ACTIVE) or
Application.Terminated;
Result:=True;
end;
end;

اما یک مشکلی وجود داره و اون هم اینه که اگه یک فایل doc قبلا با برنامه word باز باشه و ما بخواهیم با تابع بالایی یک فایل doc دیگه بازکنیم باعث میشه که حلقه repeat فقط یکبار اجرا شده و مقدار True را بدون اینکه آن فایل بسته شود برگرداند .

پیشاپیش از کمک شما متشکرم .