Use Windows Explorer icons in my Delphi application.

Writing a cool little feature on a Delphi form with TTreeView.
Want to select, load and use Windows Explorer icons in my application, for various nodes.
This is a data tree, not file tree. Just want to use icons the users are familiar with.
Greg RowlandSoftware Designer, SysDBA, WebMaster OwnerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

What issue are you having?

Greg RowlandSoftware Designer, SysDBA, WebMaster OwnerAuthor Commented:
Load and use Windows Explorer or DLL icons in my application.
Greg RowlandSoftware Designer, SysDBA, WebMaster OwnerAuthor Commented:
Found these  2 windows SDK fucntions. Could use a code example of how to actully use them. unless there is a better way.

{ // SDK #1
The ExtractAssociatedIcon function returns the handle of an indexed icon found in a file or an icon found in an associated executable file.

HICON ExtractAssociatedIcon(

    HINSTANCE hInst,      // application instance handle
    LPTSTR lpIconPath,      // path and filename of file for which icon is wanted
    LPWORD lpiIcon       // pointer to icon index

{ SDK #2
he ExtractIcon function retrieves the handle of an icon from the specified executable file, dynamic-link library (DLL), or icon file.

HICON ExtractIcon(

    HINSTANCE hInst,      // instance handle
    LPCTSTR lpszExeFileName,      // filename of file with icon
    UINT nIconIndex       // index of icon to extract
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Greg RowlandSoftware Designer, SysDBA, WebMaster OwnerAuthor Commented:
This is one way to do it;
Found this code on, which I believe was actually plagiarized from Torry's Delphi Pages.


procedure TForm1.Button1Click(Sender: TObject);
  ExtrFileName = {Enter FileName.dll here};
  icon: TIcon;
  NumberOfIcons, i: Integer;
  icon := TIcon.Create;
    // Get the number of Icons
    NumberOfIcons := ExtractIcon(Handle, PChar(ExtrFileName), UINT(-1));
    ShowMessage(Format('%d Icons', [NumberOfIcons]));
    // Extract the first 5 icons of DLL
    for i := 1 to 5 do
      // Extract an icon
      icon.Handle := ExtractIcon(Handle, PChar(ExtrFileName), i);
      // Draw the icon on your form
      DrawIcon(Form1.Canvas.Handle, 10, i * 40, icon.Handle);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sinisa VukCommented:
Store your icons (extracted from exe) in timagelist component. Then it is quite easy to connect treeview with this imagelist.
Similar question was before on EE
I think you should check these functions from the Windows SDK:
Greg RowlandSoftware Designer, SysDBA, WebMaster OwnerAuthor Commented:
Thank you Sinisa Vuk, your comment was very helpful in the next step, the code example is what I really needed.
All the best, Greg
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.