11.6.10 Modifying the WM_COMMAND Case

To support the Bitmap, Pattern, and Mode menus, you must change the WM_COMMAND case. In your window procedure, replace the current WM_COMMAND case with the following statements:

case WM_COMMAND:
    switch (wParam) {
        case IDM_ABOUT:
            lpProcAbout =
                MakeProcInstance((FARPROC) About, hinst);
            DialogBox(hinst,
                "AboutBox",
                hwnd,
                (DLGPROC) lpProcAbout);
            FreeProcInstance(lpProcAbout);
            break;

        case IDM_BITMAP1:

            fwPrevItem = fwPrevBitmap;
            fwPrevBitmap = wParam;
            GetObject(hbmpDog, 16, (LPSTR) &Bitmap);
            SelectObject(hdcMemory, hbmpDog);
            break;

        case IDM_BITMAP2:

            fwPrevItem = fwPrevBitmap;
            fwPrevBitmap = wParam;
            GetObject(hbmpCat, 16, (LPSTR) &Bitmap);
            SelectObject(hdcMemory, hbmpCat);
            break;

        case IDM_BITMAP3:

            fwPrevItem = fwPrevBitmap;
            fwPrevBitmap = wParam;
            GetObject(hbmpClrPattern, 16, (LPSTR) &Bitmap);
            hOurBitmap = SelectObject(hdcMemory, hbmpClrPattern);
            break;

        case IDM_PATTERN1:

            fwPrevItem = fwPrevPattern;
            fwPrevPattern = wParam;
            DeleteObject(hBrush);
            hBrush = CreatePatternBrush(hbmpWhite);
            InvalidateRect(hwnd, (LPRECT) NULL, TRUE);
            UpdateWindow(hwnd);
            break;

        case IDM_PATTERN2:

            fwPrevItem = fwPrevPattern;
            fwPrevPattern = wParam;
            DeleteObject(hBrush);
            hBrush = CreatePatternBrush(hbmpBlack);
            InvalidateRect(hwnd, (LPRECT) NULL, TRUE);
            UpdateWindow(hwnd);
            break;



        case IDM_PATTERN3:

            fwPrevItem = fwPrevPattern;
            fwPrevPattern = wParam;
            DeleteObject(hBrush);
            hBrush = CreatePatternBrush(hbmpZigZag);
            InvalidateRect(hwnd, (LPRECT) NULL, TRUE);
            UpdateWindow(hwnd);
            break;

        case IDM_PATTERN4:

            fwPrevItem = fwPrevPattern;
            fwPrevPattern = wParam;
            DeleteObject(hBrush);
            hBrush = CreatePatternBrush(hbmpCrossHatch);
            InvalidateRect(hwnd, (LPRECT) NULL, TRUE);
            UpdateWindow(hwnd);
            break;

        case IDM_BLACKONWHITE:

            fwPrevItem = fwPrevMode;
            fwPrevMode = wParam;
            fwStretchMode = BLACKONWHITE;
            break;

        case IDM_WHITEONBLACK:

            fwPrevItem = fwPrevMode;
            fwPrevMode = wParam;
            fwStretchMode = WHITEONBLACK;
            break;

        case IDM_COLORONCOLOR:

            fwPrevItem = fwPrevMode;
            fwPrevMode = wParam;
            fwStretchMode = COLORONCOLOR;
            break;
    }

    CheckMenuItem(GetMenu(hwnd), fwPrevItem, MF_UNCHECKED);
    CheckMenuItem(GetMenu(hwnd), wParam, MF_CHECKED);
    break;

Note that this new WM_COMMAND case handles the IDM_ABOUT case by using a switch statement instead of an if statement.