Chinaunix首页 | 论坛 | 博客
  • 博客访问: 735377
  • 博文数量: 769
  • 博客积分: 6000
  • 博客等级: 准将
  • 技术积分: 4985
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-15 16:37
文章分类

全部博文(769)

文章存档

2011年(1)

2008年(768)

我的朋友

分类:

2008-10-15 16:40:25

 // ---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
// ---------------------------------------------------------------------------
#include
#include
#include
#include
// ---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
   TButton *Button1;
   TLabel *Label1;
   void __fastcall Button1Click(TObject *Sender);
   void __fastcall FormCloseQuery(TObject *Sender, bool &CanClose);
private: // User declarations
public: // User declarations
   __fastcall TForm1(TComponent* Owner);
   static void CALLBACK TimeProc(UINT uID,UINT uMsg,
     DWORD dwUser,DWORD dw1,DWORD dw2); // 定时器回调函数
   int TimerID; // 定时器ID
};
// ---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
// ---------------------------------------------------------------------------
#endif
4)unit1.cpp代码如下:
// ---------------------------------------------------------------------------
#include
#include "mmsystem.h"
#pragma hdrstop
#include "Unit1.h"
// ---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
// ---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
   : TForm(Owner)
{
   TimerID = 0;
}
// ---------------------------------------------------------------------------
void CALLBACK TForm1::TimeProc(UINT uID,UINT uMsg, DWORD dwUser,DWORD dw1,DWORD dw2)
{
   Form1->Label1->Caption = Now();
}
// ---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
   TimerID = timeSetEvent(1000, 0, (LPTIMECALLBACK)TimeProc, 0,
     TIME_PERIODIC|TIME_CALLBACK_FUNCTION); // 设定多媒体定时器,1000ms
   if(TimerID == 0)  {
     ShowMessage("创建失败");
   }
}
// ---------------------------------------------------------------------------
void __fastcall TForm1::FormCloseQuery(TObject *Sender, bool &CanClose)
{
   if(TimerID != 0)  {
     timeKillEvent(TimerID); // 释放定时器
   }
}
// ---------------------------------------------------------------------------
--------------------next---------------------

阅读(291) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~