4.2.15 Adding a WM_PAINT Case

To make your application display the current state of the mouse, keyboard, and timer, use a WM_PAINT message to display the states. Your application repaints only the parts of its client area that require repainting.

Add the following statements to the window procedure:

case WM_PAINT:
    hDC = BeginPaint(hWnd, &ps);

    if (IntersectRect(&rect, &rectMouse, &ps.rcPaint))
        TextOut(hDC, rectMouse.left, rectMouse.top,
            MouseText, lstrlen(MouseText));
    if (IntersectRect(&rect, &rectButton, &ps.rcPaint))
        TextOut(hDC, rectButton.left, rectButton.top,
            ButtonText, lstrlen(ButtonText));
    if (IntersectRect(&rect, &rectKeyboard, &ps.rcPaint))
        TextOut(hDC, rectKeyboard.left, rectKeyboard.top,
            KeyboardText, lstrlen(KeyboardText));
    if (IntersectRect(&rect, &rectCharacter, &ps.rcPaint))
        TextOut(hDC, rectCharacter.left, rectCharacter.top,
            CharacterText, lstrlen(CharacterText));
    if (IntersectRect(&rect, &rectTimer, &ps.rcPaint))
        TextOut(hDC, rectTimer.left, rectTimer.top,
            TimerText, lstrlen(TimerText));
    if (IntersectRect(&rect, &rectScroll, &ps.rcPaint))
        TextOut(hDC, rectScroll.left, rectScroll.top,
            ScrollText, lstrlen(ScrollText));

    EndPaint(hWnd, &ps);
    break;