Unit1.cpp
上传用户:wangcy_007
上传日期:2022-01-31
资源大小:343k
文件大小:2k
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "Unit1.h"
- #include "mmsystem.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- TimerID = 0;
- }
- //---------------------------------------------------------------------------
- double _sqrt(double a)
- {
- double x1 = 0.0;
- double x2 = a/2;
- while(x1!= x2)
- {
- x1 = x2;
- x2 = (x1 + a/x1)/2;
- }
- return x1;
- }
- //------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- TimerID = timeSetEvent(1000, 0, (LPTIMECALLBACK)TimeProc, 0,TIME_PERIODIC); // 设定多媒体定时器,1000ms
- if(TimerID == 0) {
- ShowMessage("创建失败");
- }
- }
- //---------------------------------------------------------------------------
- void CALLBACK TForm1::TimeProc(UINT uID,UINT uMsg, DWORD dwUser,DWORD dw1,DWORD dw2)
- {
- static int a=0;
- a++;
- Form1->Label1->Caption=IntToStr(a);
- //Form1->Label1->Caption = Now();
- }
- void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
- {
- if(TimerID != 0) {
- timeKillEvent(TimerID); // 释放定时器
- }
- }
- //---------------------------------------------------------------------------