《Windows程序设计》文本输出部分的有关问题

《Windows程序设计》文本输出部分的问题
小弟最近开始学习windows程序设计,教材选用的是《windows程序设计》第五版
其中,第四章,讲文本输出,按照书中的要求写出的代码,可以正常的编译和执行,但是在移动滚动条的时候发现客户区闪烁得比较厉害;
找遍各种资料,试过各种方法后仍不能解决该问题,恳请高人指点一二:

main.c
C/C++ code

#include <windows.h>
#include "sysinfo.h"

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
{    
    HWND hwnd;
    MSG msg;
    WNDCLASS wndclass;
    
    wndclass.style = CS_HREDRAW | CS_VREDRAW;
    wndclass.lpfnWndProc = WndProc;
    wndclass.cbClsExtra = 0;
    wndclass.cbWndExtra = 0;
    wndclass.hInstance = hInstance;
    wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
    wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wndclass.lpszMenuName = 0;
    wndclass.lpszClassName = "unsigned";
    
    if (!RegisterClass(&wndclass))
    {
        MessageBox(NULL, TEXT("The windows class init failed"), TEXT("unsigned.lu"), MB_ICONERROR);
        return 0;
    }
    
    hwnd = CreateWindow("unsigned",
        TEXT("unsigned.lu"),
        WS_OVERLAPPEDWINDOW | WS_VSCROLL,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        NULL,
        NULL,
        hInstance,
        NULL);
    
    ShowWindow(hwnd, iCmdShow);
    UpdateWindow(hwnd);
    
    while(GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    
    return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    HDC hdc;
    PAINTSTRUCT ps;
    int iCount;
    static int iCharHeight;
    TCHAR szSizeOfItem[10];
    TEXTMETRIC tm;
    switch(message)
    {
    case WM_CREATE:
        hdc = BeginPaint(hwnd, &ps);
        GetTextMetrics(hdc, &tm);
        iCharHeight = tm.tmHeight + tm.tmExternalLeading;
        ReleaseDC(hwnd, hdc);
        break;
        
    case WM_SIZE:
        {
            SCROLLINFO si;
            
            si.cbSize = sizeof(SCROLLINFO);
            si.fMask = SIF_ALL;
            si.nMin = 0;
            si.nMax = iLineCount * iCharHeight -1;
            si.nPage = HIWORD(lParam);
            
            SetScrollInfo(hwnd, SB_VERT, &si, TRUE);    
        }
        break;
        
    case WM_VSCROLL:
        {
            SCROLLINFO si;
            
            si.cbSize = sizeof(SCROLLINFO);
            si.fMask = SIF_ALL;
            GetScrollInfo(hwnd, SB_VERT, &si);
            
            switch(LOWORD(wParam))
            {
            case SB_THUMBPOSITION:
            case SB_THUMBTRACK:
                si.nPos = si.nTrackPos;
                break;
            }
            si.fMask = SIF_POS;
            SetScrollInfo(hwnd, SB_VERT, &si, TRUE);

            InvalidateRect(hwnd, NULL, TRUE);
        }
        break;
        
    case WM_PAINT:
        {
            SCROLLINFO si;
            
            si.cbSize = sizeof(SCROLLINFO);
            si.fMask = SIF_ALL;
            GetScrollInfo(hwnd, SB_VERT, &si);

            hdc = BeginPaint(hwnd, &ps);
            for(iCount = 0; iCount < iLineCount; ++iCount)
            {
                TextOut(hdc, 0, iCount * iCharHeight - si.nPos, sysmetrics[iCount].szLable, lstrlen(sysmetrics[iCount].szLable));
                TextOut(hdc, 200, iCount * iCharHeight - si.nPos, sysmetrics[iCount].szDesc, lstrlen(sysmetrics[iCount].szDesc));
                TextOut(hdc, 400, iCount * iCharHeight - si.nPos, szSizeOfItem, wsprintf(szSizeOfItem, TEXT("%5d"), GetSystemMetrics(sysmetrics[iCount].iIndex)));
            }
            EndPaint(hwnd, &ps);
        }
        break;
        
    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
    }
    
    return DefWindowProc(hwnd, message, wParam, lParam);
}