Ver Mensaje Individual
  #4  
Antiguo 19-06-2024
ArtPortEsp ArtPortEsp is offline
Miembro
 
Registrado: may 2018
Ubicación: Mexico
Posts: 176
Reputación: 9
ArtPortEsp Va por buen camino
Cita:
Empezado por duilioisola Ver Mensaje
RunAndWait para Windows.
Si avriguas como hacerlo en Linux puedes tener la misma función compilada según un {$IFDEF WIN32} ...{$ENDIF WIN32}, {$IFDEF LINUX}...{$ENDIF LINUX}.

Código Delphi [-]
function RunAndWait(Handle: THandle; Ejecutable, Argumentos: string; const RunDirectory: PChar = nil; const Visibilidad: integer = SW_SHOWNORMAL; MensajeSiCorrecto: boolean = True): DWORD;
var
  Info : TShellExecuteInfo;
  pInfo : PShellExecuteInfo;
  ExitCode : word;
  P : PChar;
begin
  { Puntero a Info }
  { Pointer to Info }
  pInfo := @Info;
  { Rellenamos Info }
  { Fill info }
  with Info do
  begin
     cbSize := SizeOf(Info);
     fMask := SEE_MASK_NOCLOSEPROCESS;
     wnd := Handle;
     lpVerb := nil;
     lpFile := PChar(Ejecutable);
     { Parametros al ejecutable }
     { Executable parameters }
     lpParameters := PChar(Argumentos + #0);
     if RunDirectory = '' then
        lpDirectory := nil
     else
        lpDirectory := PChar(RunDirectory + #0);
     nShow := Visibilidad;
     hInstApp := 0;
  end;
  { Ejecutamos }
  { Execute }
  if not ShellExecuteEx(pInfo) then
  begin
     Result := GetLastError;
     if FormatMessage(Format_Message_Allocate_Buffer + Format_Message_From_System,
        nil,
        Result,
        0, @P,
        0,
        nil) <> 0 then
     begin
        // Display the string.
        ShowMessage(P);
        // Free the buffer.
        LocalFree(integer(P));
     end;
  end
  else
     Result := 0; // Info.hInstApp;

  { Esperamos que termine }
  { Wait to finish }
  repeat
     ExitCode := WaitForSingleObject(Info.hProcess, 500);
     Application.ProcessMessages;
  until (ExitCode <> WAIT_TIMEOUT);
  ExitCode := GetLastError;

  GetExitCodeProcess(Info.hProcess, Result);
  if ((Result < 32) and (ExitCode = 0)) then
  begin
     ExitCode := GetLastError;
     if FormatMessage(Format_Message_Allocate_Buffer + Format_Message_From_System,
        nil,
        ExitCode,
        0, @P,
        0,
        nil) <> 0 then
     begin
        // Display the string.
        if MensajeSiCorrecto or (ExitCode <> 0) then
           ShowMessage(P);
        // Free the buffer.
        LocalFree(integer(P));
     end;
  end
  else
     Result := 0; // Info.hInstApp;
end;

Primero que nada, muchas gracias!; no estoy seguro, pero al ser una aplicación de consola, no podría usar ShowMessage y cosas que tengan que ver con la GUI de windows verdad?

Al estar Shellexecute en la librería WinApi, no estaría también ligado a windows?...

Entiendo lo de la compilación condicional, en su caso tambien deberia condicionar los elementos que son para interfaz grafica?
Responder Con Cita