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
|
procedure TThreadVisualisation.Execute;
begin
ShellExecuteAndWait(FindWindow(nil,'Windows'),'open',m_fileName,'','',SW_SHOWNORMAL,INFINITE);
//Ouverture et attente de la fermeture du fichier
end;
function TThreadVisualisation.ShellExecuteAndWait(
vHandle : HWND;
vOperation : string;
vFichier : string;
vParametres : string;
vRepertoire : string;
vAffichage : Integer;
vDuree : DWORD ) : Cardinal;
var
vSEInfo : TShellExecuteInfo;
begin
//Initialisation de la structure ShellExecuteInfo
ZeroMemory(@vSEInfo, SizeOf(vSEInfo));
//Remplissage de la structure ShellExecuteInfo
vSEInfo.cbSize := SizeOf(vSEInfo);
vSEInfo.fMask := SEE_MASK_NOCLOSEPROCESS;
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
Result := Windows.WaitForSingleObject(vSEInfo.hProcess,vDuree)
//On attend la fermeture du fichier avant arrête du thread
else
begin
//ShellExecuteEx nOK : renvoyer l'erreur
Result := GetLastError();
end;
end; |
Partager