Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Getting 48X48 Icons

Posted on 2004-04-16
Medium Priority
Last Modified: 2007-12-19
ExtractIconEX will allow you to get large and small icons from an ICO file.

However, this only works on the 32X32 and 16X16 size icons.

What do I use to get the 48X48 icons and how do I tell HOW MANY icons are in the file?
Question by:EddieShipman
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
  • 3
  • 3
  • 2
  • +2
LVL 17

Expert Comment

ID: 10845646
I don't know how much is it correct, but to detect icon count I'm using this code.
It seems to work fine.

  while ExtractIconEx(PChar(ComboBox1.Items[ComboBox1.ItemIndex]),
            Index, LargeIconHandle,SmallIconHandle, 1) = 2 do

Expert Comment

ID: 10845723

u want to make such a program like this one http://www.icon-editor.net/iconmaker.exe?
LVL 26

Author Comment

ID: 10845824
mokule: I don't see how that returns the NUMBER of icons in the file.

waldin: No, just want to be able to LOAD the correct icon.
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

LVL 17

Expert Comment

ID: 10845984
Sorry for some mess
Should be
ExtractIconEx('filename', -1, LargeIconHandle,SmallIconHandle, 1)

Return Value

If the nIconIndex parameter is -1, the phiconLarge parameter is NULL, and the phiconSmall parameter is NULL, then the return value is the number of icons contained in the specified file. Otherwise, the return value is the number of icons successfully extracted from the file.

LVL 17

Expert Comment

ID: 10846138
LVL 26

Author Comment

ID: 10846402
Yes, passing null, null, -1 to ExtractIconEx does return the number.

Now, from what I'm reading, you must use LoadImage to load a 48X48 icon, it seems.

Any comments?
LVL 20

Expert Comment

ID: 10848296

"There are two ways to retrieve an object's icon. The simplest way is to call SHGetFileInfo. However, this approach is inflexible and may be rather slow. A more flexible and efficient way to retrieve an item's icon is to use IExtractIcon. The Shell uses IExtractIcon to retrieve icons when it displays the contents of a folder. To use IExtractIcon to retrieve an object's icon:

   1. Get a pointer to the IShellFolder interface of the folder that contains the object.
   2. Call IShellFolder::GetUIObjectOf with the pointer to an item identifier list (PIDL) of the object and the interface identifier (ID) of IExtractIcon (IID_IExtractIcon). The folder creates an object to handle the icon extraction, and returns the object's IExtractIcon interface pointer.
   3. Call IExtractIcon::GetIconLocation to retrieve the icon's location.
   4. Call IExtractIcon::Extract to retrieve the icon's handle."
LVL 26

Author Comment

ID: 10851533
Sorry, but it is from an icon FILE, not an executable.
LVL 34

Expert Comment

ID: 10851900
hello  EddieShipman,   If you are asking about getting icon information from Icon Files  .ICO  , you may have to read the Icon file headers, to getthis information.
 the first  Six bytes of th icon file is the  main icon file header, and looks like this -

TIconCurHeader = packed record
    wReserved: Word;
    wType: Word;  // has icon or cursor
    wCount: Word;  // has the number of individual bitmaps for icons in the file

You can use TFileStream or the delphi File to read the fifth and sixth bytes of the file as a word to get the number of icons in the file

after these header six bytes, there are the Icon headers which look like this -

  TIconSpec = packed record
    iWidth: Byte;
    iHeight: Byte;
    iColors: Word;
    Reserved1: Word;
    Reserved2: Word;
    DIBSize: Longint;
    DIBOffset: Longint;

there is one of these headers for every icon in the file

you can read the first or second byte to get the width or height
not all Icon  files have a  48x48  size icon in them, any icons the system needs that are not in the icon file, it creates

LVL 34

Accepted Solution

Slick812 earned 1000 total points
ID: 10854243
If you only need   Ico  file 48 size icons, you might try this code, the  hIconL  will be the Icon Handle for a 48 size Icon

procedure TForm1.button_Get48hIconClick(Sender: TObject);
IcoFilePath: String;
DeskTopISF: IShellFolder;
PathPidl: PItemIDList;
IEIcon: IExtractIcon;
hIconL, hIconS: HICON;
  this was made to ONLY work with  .ICO  files}
IcoFilePath := 'E:\ico folder\zTes3.ico';
if (not FileExists(IcoFilePath)) or
  (LowerCase(ExtractFileExt(IcoFilePath)) <> '.ico') then
  ShowMessage('ERROR = BAD Icon File Name');

if SHGetDesktopFolder(DeskTopISF) <> NOERROR then
  ShowMessage('ERROR = SHGetDesktopFolder FAILURE');

PathPidl := nil;
{this DOES NOT get any Shell Interface for the Icon File}
if DeskTopISF.GetUIObjectOf(Handle,1, PathPidl,IID_IExtractIconA, nil, IEIcon) <> NOERROR then
  ShowMessage('ERROR = DeskTopISF.GetUIObjectOf  FAILED');

  {I just use the Icon file path with Index Zero, there is NO Shell Interface Object,
    so this will NOT work on files that do NOT have icons in them, like .txt  or  .wav }
if IEIcon.Extract(PChar(IcoFilePath),0,hIconL, hIconS, 48 or (16 shl 16)) = NOERROR then
  DrawIconEx(Canvas.Handle,60,49, hIconL, 0, 0, 0, 0, DI_NORMAL) else
    ShowMessage('FAILURE - IExIcon Extract');

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

636 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