🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: BCB6: Getting SYS Icons

#4226
From: Andrue Cope [TeamB]
Date: Wed, 08 Mar 2006 15:30
87 lines
3388 bytes
poojo hackma wrote:

> It was simple enough to copy the technique, but I want to extend it
> to files not located on my PC (i.e. files over a network).
> 
> I want to say, "Give me my PC's default Windows icon for a .cpp,
> .doc, .pdf, .jpg, etc."  I want the icon that my PC has registered
> for that particular type of file to appear in a TListView.

We just use ExtractAssociatedIcon() but reviewing the code suggests
that someone implemented a work around at one point:

[snip]
  {
    WORD iconIndex=0;

    char damnMicrosoft[ MAXPATH+1 ];
    strcpy( damnMicrosoft, FileName.c_str() );
    result=ExtractAssociatedIcon( HInstance,
                                  damnMicrosoft,
                                  &iconIndex );
  }

  return result;
}

AFAIK this is all we do for conventional files local or networked but
we have another type of file that isn't available to windows. It may be
that our solution for that would work for you as well:

  if( IsVirtualF )
  { // Virtual object
    if( !IsADirF )
    {
      char *extZ=strrchr( FileName.c_str(), '.' );

      if( extZ )
      {
        AnsiString ext=extZ;

        Reg->RootKey=HKEY_CLASSES_ROOT;

        {
          if( Reg->OpenKey( "\\"+ext, false ) )
          {
            AnsiString key=Reg->ReadString( "" );
            if( Reg->OpenKey( "\\"+key, false ) )
            {
              if( Reg->OpenKey( "DefaultIcon", false ) )
              {
                AnsiString iconPath=Reg->ReadString("");

                char *commaPosn=strrchr( iconPath.c_str(), ',' );

                AnsiString iconNumber=0;

                if( commaPosn )
                {
                  iconNumber=commaPosn+1;

                  iconPath.SetLength( commaPosn-iconPath.c_str() );
                }

                if( FileExists( iconPath )||
                    iconPath.Pos( "%SystemRoot%" ) )
                {
                  result=ExtractIcon( Application->Handle,
                                      iconPath.c_str(),
                                      iconNumber.ToInt() );
                }
                else
                  ext=".COM";
              }
            }
          }

          Reg->CloseKey();
        }
      }
    }

..and FWIW the significance of that 'ext=".COM";' escapes me. Time for
a little bit of editing methinks :)
-- 
Andrue Cope [TeamB]
[Bicester, Uk]
http://info.borland.com/newsgroups/guide.html
Technical Details
Message-ID: <440ef8ab@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.cw.net!cw.net!news-FFM2.ecrc.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <440ef041$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,9456c511753bafd3
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Andrue Cope [TeamB]" <no.spam@not.a.valid.address>
Subject: Re: BCB6: Getting SYS Icons
Newsgroups: borland.public.cppbuilder.nativeapi
References: <440ef041$1@newsgroups.borland.com>
Date: Wed, 8 Mar 2006 15:30:52 +0000
User-Agent: XanaNews/1.17.6.6
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
NNTP-Posting-Host: 217.207.223.34
Message-ID: <440ef8ab@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1141831851 217.207.223.34 (8 Mar 2006 07:30:51 -0700)
Lines: 87
X-Authenticated-User: acope
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.cw.net!cw.net!news-FFM2.ecrc.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail