ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Image with default WIndows icon
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

AndyColmes

USA
351 Posts

Posted - Mar 27 2014 :  03:45:30  Show Profile  Reply
I am trying to create an image with a fixed size like 128x128 that represents a file type at runtime. Basically, I need to find the icon representing a file type in the computer's Windows OS, then adding that to the 128x128 canvas as a layer, finally flattening it to create an image. My difficulty at this point is how to get the icon registered on the computer's file type to do this.

Thanks for any help in advance.

w2m

USA
1990 Posts

Posted - Mar 27 2014 :  09:16:59  Show Profile  Reply
This is not a easy or even moderately easy task for a number of reasons.

1. The sizes of the available icons are not the same between operating systems especially pre-Vista. Jumbo icons are only available on Vista, Windows7 and Windows 8.
2. Not all file system icons have a 128x128 icon.
3. Most file system icons have small (16x16), large(32x32) and extra large (48x48) icons.
4. Many have jumbo icons (256x256), especially with Vista OS and higher.
5. What do you do when an icon is missing in the size you want? If a jumbo icon is available then it is a simple matter to resample the image to the smaller size. If a jumbo icon is not available then resizing the smaller icon to a larger size will not look very good.

If most have jumbo icons then you can resample the icon down to 128x128, but when you do this with imageen, you will loose transparency, so you will have to recreate the alphachannel so they are transparent.

To get the icons you can try the following code:
const
  SHIL_LARGE = $00;
  // The image size is normally 32x32 pixels. However, if the Use large icons option is selected from the Effects section of the Appearance tab in Display Properties, the image is 48x48 pixels.
  SHIL_SMALL = $01;
  // These images are the Shell standard small icon size of 16x16, but the size can be customized by the user.
  SHIL_EXTRALARGE = $02;
  // These images are the Shell standard extra-large icon size. This is typically 48x48, but the size can be customized by the user.
  SHIL_SYSSMALL = $03;
  // These images are the size specified by GetSystemMetrics called with SM_CXSMICON and GetSystemMetrics called with SM_CYSMICON.
  SHIL_JUMBO = $04;
  // Windows Vista and later. The image is normally 256x256 pixels.
  IID_IImageList: TGUID = '{46EB5926-582E-4017-9FDF-E8998DAA0950}';

procedure GetIconFromFile(AFile: String; var AIcon: TIcon;
  SHIL_FLAG: Cardinal);
{ Get the system image icon for small, large, extra large and jumbo. }
var
  iImgList: HIMAGELIST;
  iSFI: TSHFileInfo;
  iIndex: integer;
begin // Get the index of the imagelist
  SHGetFileInfo(PChar(aFile), FILE_ATTRIBUTE_NORMAL, iSFI, SizeOf(TSHFileInfo),
    SHGFI_ICON or SHGFI_LARGEICON or SHGFI_SHELLICONSIZE or
    SHGFI_SYSICONINDEX or SHGFI_TYPENAME or SHGFI_DISPLAYNAME);
  if not Assigned(AIcon) then
    AIcon := TIcon.Create;
  // get the imagelist
  iImgList := GetImageListSH(SHIL_FLAG);
  // get index
  iIndex := iSFI.iIcon;
  // extract the icon handle
  AIcon.Handle := ImageList_GetIcon(iImgList, iIndex, ILD_NORMAL);
end;

procedure TForm1.GetIcon1Click(Sender: TObject);
var
  iIcon: TIcon;
begin
  {SHIL_JUMBO- 256x256}
  iIcon := TIcon.Create;
  try
    GetIconFromFile(Filename1.Text, iIcon, SHIL_JUMBO);
    { Assign to TImage }
    Image1.Picture.Icon.Assign(iIcon);
    Image1.Update;
  finally
    iIcon.Free;
  end;
end;

I have not been able to determine how get an icon of a specific size like 128x128. If you figure out how to get an icon of 128x128 size please let me know. There is some discussion about this at stackoverflow.com:
http://stackoverflow.com/questions/1703186/can-48x48-or-64x64-icons-be-obtained-from-the-vista-shell

William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Custom ImageEn Development
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: