我的进度条重绘了部分内容,WINAPI

发布于 2024-12-08 19:07:52 字数 1044 浏览 0 评论 0 原文

在我的应用程序中,我进入了一个未知数量元素的循环, 所以我显示一个进度条来通知应用程序正在运行,

并且此代码工作正常,进度条独立刷新:

do
{                      
   ...
   SendMessage(hPBLoading, PBM_STEPIT, 0, 0);       
   ...
} while(true);

但不幸的是窗口的其余部分没有刷新(由于循环,这很明显) 在 Windows 7 中,几秒钟后,Windows 会像崩溃一样对待我的应用程序,并在结束循环后返回并刷新,

所以我发现我需要分派消息队列,我将代码更改为

do
{                      
   ...
   SendMessage(hPBLoading, PBM_STEPIT, 0, 0);       
   ...
   us_tmpBreakCounter++;
   ...

   if (us_tmpBreakCounter >= 10)
   {    
      us_tmpBreakCounter = 0;    
      UpdateSomeOtherElementsinWindow();

    if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) == TRUE) 
      {
       TranslateMessage(&msg);
       DispatchMessage(&msg);   
      }
   }
} while(true);

: ,应用程序在ex后更新并刷新。计数 10 次,因此永远不会损坏, 但不幸的是,出现了另一个问题,现在进度条没有完全重绘 - 斜角框架在几秒钟后消失,请检查下面的图片:

http://mstanisz.website.pl/temp/progressbar_01.jpg

感谢您的帮助! 米。

in my application I am entering a loop of unknown number of elements,
so I am showing a progress bar to inform that application is running,

and this code works FINE, progres bar is refreshing independly:

do
{                      
   ...
   SendMessage(hPBLoading, PBM_STEPIT, 0, 0);       
   ...
} while(true);

but unfortunately the rest of window doesn't refresh (which is obvious due to the loop)
and in Windows 7 after a few seconds Windows treat my app like it break down, and it back and refresh after ending the loop,

so I figured out that I need to dispatch the message queue and I changed my code to this:

do
{                      
   ...
   SendMessage(hPBLoading, PBM_STEPIT, 0, 0);       
   ...
   us_tmpBreakCounter++;
   ...

   if (us_tmpBreakCounter >= 10)
   {    
      us_tmpBreakCounter = 0;    
      UpdateSomeOtherElementsinWindow();

    if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) == TRUE) 
      {
       TranslateMessage(&msg);
       DispatchMessage(&msg);   
      }
   }
} while(true);

It works fine, the applcation is updated and refreshed after ex. 10 counts so its never break down,
but unfortunately another problem occured, now the PROGRESS BAR doesn't redraw fully - the beveled frame dissapears after a few seconds, check this image below:

http://mstanisz.website.pl/temp/progressbar_01.jpg

Thanks For Your Help!
m.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橙味迷妹 2024-12-15 19:07:52

看起来你正在使用 GUI 线程来执行一些长时间的任务。这不是一个好的做法。当您想要执行长时间任务时,请使用工作线程,并让 GUI 线程在工作线程工作时处理 GUI。您必须做一些额外的工作来处理两个线程之间的同步(如果 GUI 关闭则停止工作线程,避免在当前任务结束之前启动任务等等),但这就是它的工作方式。

Seems like you're using a GUI thread to do some long task. That's not a good practice. When you want to perform long tasks, use a worker thread for that, and let the GUI thread handle the GUI while the worker works. You'll have to do some extra work taking care of synchronization between the two threads (stop the worker if the GUI is closed, avoid starting a task before the current one has ended and so on), but that's the way it works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文