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

📄 unit2.cpp

📁 一个很酷的多地区时间显示,视角是从北极往下看的地球
💻 CPP
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#include <string.h>
#include <stdlib.h>
#pragma hdrstop

#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;

//---------------------------------------------------------------------------
ASTR RegDef = "--0--default--9--" ;
//---------------------------------------------------------------------------
ASTR FAST TForm2:: RegRead(ASTR Key)
{   return  RegIniFile1->ReadString(Section, Key, RegDef) ;
}
//---------------------------------------------------------------------------
void FAST TForm2:: RegEditRead( TEdit* AEdit, ASTR Key)
{   ASTR as = RegRead(Key) ;
    if(as==RegDef) return ;
    AEdit->Text = as ;
}
//---------------------------------------------------------------------------
void FAST TForm2:: PrepTipZones(void)
{   char buf[128] ;
    strncpy(buf, TipZones->Text.c_str() , 121) ; buf[120] = 0 ;
    CSTR cs ;   CSTR pbuf = buf ;   int ix = 0 ;
    while(   (NULL != (cs = strtok(pbuf, "\t ")))  &&  ix < 9  )
    {   int Zone =    (2400 + atoi(cs))  % 24  ;
        ISTR_Tip_Zones[++ix] = Zone ;
        pbuf = NULL ;
    }
    ISTR_Tip_Zones[0] = ix  ;
}
//---------------------------------------------------------------------------
FAST TForm2::TForm2(TComponent* Owner)     : TForm(Owner)
{
	RegIniFile1	= new TRegIniFile("Software\\SpaceClock") ;
    Section = "Ver10" ;

    for(int ix=0 ; ix<ControlCount ; ix++)
    {   TControl* Control = Controls[ix] ;
        ASTR Name = Control->Name ;
        if( Name.SubString(1,4) != "Zone" )  continue ;
        int zix = StrToInt(Name.SubString(5,2)) ;
        TEdit* Edit = (TEdit*)Control ;
        ZoneEdits[zix] = Edit ;
        RegEditRead(Edit, Name) ;
    }
    RegEditRead(TipZones, "TipZones" ) ;
    PrepTipZones() ;

    ASTR as = RegRead("FontName") ;
    if(as!=RegDef)  FontDialog1->Font->Name = as ;
    TColor AColor = clRed ;
    as  = RegRead("FontColor") ;
    if(as!=RegDef) AColor = (TColor) StrToIntDef(as, 0xFF) ;
    FontDialog1->Font->Color = AColor  ;
    as = RegRead("IconPeriod") ;
    RGPeriod->ItemIndex = (as==RegDef) ? 3 : StrToIntDef(as, 3) ;
}
//---------------------------------------------------------------------------
void FAST TForm2:: RegWrite(ASTR Key, ASTR Dat)
{   RegIniFile1->WriteString(Section, Key, Dat) ;
}
//---------------------------------------------------------------------------
FAST TForm2:: ~TForm2 (void)
{
    for(int Zone=0 ; Zone<24 ; Zone++)
        RegWrite(ZoneEdits[Zone]->Name, ZoneEdits[Zone]->Text) ;

    RegWrite("FontName" ,   FontDialog1->Font->Name) ;
    RegWrite("FontColor" ,  (int)FontDialog1->Font->Color) ;
    RegWrite("TipZones" ,   TipZones->Text) ;
    RegWrite("IconPeriod",  RGPeriod->ItemIndex) ;
    delete RegIniFile1 ;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::ButtonOKClick(TObject *Sender)
{   PrepTipZones() ;
    ModalResult = mrOk   ;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::ButtonFontClick(TObject *Sender)
{   FontDialog1->Execute() ;  }
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
ASTR FAST TForm2::  ASTR_Zone( int Zone )
{   ASTR as = ZoneEdits[Zone]->Text ;
    int len = as.Length() ;
    if(!len) return as ;
    if(as.Pos(";")) return "" ;
    if('+' == as[1]) as = as.SubString(2, len-1) ;
    return as.Trim() ;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormPaint(TObject *Sender)
{   Canvas->Brush->Style = bsClear ;
    for(int zix=0 ; zix<24 ; zix++)
    {   TEdit* Edit = ZoneEdits[zix] ;
        ASTR as = ASTR(  (12<zix) ? zix-24 : zix) ;
        int xx = Edit->Left - (16 + Canvas->TextWidth(as)) ;
        Canvas->TextOut( xx, 4+Edit->Top, as) ;
    }
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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