How to utilize the application's spare time?
发布日期:2022-02-07 06:39:36 浏览次数:10 分类:技术文章

本文共 1528 字,大约阅读时间需要 5 分钟。

 A window application will enter the idle time if there is no message waiting for processing. So how to utilize this interval time to do opearions.

Generally, a window message loop is like this:

while(GetMessagee(&
msg,NULL,NULL,NULL)
{
   TranslateMessage(
&
msg);
   DispatchMessage(
&
msg);
}

If we didn't receive any system message, we can use this "spare time" of our application to do some background processing and even do some stuff. This process is called Idle Processing. We need to insert our message loop right after the initialization of our global variables.

while
( TRUE )
{
    MSG msg;
    
if( PeekMessage( &msg, NULL, 00
, PM_REMOVE ) )
    
{
        
// Check for a quit message
        if( msg.message == WM_QUIT )
            
break
;
        TranslateMessage( 
&
msg );
        DispatchMessage( 
&
msg );
    }
    
else
    
{
        ProcessIdle();
    }
}
In our message loop, the first thing we do is check the message queue for messages to our application. This is accomplished by calling the PeekMessage function. If the function returns true, we call TranslateMessage and DispatchMessage so that the messages received by our program are processed. If we have no message, we'll call another function called ProcessIdle.In our message loop, the first thing we do is check the message queue for messages to our application. This is accomplished by calling the PeekMessage function. If the function returns true, we call TranslateMessage and DispatchMessage so that the messages received by our program are processed. If we have no message, we'll call another function called ProcessIdle.

转载地址:https://blog.csdn.net/wyfeizj/article/details/1908066 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:如何提高数据库查询速度 (收藏+体会)
下一篇:How to implement Polymorphism in C

发表评论

最新留言

做的很好,不错不错
[***.243.131.199]2024年04月23日 13时31分07秒