Solved

Getting 48X48 Icons

Posted on 2004-04-16
10
1,640 Views
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?
0
Comment
Question by:EddieShipman
[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
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 10845646
Hi
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
    begin
    DestroyIcon(LargeIconHandle);
    DestroyIcon(SmallIconHandle);
    Inc(Index);
    end;
0
 

Expert Comment

by:walidn
ID: 10845723

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

Author Comment

by:EddieShipman
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.
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 17

Expert Comment

by:mokule
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.

0
 
LVL 17

Expert Comment

by:mokule
ID: 10846138
0
 
LVL 26

Author Comment

by:EddieShipman
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?
0
 
LVL 20

Expert Comment

by:Madshi
ID: 10848296
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/ifaces/iextracticon/iextracticon.asp

"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."
0
 
LVL 26

Author Comment

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

Expert Comment

by:Slick812
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
  end;

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;
  end;

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

0
 
LVL 34

Accepted Solution

by:
Slick812 earned 250 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);
var
IcoFilePath: String;
DeskTopISF: IShellFolder;
PathPidl: PItemIDList;
IEIcon: IExtractIcon;
hIconL, hIconS: HICON;
begin
{WARNING ! !
  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
  begin
  ShowMessage('ERROR = BAD Icon File Name');
  Exit;
  end;

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

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
  begin
  ShowMessage('ERROR = DeskTopISF.GetUIObjectOf  FAILED');
  Exit;
  end;

  {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');
end;
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

749 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