1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| procedure TForm12.Button1Click(Sender: TObject);
function ShellExecuteAndWait(vHandle : HWND;
vOperation : string;
vFichier : string;
vParametres : string;
vRepertoire : string;
vAffichage : Integer;
vDuree : DWORD) : string;
var
vSEInfo : TShellExecuteInfo;
begin
//Initialisation de la structure ShellExecuteInfo
ZeroMemory(@vSEInfo, SizeOf(vSEInfo));
//Remplissage de la structure ShellExecuteInfo
vSEInfo.cbSize := SizeOf(vSEInfo);
vSEInfo.fMask := $2000000;
vSEInfo.Wnd := vHandle;
vSEInfo.lpVerb := PAnsiChar(vOperation);
vSEInfo.lpFile := PAnsiChar(vFichier);
vSEInfo.lpParameters := PAnsiChar(vParametres);
vSEInfo.lpDirectory := PAnsiChar(vRepertoire);
vSEInfo.nShow := vAffichage;
//Execution
if ShellExecuteEx(@vSEInfo)
then //ShellExecuteEx OK : attendre la fin du process
begin
Application.ProcessMessages;
Sleep(10);
case WaitForInputIdle(vSEInfo.hProcess, vDuree) of
0: Result:='';
WAIT_FAILED: Result:= '[WAIT_FAILED] l''attente a échouée...';
WAIT_TIMEOUT: Result:= '[WAIT_TIME_OUT] Dépassement de temps...';
end;
end
else //ShellExecuteEx KO : renvoyer l'erreur
Result := 'Erreur ShellExecute: ' + IntToStr(GetLastError());
end;
var
msgErr: string;
begin
msgErr:=ShellExecuteAndWait(Application.Handle,
'open',
'"C:\Program Files (x86)\Mozilla Firefox\FireFox.EXE"',
'http://delphi.developpez.com/faq/?page=rechercher',
'',
SW_SHOWNORMAL,
INFINITE);
if msgErr='' then
begin
Showmessage('Réussite !!!');
sleep(3000);
keybd_event(72,0,1,0);
keybd_event(65,0,1,0);
keybd_event(78,0,1,0);
keybd_event(68,0,1,0);
keybd_event(76,0,1,0);
keybd_event(69,0,1,0);
end
else
MessageBox(0, PChar(msgErr), 'Erreur', MB_ICONERROR);
end; |
Partager