Getting a firm grasp of the Microsoft Windows GDI is an important milestone on the road to becoming a Windows programmer because all graphical output to screens, printers, and other devices is performed through the GDI. So far in this book, we've used three of the six MFC classes that represent GDI objects: CPen, CBrush, and CFont. In this chapter, we'll examine the remaining three: CPalette, CBitmap, and CRgn.
CPalette represents palettes—tables of color that allow Windows to balance the sometimes conflicting needs of applications that demand more colors than the video adapter can provide. If every video adapter displayed 24-bits-per-pixel color (8 bits each for red, green, and blue), palettes would be unnecessary. But 256-color video adapters are a fact of life and probably will be for some time to come. By default, a Windows application that executes in a 256-color environment has access to only 20 colors. If you're careful about how you pick your colors and make those colors part of a palette, you can expand the selection to 256 colors and write Windows applications whose color output is almost as good on 256-color screens as it is on screens that display millions of colors. In this chapter, you'll see how to use palettes in your applications to generate color output as rich as the hardware will allow.
MFC's CBitmap class represents GDI bitmaps. CBitmap is a primitive class that does very little on its own. Combined with MFC's CDC class, however, CBitmap makes it relatively easy to draw on virtual display surfaces in memory, load bitmap resources, and display simple bitmap images on the screen. You can also use CBitmap to build more capable bitmap classes that exploit the capabilities of the Windows device-independent bitmap (DIB) engine. One technique you'll see demonstrated in this chapter is a method for creating DIB sections from BMP files and attaching them to ordinary CBitmap objects—all in just three lines of code.
CRgn is one of MFC's more obscure classes, but one that you can use for some exotic graphics effects. Rather than spoil the fun, I'll leave the details for the end of the chapter.
|The CHM file was converted to HTML by chm2web software.|