Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 784
  • Last Modified:

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.
0
Greg Rowland
Asked:
Greg Rowland
2 Solutions
 
mlmccCommented:
What issue are you having?

mlmcc
0
 
Greg RowlandSoftware Designer, SysDBA, WebMaster OwnerAuthor Commented:
Load and use Windows Explorer or DLL icons in my application.
0
 
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
   );
}
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Greg RowlandSoftware Designer, SysDBA, WebMaster OwnerAuthor Commented:
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
 
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
0
 
ariohCommented:
I think you should check these functions from the Windows SDK:
EnumResourceNames
LoadImage
0
 
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
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now