Add Global and Local Variables

You need to declare the pattern arrays, the bitmap handles and context handles, and other global variables used to create and display the bitmaps. To define these global variables, add the following statements to the beginning of your source file:

BYTE White[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };

BYTE Black[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

BYTE Zigzag[] = { 0xFF, 0xF7, 0xEB, 0xDD, 0xBE, 0x7F, 0xFF, 0xFF };

BYTE CrossHatch[] = { 0xEF, 0xEF, 0xEF, 0xEF, 0x00, 0xEF, 0xEF, 0xEF };

HBITMAP hPattern1;

HBITMAP hPattern2;

HBITMAP hPattern3;

HBITMAP hPattern4;

HBITMAP hBitmap1;

HBITMAP hBitmap2;

HBITMAP hBitmap3;

HBITMAP hMenuBitmap1;

HBITMAP hMenuBitmap2;

HBITMAP hMenuBitmap3;

HBITMAP hBitmap;

HBITMAP hOldBitmap;

HBRUSH hBrush; /* brush handle */

WORD fStretchMode; /* type of stretch mode to use */

HDC hDC; /* handle to device context */

HDC hMemoryDC; /* handle to memory device context */

BITMAP Bitmap; /* bitmap structure */

BOOL bTrack = FALSE; /* TRUE if user is selecting a region */

RECT Rect;

WORD wPrevBitmap = IDM_BITMAP1;

WORD wPrevPattern = IDM_PATTERN1;

WORD wPrevMode = IDM_WHITEONBLACK;

WORD wPrevItem;

int Shape = SL_BLOCK; /* shape to use for the selection rectangle */

The pattern arrays White, Black, Zigzag, and CrossHatch contain the bits defining the 8-by-8-pixel bitmap images. The variables hPattern1, hPattern2, hPattern3, and hPattern4 hold the bitmap handles of the brush patterns. The variables hBitmap1, hBitmap2, and hBitmap3 hold the bitmap handles of the bitmaps to be displayed. The variables hMenuBitmap1, hMenuBitmap2, and hMenuBitmap3 hold the bitmap handles of bitmaps to be displayed in the Bitmaps menu. The variables hBrush, hBitmap, and fStretchMode hold the current background brush, bitmap, and stretching mode. The variables hDC, hMemoryDC, and hOldBitmap hold handles used with the memory device context. The Bitmap structure holds the dimensions of the current bitmap. The bTrack variable is used to indicate a selection in progress. The Rect structure holds the current selection rectangle. The variables wPrevBitmap, wPrevPattern, wPrevMode, and wPrevItem hold the menu IDs of the previously chosen bitmap, pattern, and stretching mode. These are used to place and remove checkmarks in the menus.

Add the following local variables to the MainWndProc function:

HMENU hMenu;

HBRUSH hOldBrush;

HBITMAP hOurBitmap;