whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

100 Visitors Online


 
...Associate an application with a file extension?
Autor: Simon Grossenbacher
Homepage: http://www.swissdelphicenter.ch
[ Print tip ]  

Tip Rating (5):  
     


uses
  
registry, shlobj;

procedure TForm1.RegisterFileType(prefix: string; exepfad: string);
var
  
reg: TRegistry;
begin
  
reg := TRegistry.Create;
  try
    
reg.RootKey := HKEY_CLASSES_ROOT;
    //create a new key  --> .pci
    
reg.OpenKey('.' + prefix, True);
    try
      
//create a new value for this key --> pcifile
      
reg.Writestring('', prefix + 'file');
    finally
      
reg.CloseKey;
    end;
    //create a new key --> pcifile
    
reg.CreateKey(prefix + 'file');
    //create a new key pcifile\DefaultIcon
    
reg.OpenKey(prefix + 'file\DefaultIcon', True);
    //and create a value where the icon is stored --> c:\project1.exe,0
    
try
      
reg.Writestring('', exepfad + ',0');
    finally
      
reg.CloseKey;
    end;
    reg.OpenKey(prefix + 'file\shell\open\command', True);
    //create value where exefile is stored --> c:\project1.exe "%1"
    
try
      
reg.Writestring('', exepfad + ' "%1"');
    finally
      
reg.CloseKey;
    end;
  finally
    
reg.Free;
  end;
  SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nilnil);
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  
RegisterFileType('pci', 'c:\project1.exe');
end;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners