You must declare the pattern arrays, the bitmap 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:
short White[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
short Black[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
short Zigzag[] = { 0xFF, 0xF7, 0xEB, 0xDD, 0xBE, 0x7F, 0xFF, 0xFF };
short CrossHatch[] = { 0xEF, 0xEF, 0xEF, 0xEF, 0x00, 0xEF, 0xEF, 0xEF };
HBITMAP hbmpWhite;
HBITMAP hbmpBlack;
HBITMAP hbmpZigZag;
HBITMAP hbmpCrossHatch;
HBITMAP hbmpDog;
HBITMAP hbmpCat;
HBITMAP hbmpClrPattern;
HBITMAP hmenuBitmap1;
HBITMAP hmenuBitmap2;
HBITMAP hmenuBitmap3;
HBITMAP hBitmap;
HBITMAP hOldBitmap;
HBRUSH hBrush; /* brush handle */
WORD fwStretchMode; /* type of stretch mode to use */
HDC hdc; /* handle of device context */
HDC hdcMemory; /* handle of memory device context */
BITMAP Bitmap; /* bitmap structure */
BOOL fTrack = FALSE; /* TRUE if user is selecting a region */
RECT Rect;
WORD fwPrevBitmap = IDM_BITMAP1;
WORD fwPrevPattern = IDM_PATTERN1;
WORD fwPrevMode = IDM_WHITEONBLACK;
WORD fwPrevItem;
WORD fwShape = SL_BLOCK; /* shape to use for selection rectangle */
In this example, the pattern arrays White, Black, Zigzag, and CrossHatch contain the bits defining the 8-by-8-pixel bitmap images. The variables hbmpWhite, hbmpBlack, hbmpZigZag, and hbmpCrossHatch contain the bitmap handles of the brush patterns; hbmpDog, hbmpCat, and hbmpClrPattern contain the bitmap handles of the bitmaps to be displayed; hmenuBitmap1, hmenuBitmap2, and hmenuBitmap3 contain the bitmap handles of bitmaps to be displayed in the Bitmaps menu; hBrush, hBitmap, and fwStretchMode contain the current background brush, bitmap, and stretching mode; and hdc, hdcMemory, and hOldBitmap contain handles used with the memory device context. The Bitmap structure specifies the dimensions of the current bitmap. The fTrack variable indicates a selection in progress. The Rect structure defines the current selection rectangle. The variables fwPrevBitmap, fwPrevPattern, fwPrevMode, and fwPrevItem identify the previously chosen bitmap, pattern, and stretching mode. These identifiers are used to place and remove check marks in the menus.
Add the following local variables to the MainWndProc function:
HMENU hMenu;
HBRUSH hOldBrush;
HBITMAP hOurBitmap;