Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
Member Area
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Become a Member
-Why sign up!
-Chat Online!
-Indexes NEW!!
-Build your resume
-Find a job
-Post a job
-Resume Search
-Link to us
Visit Embarcadero
Embarcadero Community
How to Register your own file extensions in the Windows registry Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Delphi 6.x
User Rating
No Votes
# Votes
DSP, Administrator
Reference URL:
			Author: William Gerbert 

I have an application that create files. I want those files to be associated to my 
application so that when you double click on those files will launch my application 
and open the particular file. How do I do this?


Take a look at the registry (HKEY_CLASSES_ROOT) to see what exactly is possible. 
Basically, you have to add an entry that equals the file extension, one that equals 
an unique name and the action. And you have to tell Windows that you have 
registered a new extension. Something like:

1   { ... }
2   var
3     Regist: TRegistry;
4   begin
5     Result
6       Regist := TRegistry.Create;
7     try
8       Regist.RootKey := HKEY_CLASSES_ROOT;
9       {file type}
10      if Regist.OpenKey('.xyz' {= your extension}, True) then
11      begin
12        Regist.WriteString('', 'xyz-file' {= unique name});
13        Regist.CloseKey;
14      end;
15      {name}
16      if Regist.OpenKey('xyz-file' {= same unique name}, True) then
17      begin
18        Regist.WriteString('', 'xyz super file'
19          {= short description, is shown in explorer});
20        Regist.CloseKey;
21      end;
22      {icon}
23      if Regist.OpenKey('xyz-file\DefaultIcon', True) then
24      begin
25        {third icon of your exe, 0 is the main icon I think, of course you can use 
26  			other files than Application.ExeName}
27        Regist.WriteString('', Application.ExeName + ', 3');
28        Regist.CloseKey;
29      end;
30      {open}
31      if Regist.OpenKey('xyz-file\Shell\Open\Command', True) then
32      begin
33        Regist.WriteString('', Application.ExeName + ' "%1"');
34          {or other/ additional parameters}
35        Regist.CloseKey;
36        Result := True;
37      end;
38      {you can add more for edit, print etc.}
39      SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
40      {tell Windows we have done it}
41    finally
42      Regist.Free;
43    end;
44  end;

Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10


Share this page
Download from Google

Copyright © Mendozi Enterprises LLC