Mega Code Archive

 
Categories / Delphi / Examples
 

Yet another take on located the application associated with an extension

Title: Yet another take on located the application associated with an extension Question: how to find the application associated with a given extension Answer: Seems like every other example I've seen involved checking the registry, so I figured I'd throw this one up since it does the exact same thing, but in a different manner(got to have options and all that) procedure TMnfrm.btnClick(Sender: TObject); var fst : TFileStream; App:array[0..255] of char; ret:integer; fnam,ext : String; begin app:=''; // I used a TCombobox to list a bunch of common extensions if extbox.Text = '' then extbox.ItemIndex:=0; ext := extbox.Text; if ext[1] '.' then insert('.',ext,1); // apnam is TEdit where I display the final result apnam.Text:=''; fnam:='tmp'+ext; // img is just a TImage img.Picture.Icon.ReleaseHandle; fst := TFileStream.Create(fnam,fmCreate OR fmShareDenyNone); fst.Free; {*Find the associated EXE for this file type*} ret:=FindExecutable(PChar(fnam),nil,App); if ret31 then begin //Assocation found! if ExtractFileName(app) fnam then begin apnam.Text:=ExtractFileName(app); // this line gets icon from the application img.Picture.Icon.Handle := ExtractIcon(Hinstance,app,0); end else apnam.Text:='No Associated App'; end else apnam.Text:='No Associated App'; deletefile(fnam); //clean up... end; So now have at least two ways of doing this, there are probably more, but I can't really say as I wish to persue this any further