• 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);
            }
    
        }
    
    
    }
  • 相关阅读:
    nios sgdma(Scatter-Gather dma)示例
    关于nios 中printf 的问题
    Nios II 系统时钟timestamp的应用
    DMA在FPGA的应用之我见
    PIO Core
    VGA接口时序约束
    时序分析,重中之重,柳暗花明又一村 搞定美女了问题
    深入浅出VGA和DVI接口
    基于FPGA的VGA可移植模块终极设计
    理解FPGA中的RAM、ROM和CAM;ROM、RAM、DRAM、SRAM、FLASH
  • 原文地址:https://www.cnblogs.com/xiangtailiang/p/2444632.html
Copyright © 2020-2023  润新知