C++回调函数(callback)的使用(2)

DWORD StartTick;
         //一个延时循环
              for(;Step<200;Step++)
              {
                         StartTick = GetTickCount();
                   /*这一段为线程交出部分运行时间以让系统处理其他事务*/
                        for(;GetTickCount()-StartTick<10;)
                          {
                                  if(PeekMessage(&Msg,NULL,0,0,PM_NOREMOVE) )
                                  {
                                    TranslateMessage(&Msg);
                                    DispatchMessage(&Msg);
                                    }
                            }  

/*把运行情况打印到桌面,这是vcbear调试程序时最喜欢干的事情*/
            sprintf(Buffer,"Running %04d",Step);
                          if(hDC!=NULL)
                                   TextOut(hDC,30,50,Buffer,strlen(Buffer));
                    }
                 /*延时一段时间后调用回调函数*/  
                 (*gCallback)(Step,1);
                  /*结束*/
                    ::ReleaseDC (HWND_DESKTOP,hDC);
                   return 0;
       }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/eea80e60455f6c28d3d0a205d1fb56c5.html