Solved

Getting 48X48 Icons

Posted on 2004-04-16
10
1,622 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
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 17

Expert Comment

by:mokule
Comment Utility
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
Comment Utility

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

Author Comment

by:EddieShipman
Comment Utility
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
 
LVL 17

Expert Comment

by:mokule
Comment Utility
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
Comment Utility
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 26

Author Comment

by:EddieShipman
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry, but it is from an icon FILE, not an executable.
0
 
LVL 33

Expert Comment

by:Slick812
Comment Utility
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 33

Accepted Solution

by:
Slick812 earned 250 total points
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now