🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #8063

Re: File association icons

#8063
From: AlexB
Date: Wed, 01 Dec 2004 07:58
92 lines
3718 bytes
Tog wrote:

> how do I make windows display my custom icons for associations 
> related to my applications?

Search in groups.google.com for answer.
For example (Delphi code):
--------------------
Carl Olsen (carlolsen@omax.com)
Re: Associate file extension

View this article only
borland.public.delphi.winapi
2001-09-17 16:38:49 PST

Here is a routine:

////////////////////////////////////////////////////////////////////////////
////
function
RegisterAssociation(ExeName,FileExt,FileDesc:String;FileIcon:String):boolean
;
{
   This function registers a file association.

   ExeName   is the full path and name of the exe that will be associated
with the extension.
   FileExt   is the extension of the file to register i.e. ".dxf" or .ord".
   FileDesc  is the description of the file. i.e. "Drawing Exchange File".
   FileIcon  is the location of the icon to associate with this file type.
             For example "C:\MyApplicationLocation\Myapplication.exe,0"
             Note the ",0" means use the icon associated with the .exe.
             You can also say ",1" to use the next icon, if one exists.
             Or you can pass the name of the icon itself such as:
             "C:\MyApplication\Icons\MyIcon.ico".
   Note: You may have to re-boot the PC before the associated icon will
change.
   Note: When end user double clicks on the registered file type, your .exe
         will launch, and the file name will be passed via ParamStr(1).
         (If the file name contains spaces, then it may also be passed in
          ParamStr(2), etc.)
}
Var
   FileClass:String;
begin

   Result:=false;

   FileExt:=Trim(FileExt);
   If FileExt='' then exit;
   If FileExt[1]<>'.' then FileExt:='.'+FileExt;

   FileClass:=Copy(FileExt,2,Length(FileExt))+'file';

   With TRegistry.create do
   begin
     Try
       RootKey:=HKEY_CLASSES_ROOT;
       if OpenKey(FileExt,True) then
       begin
         WriteString('',FileClass);
         CloseKey;
       end;
       if OpenKey(FileClass,True) then
       begin
         WriteString('',FileDesc);
         CloseKey;
       end;
       if OpenKey(FileClass+'\Shell\Open',True) then
       begin
         WriteString('','&Open');
         CloseKey;
       end;
       if OpenKey(FileClass+'\Shell\Open\command',True) then
       begin
         WriteString('',ExeName+' "%1"');
         CloseKey;
         Result:=true;
       end;
       {Register an icon file with the application.}
       if OpenKey(FileClass+'\DefaultIcon',True) then
       begin
         WriteString('',FileIcon);
         CloseKey;
       end;
     Finally
       Free;
     end;
   end;

end;
--------------------
Technical Details
Message-ID: <41ad79c0@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news4.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <41ad54e0@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,ea6877066ea144fe
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Wed, 01 Dec 2004 13:58:43 +0600
From: AlexB <b.a.v@inbox.ru>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax)
X-Accept-Language: ru, en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: File association icons
References: <41ad54e0@newsgroups.borland.com>
In-Reply-To: <41ad54e0@newsgroups.borland.com>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 212.192.185.54
Message-ID: <41ad79c0@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1101887936 212.192.185.54 (30 Nov 2004 23:58:56 -0700)
Lines: 92
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news4.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail