1. Computing

Associate an application with a file extension

By

The code in the OnClick for Button1 sets "adp" to be opened by "c:\myadpapp.exe".

~~~~~~~~~~~~~~~~~~~~~~~~~
uses registry, shlobj;

procedure RegisterFileType(ExtName:String; AppName:String) ;
var
   reg:TRegistry;
begin
  reg := TRegistry.Create;
  try
   reg.RootKey:=HKEY_CLASSES_ROOT;
   reg.OpenKey('.' + ExtName, True) ;
   reg.WriteString('', ExtName + 'file') ;
   reg.CloseKey;
   reg.CreateKey(ExtName + 'file') ;
   reg.OpenKey(ExtName + 'file\DefaultIcon', True) ;
   reg.WriteString('', AppName + ',0') ;
   reg.CloseKey;
   reg.OpenKey(ExtName + 'file\shell\open\command', True) ;
   reg.WriteString('',AppName+' "%1"') ;
   reg.CloseKey;
  finally
   reg.Free;
  end

  SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil) ;
end;


procedure TForm1.Button1Click(Sender: TObject) ;
begin
   RegisterFileType('adp','c:\myadpapp.exe') ;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Drag from ListBox to Edit
« Get Cursor position in TRichEdit

©2014 About.com. All rights reserved.