I find the whole field pretty confusing (mostly MS's fault) and have yet to
find a good overview. The MS documentation simply stinks. Even Petzold wasn't
very much help.
Here's my current (gappy) understanding. I hope that it's some help, or at
least that someone else can fill in the gaps for both of us.
The thing to realise is that Windows has two completely different ways of
loading icons into a running program. One is to load them from a .ICO file;
the other is to load them from the "resources" bound into some .EXE or .DLL
(with the current program's .EXE as a special case of that). There are
separate APIs for the two operations, and they don't even look similar to each
other... (And, come to that, the actual binary layout of the Icon data is not
quite the same in the two cases, which just makes things more "fun", though it
shouldn't affect you unless you want to write an icon/resource editor.)
(BTW, one of the reasons that Petzold wasn't very much help is that he seemed
to concentrate on only the first of these, when the second is more common
use -- at least in the Dolphin system.)
Dolphin tries hard to hide this complexity, and does a good job for the most
part. The downside is that the code gets pretty complicated, and it's hard to
work out the underlying conventions that drive what's going on just from
reading it. (There seem to be blizzards of FileLocators flashing around, most
of which seem redundant, for instance.)
Anyway, the way to create an Icon from a .ICO file is by an expression like:
Icon fromFile: 'filename.ico' usingLocator: aFileLocator.
where the FileLocator is an instance of one of the subclasses of FileLocator
whose job is to turn a "relative" filename into something that the Window's OS
can actually open. For instance there is a ImageRelativeFileLocator which
interprets the name as if it were relative to the location of the image you are
running. There are several other possible file locators you can use, or you
can write your own.
A slightly simpler form of the above is:
Icon fromFile: 'filename.ico'.
which is just the same except that it will use the default locator, which is an
ImageRelativeFileLocator. If you provide an absolute pathname then the
ImageRelativeFileLocator won't change what you've given it at all, so you can
say things like:
Icon fromFile: 'C:\Somewhere\filename.ico'.
and that will work wherever the image was placed.
As an aside, Icon>>printOn: produces confusing output since it /looks/ like a
valid Icon creation expression (indeed it is valid -- just wrong), but the
expression doesn't reflect the FileLocator that is actually in use.
The alternative method of loading icons is from the resources compiled into a
DLL (or .EXE). Here the fully general creation expression is something like:
Icon fromId: 134 in: ShellLibrary default.
Here you give an "id" which can be either a String or an Integer to find the
correspondingly named icon resource in an instance of ExternalLibrary.
ExternalLibraries are normally used for wrapping access to another DLL's code,
not just for loading icons, so you may well want to load icons from some
arbitrary DLL (or .EXE) that doesn't already have a corresponding
ExternalLibrary subclass. The special subclass ExternalResourceLibrary is
intended to cover that case. You can say things like:
notepad := ExternalResourceLibrary open: 'C:\