C++技巧(多媒体定时器的简单例子)

C++技巧(多媒体定时器的简单例子),第1张

C++技巧(多媒体定时器的简单例子),第2张

1)新建一个项目,保存
2)添加一个按钮和一个标签
3)修改unit1.h代码如下:
/
# ifndef unit 1h
# define unit 1h
/
。include
# include
# include
//
class t form 1:public t form
{
_ _ published://I managed Components
t button * button 1;
t label * label 1;
void _ _ fast call button 1 click(to object * Sender);
void _ _ fastcall FormCloseQuery(to object * Sender,bool & can close);
私有://用户声明
公共://用户声明
_ _ fast call t form 1(t component * Owner);
静态void回调TimeProc(UINT uID,UINT uMsg,
DWORD dwUser,DWORD dw1,DWORD dw2);//定时器回调函数
int time rid;//考试提示:定时器ID
};
//
extern PACKAGE t form 1 * form 1;
/
# endif
4)unit 1 . CPP的代码如下:
/
# include
# include " mm system . h "
# pragma hdrstop include " unit 1 . h "
/
# pragma package(smart _ init)
# pragma resource " *。DFM "
t form 1 * form 1;
//
_ _ fast call t form 1::t form 1(t component * Owner)
:t form(Owner)
{
time rid = 0;
}
//
void回调TForm1::TimeProc(UINT uID,UINT uMsg,DWORD dwUser,DWORD dw1,DWORD dw2)
{
form 1 > label 1 > Caption = Now();
}
//
void _ _ fastcall t form 1::button 1 click(to object * Sender)
{
TIME rid = TIME setevent(1000,0,(LPTIMECALLBACK)TimeProc,0,
TIME _ PERIODIC | TIME _ CALLBACK _ FUNCTION);//设置多媒体定时器,1000 ms
if(timer ID = = 0){
显示消息("创建失败");
}
}
//
void _ _ fastcall t form 1::FormCloseQuery(to object * Sender,bool & can close)
{
if(time rid!= 0){
time kill event(time rid);//释放定时器
}
}
/
操作效果:点击按钮后,Label1开始显示时间。

位律师回复
DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
白度搜_经验知识百科全书 » C++技巧(多媒体定时器的简单例子)

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情