Articles   Members Online: 3
-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
How can I get the application associated with a document 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
22-May-03
Category
System
Language
Delphi 3.x
Views
60
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Ernesto De Spirito 

How can I get the application associated with a document?

Answer:

Where is that information? 

The applications associated with the file extensions are stored in the Windows 
Registry. To get this information first we should retrieve the "class" that a file 
extensions belongs to. This information can be found at: 

  HKEY_CLASSES_ROOT\.ext\(default) 

where ".ext" is the file extension you want (like ".txt", ".bmp", etc.). Then we 
get the command line used to open that kind of files. To do that, we retrieve the 
data under 

  HKEY_CLASSES_ROOT\class\Shell\Open\Command\(default) 

where "class" is the file class an extension belongs to. That string usually has 
the form 

  "D:\PATH\APPNAME.EXT" "%1" -OPTIONS 

where %1 is a placeholder for the document file to open with the application, so we 
should find its position within the string and replace it with the filename we want 
to open. 

Example 

The following function returns the command line of the associated application to 
open a documente file: 
1   
2   function GetAssociation(const DocFileName: string): string;
3   var
4     FileClass: string;
5     Reg: TRegistry;
6   begin
7     Result := '';
8     Reg := TRegistry.Create(KEY_EXECUTE);
9     Reg.RootKey := HKEY_CLASSES_ROOT;
10    FileClass := '';
11    if Reg.OpenKeyReadOnly(ExtractFileExt(DocFileName)) then
12    begin
13      FileClass := Reg.ReadString('');
14      Reg.CloseKey;
15    end;
16    if FileClass <> '' then
17    begin
18      if Reg.OpenKeyReadOnly(FileClass + '\Shell\Open\Command') then
19      begin
20        Result := Reg.ReadString('');
21        Reg.CloseKey;
22      end;
23    end;
24    Reg.Free;
25  end;


Copyright (c) 2001 Ernesto De Spiritomailto:edspirito@latiumsoftware.com
Visit: http://www.latiumsoftware.com/delphi-newsletter.php

			
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