在mfc的界面中添加动态时间:系统时间(动态),软件运行时间(动态)
先在.h头文件中定义线程(可用定时器OnTime来替换线程);
public:
static DWORD WINAPI threadFuncTime(LPVOID threadTime);//时间线程
HANDLE hThreadTime;//柄
DWORD ThreadIDTime;//ID
其次在“资源视图”点开工程项目,在Dialog里面找到对应的DIALOG,“工具箱”点击“Static Text”,拖出一个静态框并把ID改成IDC_Time
然后往.cpp文件中 DWORD XXXDlg::threadFuncTime(LPVOID threadTime) 函数添加代码
DWORD XXXDlg::threadFuncTime(LPVOID threadTime)
{
CPictureprocessingDlg * pDTime = (CPictureprocessingDlg*)threadTime;
CTime CurrentTime;//时间函数
CString strTime, c_Time;
//StartTime = CTime::GetCurrentTime();
int s;
long t1 = GetTickCount();//获取软件运行
while (1)
{
CurrentTime = CTime::GetCurrentTime();
c_Time = CurrentTime.Format(" %Y年%m月%d日 %H:%M:%S");//转换CString
pDTime->SetWindowText(L"界面顶部title显示的系统时间" + c_Time);
long t2 = GetTickCount();//程序段结束后取得系统运行时间(ms)
//转换成00:00:00形式
s = (t2 - t1) / 1000;
strTime.Format(L"%.2d:%.2d:%.2d",
s / 3600, (s - (s / 3600 * 3600)) / 60,
s - (s / 3600 * 3600) - (s - (s / 3600 * 3600)) / 60 * 60);//转化为00:00:00格式
pDTime->SetDlgItemTextW(IDC_Time, L"软件运行时间 " + strTime);
Sleep(1000);//休眠1000毫秒
}
return 0;
}