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

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

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

例如:

SetTimer(1,1000,NULL)

KillTimer(1)

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

如果有问题HI我

做一个显示系统时间的程序吧:窗体form1内添加控件timer1,label1,button1。

双击form1来编写form1_Load(arg0, arg1)事件:

private void form1_Load(object sender, EventArgs e)

{

this.label1.Text = "本程序用于显示当前系统时间"

this.button1.Text = "开始"

}

双击button1来编写button1_Click(arg0, arg1)事件:

private void button1_Click(object sender, EventArgs e)

{

int thisTime = 0

if(this.button1.Text == "开始"){

this.timer1.Interval = 1000

this.timer1.Enabled = true

this.button1.Text = "停止"

}

if(this.button1.Text == "停止"){

this.timer1.Enabled = false

this.button1.Text = "开始"

}

}

双击timer1来编写timer1_Tick(arg0, arg1)事件:

private void timer1_Tick(object sender, EventArgs e)

{

this.label1.Text = "当前系统时间是:" + DateTime.Now.ToString()

}

运行下看看。

#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/11552662.html

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

发表评论

登录后才能评论

评论列表(0条)

保存