Einzelnen Beitrag anzeigen

BitWriter

Registriert seit: 21. Feb 2004
1 Beiträge
 
Delphi 7 Enterprise
 
#7

Re: Handle zu fensterlosem Programm

  Alt 18. Mär 2004, 15:23
Delphi-Quellcode:
//Kleiner Tipp: könnte noch vereinfacht werden...
//--------------------------------------------------
USES
    Windows; //u.a. für HWND
    ShellApi; //u.a. für FindExecutable()

function ShellExecPossible(PathName,FileName:string):boolean;
var lpFile, lpDirectory,
    ExeName : PChar;
begin
  ExeName:=StrAlloc(255);
  lpFile:=StrAlloc(255);
  lpDirectory:=StrAlloc(255);
  StrPCopy(lpDirectory, ExtractFilePath(PathName));
  StrPCopy(lpFile, FileName);
  Result:=FindExecutable(lpFile, lpDirectory, ExeName)>32;
  if Result and (ExeName<>'') and NOT(FileExists(ExeName)) then
    Result:=false;
  StrDispose(lpFile);
  StrDispose(ExeName);
  StrDispose(lpDirectory);
end;

procedure ShellExec(ApplHande: HWND;lpOperation,lpFile:string);
const
     lpDirectory='';
     lpParameter=nil;
     nShowCmd=SW_NORMAL;
begin
  ShellExecute(ApplHande, PChar(lpOperation), PChar(lpFile), PChar(lpDirectory), lpParameter, nShowCmd);
end;

// Aufruf:
// if ShellExecPossible(RunPath,RunPrg) then
// ShellExec(Application.Handle,'open',RunPath+RunPrg);
[edit=MrSpock]Codetags eingefügt. Mfg, MrSpock[/edit]
[edit=MrSpock] Mfg, MrSpock[/edit]
Mfg
BitWriter
  Mit Zitat antworten Zitat