Using Resources the Windows Way

Digging resources out of other programs is interesting, but from a practical standpoint it痴 hardly worth the trouble. Visual Basic already provides a better way of getting at most resources, so why even bother with API functions? Well, it turns out that what you get from resource functions is the same thing you get from other API functions: handles to GDI objects or global memory.

No matter what graphics task you attempt, you値l be dealing with handles such as HBITMAPs, HICONs, HCURSORs, and so on. Sometimes you値l be using them indirectly, but you池e not going to attain programming freedom until you can change seamlessly back and forth between API handles and equivalent Visual Basic features. We talked a little bit about this in Chapter 7. In this chapter, we池e going to look at the most important GDI handle types one by one.

In WinWatch, we値l be using the Show and Play procedures to display the appropriate data on the pbResource picture box. Among other things, these procedures save the resource type so that you can call the ClearResource procedure to clean up the current resource before a new resource is loaded. ClearResource removes the representation of the last resource. Sometimes this is as simple as erasing the picture box where the resource was displayed. Other times the procedure must take type-specific cleanup actions, such as restoring the original menu or cursor.

The rest of this chapter looks at the specific Show and Play procedures that use the resources as well as the cleanup code that clears them. In other words, we値l be looking at the mechanics of using Windows handles in Visual Basic code.

We値l also be looking at some resources from the other standpoint葉ranslating Visual Basic data types such as Picture into Windows handles. We値l use the Picture Browser shown in Figure 8-4 to illustrate these techniques. The Picture Browser loads files for bitmaps, icons, cursors, waves, and metafiles. It displays the data graphically and uses API techniques to decipher everything Windows knows about the data.

Figure 8-4. The Picture Browser.