The Windows Way of Drawing
When you drop the Visual Basic safety net and start drawing with the Windows API, you’ll find yourself dealing with issues that didn’t concern you before. Scaling becomes a problem. You must figure out what Visual Basic properties mean to Windows and vice versa. Despite the problems, here are several good reasons why you might want to draw the hard way:
-
Some operations you might want to perform are not supported in
Visual Basic—drawing polygons, managing regions, and filling, for
example.
-
Some surfaces on which you might want to draw don’t support Visual Basic drawing methods—buttons, menus, list boxes, metafiles, and memory device contexts, for example.
-
Windows API functions are often faster than comparable Visual Basic operations. This is because Visual Basic is doing some extra work behind the scenes. If you’re willing to do the necessary work yourself, you might get a performance gain. Then again you might not. You have to test the performance on a case-by-case basis.
-
You can create generic functions that do some drawing operation on any surface. Instead of providing a canvas parameter (which is actually a late-bound Object), you can provide an hDC parameter and use API functions on it.
Let’s look at some examples.