Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7060855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:24:10+00:00 2026-05-28T04:24:10+00:00

I’m having problem with SHGetFileInfoW function I’m using. It’s a quite slow and first

  • 0

I’m having problem with SHGetFileInfoW function I’m using.

It’s a quite slow and first read on startup (Initialization) consumes 100ms.

In MSDN stays that it should be read from thread, not the main thread because it can stuck process.

I want to use some other function, if there is any, in order to read Icons.

Another thing. How is possible to read big icons, currently I can read up to 32×32 (SHGFI_LARGEICON)

Thanks!

Actual code:

procedure TForm1.LoadIcons;
var
  Info:     TShFileInfo;
  Icon:     TIcon;
  Flags:    UINT;
  FileName: PAnsiChar;

begin
  FileName := '.txt';
  Flags := SHGFI_USEFILEATTRIBUTES or SHGFI_ICON or SHGFI_LARGEICON;
  Icon := TIcon.Create;
  try
    SHGetFileInfo(FileName, FILE_ATTRIBUTE_NORMAL, Info,
      SizeOf(Info), Flags);
    Icon.Handle := Info.hIcon;
    Image1.Picture.Assign(Icon);
    Image1.Refresh;
  finally
    DestroyIcon(Info.hIcon);
    Icon.Free;
  end;
end;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:24:11+00:00Added an answer on May 28, 2026 at 4:24 am

    You could find the DefaultIcon for a given file extension from the Registry and use ExtractIconEx. Here is an example

    I don’t know if it’s faster than SHGetFileInfo

    EDIT:

    I have extracted (from the sample) the part which gets the ICON from the Extension.
    It actually works very fast. could be optimized more.
    (I modified the code a bit):

    // find the icon for a certain file extension in the registry
    function TForm1.RegistryIconExtraction(Extension : string): integer;
    var
        RegKey : TRegistry;
        IconPos : integer;
        AssocAppInfo : string;
        ExtractPath, FileName : string;
        IconHandle, PLargeIcon, PSmallIcon : HICON;
        AnIcon : TIcon;
    
    begin
      Result := 0; // default icon
    
      if Extension[1] <> '.' then Extension := '.' + Extension;
    
      RegKey := TRegistry.Create(KEY_READ);
      try
        // KEY_QUERY_VALUE grants permission to query subkey data.
        RegKey.RootKey := HKEY_CLASSES_ROOT; // set folder for icon info lookup
        if RegKey.OpenKeyReadOnly(Extension) then // extension key exists?
        try
          AssocAppInfo := RegKey.ReadString('');  // read app key
          RegKey.CloseKey;
        except
          Exit;
        end;
        if ((AssocAppInfo <> '') and  // app key and icon info exists?
          (RegKey.OpenKeyReadOnly(AssocAppInfo + '\DefaultIcon'))) then
        try
          ExtractPath := RegKey.ReadString(''); // icon path
          RegKey.CloseKey;
        except
           Exit;
        end;
      finally
        RegKey.Free;
      end;
    
      // IconPos after comma in key  ie: C:\Program Files\Winzip\Winzip.Exe,0
      // did we get a key for icon, does IconPos exist after comma seperator?
      If ((ExtractPath <> '') and (pos(',', ExtractPath) <> 0)) then
      begin
    
        // Filename in registry key is before the comma seperator
        FileName := Copy(ExtractPath, 1, Pos(',', ExtractPath) - 1);
        // extract the icon Index from after the comma in the ExtractPath string
        try
          IconPos := StrToInt(copy(ExtractPath, Pos(',', ExtractPath) + 1,
            Length(ExtractPath) - Pos(',', ExtractPath) + 1));
        except
          Exit;
        end;
    
        IconHandle := ExtractIconEx(PChar(FileName), IconPos, PLargeIcon, PSmallIcon, 1);
    
        If (PLargeIcon <> 0) then
        begin
          AnIcon := TIcon.Create;
          AnIcon.Handle := PLargeIcon;
    
          Image1.Picture.Assign(AnIcon);
          Image1.Refresh;
    
          AnIcon.Free;
        end;
    
        DestroyIcon(PLargeIcon);
        DestroyIcon(PSmallIcon);
      end;
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
      t1, t2: DWORD;
    begin
      t1 := GetTickCount;
      RegistryIconExtraction('.txt');
      t2 := GetTickCount;
      Memo1.Lines.Add(IntToStr(t2-t1));
    end;
    

    EDIT2: The sample code is now Vista/Win7 UAC compliant.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm making a simple page using Google Maps API 3. My first. One marker
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.