3.4.2 Adding a WM_CREATE Case

To enable Output to draw in its client area, you must create the drawing tools. Since you need only create these tools once, a convenient place to do so is in the WM_CREATE message. Add the following statements to MainWndProc:

case WM_CREATE:

    /* Create the brush objects. */

    hRedBrush =   CreateSolidBrush(RGB(255,   0,   0));
    hGreenBrush = CreateSolidBrush(RGB(  0, 255,   0));
    hBlueBrush =  CreateSolidBrush(RGB(  0,   0, 255));

    /* Create the "---" pen. */

    hDashPen = CreatePen(PS_DASH, /* style */
        1,                        /* width */
        RGB(0, 0, 0));            /* color */

    /* Create the "..." pen. */

    hDotPen = CreatePen(2,        /* style */
        1,                        /* width */
        RGB(0, 0, 0));            /* color */
    break;

The CreateSolidBrush functions create the solid brushes to be used for filling the rectangle, the ellipse, and the circle that Output draws on the screen in response to the WM_PAINT message. The CreatePen functions create the dotted and dashed lines used to draw borders.