⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chickunit.cpp

📁 网吧电脑游戏升级系统
💻 CPP
字号:
/*这份代码经源码格式软件格式化过
     yang_hx@neusoft.com      */
//---------------------------------------------------------------------------

#include<vcl.h>
#pragma hdrstop 

#include "ChickUnit.h"
#include "dos.h" 
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm" 
TForm1*Form1 ;
//---------------------------------------------------------------------------
__fastcall TForm1 :: TForm1(TComponent*Owner)
:
TForm(Owner)
{
sStartTime="00:00:01" ;
sEndTime="06:00:01" ;
bTimeState=false;
    Time= new ChickTime(true);
    Time->FreeOnTerminate=true ;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------

__fastcall ChickTime :: ChickTime(bool CreateSuspended)
:
TThread(CreateSuspended)
{
    FreeOnTerminate=true ;
    Resume();
    
}
//---------------------------------------------------------------------------
void __fastcall ChickTime :: Execute()
{
    Synchronize(CreateTimer);
//    Synchronize(UpdateCaption);
    //---- Place thread code here ----
}
//---------------------------------------------------------------------------
void __fastcall ChickTime :: UpdateCaption()
{
Form1->OnClick; 
}

void __fastcall TForm1::TimerTimer(TObject *Sender)
{
Form1->Label1->Caption = Now();
    bTimeState=false;
     Timer->Enabled = true;
    //按时触发演示程序
    struct time t;
    AnsiString thour,tmin,tsec;
    AnsiString tShour,tSmin,tSsec;
    AnsiString tEhour,tEmin,tEsec;

    //取当时时间
    gettime(&t);
    thour=AnsiString(t.ti_hour);
    tmin=AnsiString(t.ti_min);
    //tsec=AnsiString(t.ti_sec);

        tShour=sStartTime.SubString(0,2);
        tSmin=sStartTime.SubString(3,2);
        //tSsec=sStartTime.SubString(6,2);
        tEhour=sEndTime.SubString(0,2);
        tEmin=sEndTime.SubString(3,2);

    //闹钟服务功能
    if(bTimeState==false)
    {
        if ((StrToInt(thour)>StrToInt(tShour))||((StrToInt(thour)==StrToInt(tShour))&&
            (StrToInt(tmin)>=StrToInt(tSmin))))
        {
            if ((StrToInt(thour)<StrToInt(tEhour))||((StrToInt(thour)==StrToInt(tEhour))&&
                (StrToInt(tmin)<=StrToInt(tEmin))))
            {
     //           EnterCreiticalSection (&gTimeKey );
                bTimeState=true;
                //时间条件满足,置标志位。
     //           LeaveCreiticalSection (&gTimeKey);
                ShowMessage("bTimeState=true");
                return;
            }
        }
    }
    else if(bTimeState==true)
    {
        if ((StrToInt(thour)>StrToInt(tEhour))||((StrToInt(thour)==StrToInt(tEhour))&&
            (StrToInt(tmin)>=StrToInt(tEmin))))
        {
     //       EnterCreiticalSection (&gTimeKey );
            bTimeState=false;
            //时间条件满足,置标志位。
     //       LeaveCreiticalSection (&gTimeKey);
//            ShowMessage("bTimeState=false");
                Form1->Label1->Caption= tShour + tSmin;
            return;
        }
        if ((StrToInt(thour)<StrToInt(tShour))||((StrToInt(thour)==StrToInt(tShour))&&
            (StrToInt(tmin)<=StrToInt(tSmin))))
        {
     //       EnterCreiticalSection (&gTimeKey );
            bTimeState=false;
            //时间条件满足,置标志位。
     //       LeaveCreiticalSection (&gTimeKey);
 //           ShowMessage("bTimeState=false");
                 Form1->Label1->Caption= tShour + tSmin;
            return;
        }
    }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    Form1->Timer->Enabled=true;
}
//---------------------------------------------------------------------------
void _fastcall CreateTimer() //用来建立Timer
{
    FTimer = new ChickTime(true); //FTimer是TTimer *
    FTimer->Interval = 1000;
    FTimer->OnTimer = TimeOnTimer; //TIMER事件自己实现
    FTimer->Enabled = true;
}

void _fastcall DestoryTimer()  //释放TIMER
{
    delete FTimer;
}


//Synchronize(DestoryTimer);



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -