Solved

Getting 48X48 Icons

Posted on 2004-04-16
10
1,629 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 33

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 33

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 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

18 Experts available now in Live!

Get 1:1 Help Now