A little better LoadResPicture

Since LoadImage can load from resources as well as from files, it’s relatively easy to enhance LoadResPicture in the same way you enhanced LoadPicture. It’s a little more complicated because you have to deal with resources specified by string name or by integer index, but most of the code is the same.

There is one big difference, however. LoadImage can read icons from resources in an EXE file, but it hasn’t a clue about how to read them in the Visual Basic environment. When you run in the environment, you’re not really running your own program; you’re running VB5.EXE. If you try to load icon resource 25 using the Windows API, you’ll get Visual Basic’s resource 25 or, more likely, you’ll get an error. LoadResPicture knows how to dig your resource out of some internal format known only to Madame Basic’s crystal ball. The best LoadAnyResPicture can do is detect the environment with a function called IsExe and then call the real LoadResPicture.

You might think that having icons be one size in the environment and another in an EXE would be unworkable. Actually, it’s not so bad. For example, assume that you put multi-image icons in a resource file and then load them into an ImageList control as small icons at run time. You’ll end up with large icons squished to small icons in the environment, but your small icons will come out as small icons in the EXE. You can do the same thing for Image controls by playing with the image size and the Stretch property. It’s an annoying problem for you, but your customers will never be the wiser.