Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > API de Windows
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 02-06-2015
pokexperto1 pokexperto1 is offline
Miembro
NULL
 
Registrado: dic 2013
Posts: 35
Poder: 0
pokexperto1 Va por buen camino
Question ¿Validar ShellExecute con Try?

Ya se que mi pregunta será un poco tonta pero quiero que mi programa abra una pag web en el exlorador (eso funciona bien), pero quiero que saber si no lo ha conseguido abrir. He probado con:
Código Delphi [-]
try
  ShellExecute(Handle, 'open', 'descargar.htm', nil, nil, SW_SHOW);
except
  sel := MessageDlg('No se ha encontrado el archivo de recuperación, reinstala por favor', mtCustom, [mbOk], 0);
  close;
end;

Última edición por nlsgarcia fecha: 02-06-2015 a las 23:32:51. Razón: Formateo Delphi
Responder Con Cita
  #2  
Antiguo 03-06-2015
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola pokoexperto1.

La función ShellExecute devuelve un valor, que es mayor o igual a 32 cuando se ejecuta con éxito o, de modo contrario, representa el tipo de error.

Podrías intentar algo similar a este ejemplo:
Código Delphi [-]
var
  Msg: string;
  Err: LongWord;
begin
  Err := ShellExecute(Handle, 'open', 'descargar.htm', nil, nil, SW_SHOW);
  if Err <= 32 then
  begin
    case Err of
       2: Msg := 'File not found';
       3: Msg := 'Path not found';
       5: Msg := 'Access denied';
       8: Msg := 'Out of memory';
      26: Msg := 'Cannot share an open file';
      27: Msg := 'File association information not complete';
      28: Msg := 'DDE operation timed out';
      29: Msg := 'DDE operation failed';
      30: Msg := 'DDE operation is busy';
      31: Msg := 'File association not available';
      else
        Msg := 'Unspecified Error';
    end;
    MessageBox(Handle ,PChar(Msg), '', MB_ICONERROR + MB_OK);
  end;

Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....

Última edición por ecfisa fecha: 03-06-2015 a las 01:38:17.
Responder Con Cita
  #3  
Antiguo 03-06-2015
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Poder: 21
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
pokexperto1,

Cita:
Empezado por pokexperto1
...¿Validar ShellExecute con Try?...quiero saber si no lo ha conseguido abrir...


Revisa este código:
Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ShellAPI;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
   NameApp : PChar;
   ErrMsg : Integer;

begin

   NameApp := 'C:\Windows\System32\xNotepad.exe';

   ErrMsg := ShellExecute(Handle, nil, NameApp, nil, nil, SW_SHOW);

   if (ErrMsg <= 32) then
      raise Exception.CreateFmt('ShellExecute Error %d : %s',[GetLastError,SysErrorMessage(GetLastError)]);

end;

end.
El código anterior en Delphi 7 sobre Windows 7 Professional x32, Levanta una excepción si la función ShellExecute devuelve un código de error, como se muestra en la siguiente imagen:



Revisa esta información:
Cita:
Empezado por Microsoft

ShellExecute function


Return value Type: HINSTANCE

If the function succeeds, it returns a value greater than 32. If the function fails, it returns an error value that indicates the cause of the failure. The return value is cast as an HINSTANCE for backward compatibility with 16-bit Windows applications. It is not a true HINSTANCE, however. It can be cast only to an int and compared to either 32 or the following error codes below.

Return codeDescription 0 : The operating system is out of memory or resources.
ERROR_FILE_NOT_FOUND : The specified file was not found.
ERROR_PATH_NOT_FOUND : The specified path was not found.
ERROR_BAD_FORMAT : The .exe file is invalid (non-Win32 .exe or error in .exe image).
SE_ERR_ACCESSDENIED : The operating system denied access to the specified file.
SE_ERR_ASSOCINCOMPLETE : The file name association is incomplete or invalid.
SE_ERR_DDEBUSY : The DDE transaction could not be completed because other DDE transactions were being processed.
SE_ERR_DDEFAIL : The DDE transaction failed.
SE_ERR_DDETIMEOUT : The DDE transaction could not be completed because the request timed out.
SE_ERR_DLLNOTFOUND : The specified DLL was not found.
SE_ERR_FNF : The specified file was not found.
SE_ERR_NOASSOC : There is no application associated with the given file name extension. This error will also be returned if you attempt to print a file that is not printable.
SE_ERR_OOM : There was not enough memory to complete the operation.
SE_ERR_PNF : The specified path was not found.
SE_ERR_SHARE : A sharing violation occurred.


Tomado de : ShellExecute function
Espero sea útil

Nelson.

Última edición por nlsgarcia fecha: 03-06-2015 a las 16:47:31.
Responder Con Cita
  #4  
Antiguo 05-06-2015
pokexperto1 pokexperto1 is offline
Miembro
NULL
 
Registrado: dic 2013
Posts: 35
Poder: 0
pokexperto1 Va por buen camino
Smile Gracias :D

Gracias a todo al final ya esta solucionado.
Por si a alguien le interesa el codigo:
Código Delphi [-]
procedure TForm1.FormCreate(Sender: TObject);
begin
  if fileexists(directorio + 'ini.ini') then
  begin
  cargarinis;
  end
  else
  begin
    Errorinicio();
  end;
  directorio := getcurrentdir;
  try
    form2.fondo1.Picture.LoadFromFile(directorio + 'fondo1.jpg');
    form2.fondo2.Picture.LoadFromFile(directorio + 'fondo2.jpg');
    form2.platoentero.Picture.LoadFromFile(directorio + 'plato_entero.png');
    form2.platoroto.Picture.LoadFromFile(directorio + 'plato_roto.png');
  except
    Errorinicio();
  end;
end;

procedure TForm1.Errorinicio();
var
  sel: integer;
  error: integer;
begin
  sel := MessageDlg
    ('Parece ser que no tienes los archivos necesarios para el juego, ¿Quieres que lo solucione?',
    mtError, mbOKCancel, 0);
  if sel = 1 then
  begin
    sel := MessageDlg('Se va a abrir el navegador. ¿Proceder?...', mtCustom,
      mbOKCancel, 0);
    if sel = 1 then
      error := ShellExecute(Handle, 'open', 'descargar.htm', nil, nil, SW_SHOW);
      if (error <= 32) then
        sel := MessageDlg
          ('No se ha encontrado el archivo de recuperación, reinstala el juego por favor',
          mtCustom, [mbOk], 0);
      application.Terminate;
    end
  else
  begin
    sel := MessageDlg('El juego se va a cerrar', mtCustom, [mbOk], 0);
    application.Terminate;
  end;
end;
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Shellexecute mjjj Varios 2 11-09-2007 17:41:21
ShellExecute jorodgar Varios 8 07-05-2007 13:46:15
ShellExecute erfedecai API de Windows 4 26-06-2006 19:12:46
shellexecute. REHome API de Windows 2 26-09-2005 11:23:25
shellexecute sarga API de Windows 2 17-04-2004 12:47:26


La franja horaria es GMT +2. Ahora son las 20:43:53.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi