Советы по Delphi

         

Запуск программы с ожиданием


Приведу код функции, вызываемой также, как и WinExec, но ожидающую заваршения вызванного приложения. Единственное различие - при успешном выполнении функция возвращает ноль.

    function WinExecAndWait(Path: PChar; Visibility: Word): Word; var InstanceID: THandle; Msg: TMsg; begin InstanceID := WinExec(Path, Visibility); if InstanceID < 32 then { значение меньшее чем 32 указывает на ошибку запуска } WinExecAndWait := InstanceID else repeat

while
PeekMessage(Msg, 0, 0, 0, pm_Remove) do begin if Msg.Message = wm_Quit then Halt(Msg.WParam); TranslateMessage(Msg); DispatchMessage(Msg); end; until GetModuleUsage(InstanceID) = 0; WinExecAndWait := 0; end;
[000352]



Содержание раздела