3.4.4 Modifying the WM_DESTROY Case

Before terminating, the Output application should delete the drawing tools created for its window; this frees the memory that each drawing tool uses. To make the application do this, use the DeleteObject function to delete the various pens and brushes in the WM_DESTROY case. Modify the WM_DESTROY case so that it looks like this:

case WM_DESTROY:

    DeleteObject(hRedBrush);
    DeleteObject(hGreenBrush);
    DeleteObject(hBlueBrush);
    DeleteObject(hDashPen);
    DeleteObject(hDotPen);
    PostQuitMessage(0);
    break;

You must call the DeleteObject function once for each object you want to delete.