Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
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
29-Sep-02
Category
Win API
Language
Delphi 5.x
Views
116
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			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?

Answer:

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

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC