11.6.6 Modifying the WM_DESTROY Case

Before your application terminates, it must delete any bitmaps, patterns, brushes, and memory device contexts it has created. You delete bitmaps, patterns, and brushes by using the DeleteObject function. You delete the memory device context by using the DeleteDC function. Modify the WM_DESTROY case so that it looks like this:

case WM_DESTROY:
    SelectObject(hdcMemory, hOldBitmap);
    DeleteDC(hdcMemory);
    DeleteObject(hBrush);
    DeleteObject(hbmpWhite);
    DeleteObject(hbmpBlack);
    DeleteObject(hbmpZigZag);
    DeleteObject(hbmpCrossHatch);
    DeleteObject(hbmpDog);
    DeleteObject(hbmpCat);
    DeleteObject(hbmpClrPattern);
    DeleteObject(hmenuBitmap1);
    DeleteObject(hmenuBitmap2);
    DeleteObject(hmenuBitmap3);

    PostQuitMessage(0);
    break;