VC怎样添加和调用timer控件?

VC怎样添加和调用timer控件?,第1张

vc不像VB并没有timer控件,如果想要添加一个定时器,只要调用SetTimer就可以了,具体用法可看MSDN,关掉就是KillTimer

例如:

SetTimer(1,1000,NULL)

KillTimer(1)

你再添加对WM_TIMER消息的映射函数OnTimer函数就可以了。

如果有问题HI我

Timer控件的主要属性:

Enable:Timer控件是否启用

Interval:事件的运行间隔时间

Timer控件的事件:

timer_Tick:事件间隔时进行的 *** 作

实时时钟的简单实现:

新建Windows应用程序,在窗体中添加两个label(lblCurrentTime,lblTime),代码页面如下:

[csharp] view plain copy

using System

using System.Collections.Generic

using System.ComponentModel

using System.Data

using System.Drawing

using System.Text

using System.Windows.Forms

namespace TimerTest

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent()

}

private void timerTest_Tick(object sender, EventArgs e)

{

lblTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")

}

private void Form1_Load(object sender, EventArgs e)

{

lblTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")

}

}

}

#include <iostream>

#include <time.h>

using namespace std

int main()

{

clock_t start = clock()

//do some process here

clock_t end = (clock() - start)/CLOCKS_PER_SEC

cout<<"time comsumption is "<<end<<endl

}

扩展资料

使用linux的系统设置计时

#include <sys/time.h>

int main()

{

timeval starttime,endtime

gettimeofday(&starttime,0)

//do some process here

gettimeofday(&endtime,0)

double timeuse = 1000000*(endtime.tv_sec - starttime.tv_sec) + endtime.tv_usec - startime.tv_usec

timeuse /=1000//除以1000则进行毫秒计时,如果除以1000000则进行秒级别计时,如果除以1则进行微妙级别计时

}

timeval的结构如下:

strut timeval

{

long tv_sec/* 秒数 */

long tv_usec/* 微秒数 */

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/bake/11369398.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-15
下一篇 2023-05-15

发表评论

登录后才能评论

评论列表(0条)

保存