进度条未在Win32中更新

时间:2013-08-28 13:16:42

标签: visual-studio-2010 winapi visual-c++ timer

我在Win32中创建了一个进度条,当我在Release配置中构建应用程序但在Debug配置中工作时,它不会更新。进度条创建如下:

progBar= CreateWindowEx(0,PROGRESS_CLASS,NULL,WS_CHILD | WS_VISIBLE|PBS_SMOOTH,rc.right/2-130,rc.bottom/2, 260, 17,hWnd, NULL, hInst, NULL);

        //Sets the range of progress bar
        SendMessage(progBar, PBM_SETRANGE, 0, MAKELPARAM(0,10));    //0->min value; 10->max value
        SetTimer(hWnd, TIMER_1, 1000, TimerProc);                   //set the timer

我的TimerProc是:

void CALLBACK TimerProc(HWND hWnd, UINT msg, UINT idEvent, DWORD dwTime)
{

switch(msg)
{
    case WM_TIMER:
    {
        SendMessage(progBar, PBM_SETPOS,stepValue,0);       //stepValue
        InvalidateRect(progBar,NULL,TRUE);

        if(stepValue>9)
        {
            stepValue=0;
        }

        else
        {
            stepValue++;
        }
    }
  }
  return;
}

我正在使用Visual Studio 2010.我可能因为它在Debug配置中工作而错过了一些库。我选择的运行时库是多线程(/ MT)

1 个答案:

答案 0 :(得分:1)

根据汉斯的说法,我尝试了Marquee风格的进度条并且有效。代码更改如下:

        progBar= CreateWindowEx(0,PROGRESS_CLASS,NULL,WS_CHILD | WS_VISIBLE|PBS_MARQUEE,rc.right/2-130,rc.bottom/2, 260, 17,hWnd, NULL, hInst, NULL);

        SendMessage(progBar, PBM_SETMARQUEE,TRUE,50); 

我删除了SetRange语句。根据此链接

http://social.msdn.microsoft.com/Forums/vstudio/en-US/407cf8d0-02cc-4276-adb1-3fc619ce4f3a/progress-bar-with-marquee-style

我必须添加

#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") 

否则Marquee进度条不起作用。有人可以解释一下吗?但这也适用于Release版本。

相关问题