C下WIN32SDK进度条

DWORD WINAPI PBThreadProc( LPVOID lpParameter )
{
    HWND hwndPB = (HWND) lpParameter;    //进度条的窗口句柄
    PBRANGE range;                        //进度条的范围
    
    SendMessage( hwndPB, PBM_SETRANGE,    //设置进度条的范围
        (WPARAM)0, (LPARAM)(MAKELPARAM(0,100)) );
    
    SendMessage( hwndPB, PBM_GETRANGE,    //获取进度条的范围
        (WPARAM)TRUE,                    //TRUE 表示返回值为范围的最小值,FALSE表示返回最大值
        (LPARAM)&range );

    while(TRUE)
    {
        SendMessage( hwndPB, PBM_DELTAPOS, //设置进度条的新位置为当前位置加上范围的1/20
            (WPARAM)((range.iHigh-range.iLow)/20), (LPARAM)0 ); 
        if( SendMessage( hwndPB, PBM_GETPOS, (WPARAM)0, (LPARAM)0 ) //取得进度条当前位置
             == range.iHigh )
        {
            SendMessage( hwndPB, PBM_SETPOS, (WPARAM)range.iLow, (LPARAM)0 ); //将进度条复位
        }
        Sleep(1000);
    }
}
            
CreateThread(            //操作进度条的线程
                NULL,
                0,
                (LPTHREAD_START_ROUTINE)PBThreadProc,
                hwndPB,
                0,
                0
                );

你可能感兴趣的:(win32SDK)