现在的位置: 首页 > 综合 > 正文

主线程要执行一个复杂的操作还要响应界面操作

2018年02月12日 ⁄ 综合 ⁄ 共 411字 ⁄ 字号 评论关闭

例如: 主线程中一个对话框的按钮事件如下:

 

for(int i=0; i<1000; i++)
{
   Sleep(10);

   if(i%100)
   {
    MSG msg;
    while(::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
    {
      if(!theApp.PumpMessage()) 
      {
       ::PostQuitMessage(0);
       return;
      }
    }
   }
}

 

如果将

 

   if(i%100)
   {
    MSG msg;
    while(::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
    {
      if(!theApp.PumpMessage()) 
      {
       ::PostQuitMessage(0);
       return;
      }
    }
   }

 

去掉后,只有执行完该函数后 主线程的其他消息才能响应 导致拖动界面操作无法执行

 

 

 

抱歉!评论已关闭.