计时器程序小结
【需求】
同事希望我帮他找一个能演示PPT、Excel、Word时用于计时的程序,基本要求是:
按此要求在网上搜索了一些,包括各种类型的免费、试用安装版、绿色版软件、PPT宏等,但都不太理想。
在download.csdn.net搜索计时器找到一个好用的软件,直接运行即使得,大小只有13KB左右,估计是用C#写的,
但没有公布源码。
同事觉得我认可的这款软件并不符合他的要求,博主无奈只好亲自上阵(好在此工程不复杂)拟写了一个小程序。
贴在此处以供参考。欢迎拍砖 :)
开发环境是C++ Builder 6.0,所用控件是最简单的form、static_text,还有两个button。
使用效果图示:
源码如下——
//---------------------------------------#include <vcl.h>#pragma hdrstop#include "Unit1.h"//---------------------------------------#pragma package(smart_init)#pragma resource "*.dfm"TBearTimer *BearTimer;//---------------------------------------__fastcall TBearTimer::TBearTimer(TComponent* Owner): TForm(Owner){ this->st_time->Left=20; this->st_time->Top=5; this->st_time->Width=150; this->st_time->Height=40; this->Timer1->Enabled = false; this->st_time->Caption = "00:00:00"; //this->Btn_clear->Visible = false; //this->Btn_clear->Enabled = false; }//---------------------------------------void __fastcall TBearTimer::Timer1Timer(TObject *Sender){TDateTime tmpTime = Time(); // store the current date and time AnsiString str= (tmpTime.operator -(this->curTime) ).TimeString(); st_time->Caption=str;/*杨,xp里这样设置:控制面板>区域和语言>区域>自定义>时间>设置“长时间”显示为HH:mm:ss,我猜你现在的设置应该是"tt hh:mm:ss" 你看下对不对;可以打开计时器,设置时间以后点应用,计时器显示会变, 然后换个设置再点应用,计时器显示又变。*/// 由于不同的操作系统对显示时间(注意不是日期)的默认设置不同, // 若要显示设计者希望出现的效果,则应调整系统时间设置,按上}//---------------------------------------void __fastcall TBearTimer::Btn_beginClick(TObject *Sender){ this->curTime = Time(); // store the current date and time this->Timer1->Enabled = true;}//---------------------------------------void __fastcall TBearTimer::Btn_clearClick(TObject *Sender){this->Timer1->Enabled = false; this->st_time->Caption = "00:00:00";//暂停功能则注释该行}//---------------------------------------//优化://1、如何只刷新数字,不闪屏//2、前置--已实现 FormStyle=fsStayOnTop//3、去掉最大化--已实现 BorderStyle=bsDialog, BorderIcons只选择最小化与系统菜单/* 杨界面还需改进。 --已实现 Form 和 st_time 底色均用clBlack界面再亮丽一点、字体再清晰一点 --已实现 st_time font选用Quartz(下载置于C:/Windows/Fonts文件夹下), 颜色酸橙色增加微秒。--无必要,暂不修改就差不多了*/// 讨论:第二个按钮设置成清零,还是暂停好?因为“开始”点一下就自动清零了,暂时用“清零”