6.5.8 Adding a WM_PAINT Case

To ensure that the text string and selection rectangle are redrawn when necessary (for example, when another window has temporarily covered the client area), add the following case to the window procedure:

case WM_PAINT:
    {
        PAINTSTRUCT ps;

        hdc = BeginPaint(hwnd, &ps);
        TextOut(hdc, 1, 1, szStr, lstrlen(szStr));
        if (OrgX != PrevX || OrgY != PrevY) {
            MoveTo(hdc, OrgX, OrgY);
            LineTo(hdc, OrgX, PrevY);
            LineTo(hdc, PrevX, PrevY);
            LineTo(hdc, PrevX, OrgY);
            LineTo(hdc, OrgX, OrgY);
        }
        EndPaint(hwnd, &ps);
    }
    break;