Solved

Use Windows Explorer icons in my Delphi application.

Posted on 2014-09-08
8
628 Views
Last Modified: 2014-09-17
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.
0
Comment
Question by:Greg Rowland
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 40312098
What issue are you having?

mlmcc
0
 
LVL 4

Author Comment

by:Greg Rowland
ID: 40312136
Load and use Windows Explorer or DLL icons in my application.
0
 
LVL 4

Author Comment

by:Greg Rowland
ID: 40312150
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
   );
}
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Accepted Solution

by:
Greg Rowland earned 0 total points
ID: 40312713
This is one way to do it;
Found this code on VBForums.com, which I believe was actually plagiarized from Torry's Delphi Pages.

uses
  shellApi;

procedure TForm1.Button1Click(Sender: TObject);
const
  ExtrFileName = {Enter FileName.dll here};
var
  icon: TIcon;
  NumberOfIcons, i: Integer;
begin
  icon := TIcon.Create;
  try
    // 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
    begin
      // 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);
    end;
  finally
    icon.Free;
  end;
end;
0
 
LVL 27

Assisted Solution

by:Sinisa Vuk
Sinisa Vuk earned 500 total points
ID: 40312779
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
0
 
LVL 9

Expert Comment

by:arioh
ID: 40321945
I think you should check these functions from the Windows SDK:
EnumResourceNames
LoadImage
0
 
LVL 4

Author Closing Comment

by:Greg Rowland
ID: 40327554
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
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MS Access from Delphi 31 79
BATCH to EXE Converter 2 67
Back-end Database connect string being set someplace where I can't find it. 10 45
"lblTime is not declared" 3 30
In this post we will learn different types of Android Layout and some basics of an Android App.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question