Einzelnen Beitrag anzeigen

QuickAndDirty

Registriert seit: 13. Jan 2004
Ort: Hamm(Westf)
1.883 Beiträge
 
Delphi 12 Athens
 
#12

AW: Problem mit ShellExecute und Windows 8

  Alt 19. Jan 2013, 11:19
WaitForSingleObject
funktioniert nur für Anwendungen mit nur einem "Fenster" oder mit ConsolenAnwendungen.

Deswegen habe ich das in "meiner" Funktion (zusammen mit ungefähr allen DP mitgliedern entwickelt) durch MsgWaitForMultipleObject ersetzt!

Delphi-Quellcode:
function ExecAndWait(Filename, Params: string; TimeOut:Integer=-1 ; WindowState: word = SW_SHOWNORMAL): boolean;
var
  ShExecInfo: SHELLEXECUTEINFO;
  started,r : Cardinal;

  const
  SEE_MASK_NOASYNC= $100;
begin
  Result := false;
  if Filename = 'then
    exit;
  if not FileExists(FileName) then
  Begin
    ShowMessage('Datei nicht existent!');
    Exit;
  End;
  ZeroMemory(@ShExecInfo, SizeOf(ShExecInfo));
  ShExecInfo.Wnd := application.Handle;
  ShExecInfo.cbSize := sizeof(SHELLEXECUTEINFO);
  ShExecInfo.fMask := SEE_MASK_NOCLOSEPROCESS or SEE_MASK_NOASYNC;
  ShExecInfo.lpVerb := 'open';
  ShExecInfo.lpFile := PChar(Filename);
  ShExecInfo.lpParameters := PChar(Params);
  ShExecInfo.lpDirectory := PChar(ExtractFileDir(Filename));
  ShExecInfo.nShow := WindowState;
  Result := ShellExecuteEx(@ShExecInfo);
  if Result then
  begin
    started := Gettickcount;
    repeat
      R := MsgWaitForMultipleObjects(1, ShExecInfo.hProcess, False, TimeOut, QS_ALLINPUT);
      if r <> WAIT_OBJECT_0 then
        Application.ProcessMessages;
    until (r = WAIT_OBJECT_0) or ( (Timeout >-1) and ( Started + TimeOut < GetTickCount )) ;
    if (timeout > -1) then
      Result := not( Started + TimeOut < GetTickCount );
    CloseHandle(ShExecInfo.hProcess);
  end
  else
    Showmessage(SysErrorMessage(GetLastError));

End;
Andreas
Monads? Wtf are Monads?

Geändert von QuickAndDirty (19. Jan 2013 um 11:22 Uhr)
  Mit Zitat antworten Zitat