zoukankan      html  css  js  c++  java
  • Windows Console 程序中定时器的使用

    本程序使用定时器方法,设置一个1000ms的定时器(SetTimer),然后捕捉该消息,然后调用回调函数TimerProc,在该函数中输出DEF,注意,SetTimer可以直接写回调函数地址,不必捕捉消息。

    这里给出的是捕捉消息的版本。

    //************************************************************************************    
    //本程序使用定时器方法,设置一个1000ms的定时器(SetTimer),然后捕捉该消息,然后调用回调函数    
    //     TimerProc,在该函数中输出DEF,注意,SetTimer可以直接写回调函数地址,不必捕捉消息。       
    //************************************************************************************    
    
    
    
    #include "stdafx.h"    
    #include <windows.h>    
    
    
    void TimerProc()
    {
    
        static DWORD tick = 0;
        static DWORD tmp = GetTickCount();
    
        tick = GetTickCount() - tmp;
        tmp = GetTickCount();
        printf(" TimerProc________________def %d\n", tick);
    }
    
    
    int main()
    {
    
        SetTimer(NULL, 0, 1000, NULL); //设置一个定时器,定时器的回调函数为0,仅产生定时器消息,在main函数里捕捉该消息 
        MSG msg;
        BOOL bRet;
    
        while (1)
        //该循环捕捉定时器消息,并且防止main函数退出    
        {
            bRet = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
            if (bRet ==  - 1)
            {
                // handle the error and possibly exit
            }
            else if (bRet && msg.message == WM_TIMER)
            {
                TimerProc();
            }
            else
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
    
        }
    
    
    }
  • 相关阅读:
    Windows OS上安装运行Apache Kafka教程
    CSS3 transition属性
    CSS3新增UI样式
    css3响应式布局
    CSS3弹性盒模型
    CSS3
    移动端开发的那点事儿
    git开源项目协作
    移动端(IOS)iframe监听不到 onscroll 事件
    Javascript高级程序设计读书笔记(第10章 DOM)
  • 原文地址:https://www.cnblogs.com/xiangtailiang/p/2444632.html
Copyright © 2011-2022 走看看