c ++程序功能必须处于周期性频率 [英] c++ program function has to be in periodic frequency

查看:83
本文介绍了c ++程序功能必须处于周期性频率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在c ++程序中,我喜欢调用同一程序的函数,但必须以周期性的频率(指定的时间间隔)执行...

问候,
sanath

Hi,

In c++ program, i like to call a function of the same program but that has to be execute in periodic frequency(specified time interval)...

regards,
sanath

推荐答案

您可以为此使用计时器.请参见在MSDN上使用计时器 [
You may use a timer for this. See Using Timers at MSDN[^].


您必须采用以下方式:
You have to do it in this way:
#pragma once
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <tchar.h>

#pragma comment (lib,"user32.lib")
enum
{
  INTERVAL  = 2000// milliseconds
  MAX_COUNT = 10,
};


void FAR PASCAL __fnTimer(HWND, UINT, UINT_PTR, DWORD)
{
  static int  count = MAX_COUNT;
  if(0>=--count) PostQuitMessage(0);
  Beep(3000,100);
}

int FAR PASCAL _tWinMain(HINSTANCE h,HINSTANCE p,LPTSTR c,int sw)
{
  if(0<SetTimer(0,0,INTERVAL,__fnTimer))
  {
    for(MSG m;GetMessage(&m,0,0,0);DispatchMessage(&m));
  }
  return 0;
}


我假设您使用Windows.
祝你好运.


i assumed youre using windows.
Good luck.


使用计时器,如何在每个指定的时间调用函数?
by using timers, how can I call my function for every specified time?


这篇关于c ++程序功能必须处于周期性频率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆