About Icons/Icon Extraction (Article)
Version Compatibility: Visual Basic 6
Instructions: Copy the declarations and code below and paste directly into your VB project.
About Icons /Icon Edit
The purpose of this posting is to remove the general fallacies relating to icons / icon edit.
Though I have stopped posting code on web site (Planet Source Code and FreeVBCOde.com) since two/three years ago (due to time constraints, I still like these sites for their excellent facilities and for its vitality in general, hence I would occasionally roll in for a brief visit. Recently I have come across quite a number of postings on the subject of icon edit, icon editor, icon extraction or conversion. Unfortunately, most of the codes manifest the incorrect approaches.
The following is a summary of fallacious impressions carried in the above-said postings:
1. If Explorer displays their images as icons, the ICO files must be valid ones.
Comment: Not necessarily the case. For a quick test, you can create a bitmap file, save it with "ICO" file extension, then see if Explorer displays it.
2. Whilst by now it is well understood that LoadPicture() cannot be used to effectively load the newer icons, APIs such as DrawiconEx or ExtractIconEx can be used to tackle all issues relating to reading ICO files.
Comment: The use of the said APIs is very limited, hence cannot handle many of the icon files.
3. Codes pertaining to icon edit/conversion, written two/three years ago, are still usable.
Comment: They are no longer good. I myself posted an abridged version of Icon Editor on PSC three years ago, but deleted it in early 2001 (even though it was a prize winner then). I also deleted an old posting on converting bmp to ico. (One of the beauties of PSC – allowing authors to remove old/obsolete postings).
To correctly handle the icon files (read, manipulate, save, extract or convert), one must understand the header structures and know well how to deal with the bitmap data arrangements according to the different sizes and color depths, especially the ones with alpha-channel (XP icons).
If you have questions of the nature of general interest, please leave them in the Forum of this site (please don’t send me an e-mail). I will try to answer them in order to clarify the points. It must be emphasized, however, that I will not give out actual codes.