void CMFCTimeOperateDlg::OnBnClickedBtnGetctime()
{
// TODO: 在此添加控件通知处理程序代码
if (!m_bCtime)
{
CTime currTime = CTime::GetCurrentTime();
CString strCTime = currTime.Format(_T("%Y-%m-%d %H:%M:%S"));
GetDlgItem(IDC_EDIT_CURRTIME1)->SetWindowText(strCTime);
SetTimer(1, 1000, NULL);
m_bCtime = TRUE;
GetDlgItem(IDC_BTN_GETCTIME)->SetWindowText(_T("暂停"));
}
else
{
KillTimer(1);
m_bCtime = false;
GetDlgItem(IDC_BTN_GETCTIME)->SetWindowText(_T("获取CTime"));
}
}
void CMFCTimeOperateDlg::OnCloseupDatetimepicker1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: 在此添加控件通知处理程序代码
m_DateTimeCtrl1.GetTime(m_BaseTime);
*pResult = 0;
}
void CMFCTimeOperateDlg::OnCloseupDatetimepicker2(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: 在此添加控件通知处理程序代码
m_DateTimeCtrl2.GetTime(m_BaseOleDateTime);
*pResult = 0;
}
void CMFCTimeOperateDlg::OnBnClickedBtnGetctimespan()
{
// TODO: 在此添加控件通知处理程序代码
CTime currTime = CTime::GetCurrentTime();
CTimeSpan timeSpan = currTime-m_BaseTime;
/*CString strTimeSpan = _T("");*/
CString strTimeSpan = timeSpan.Format(_T("总天数:%D 小时:%H,分:%M,秒:%S"));
GetDlgItem(IDC_EDIT_TIMESPAN1)->SetWindowText(strTimeSpan);
}
void CMFCTimeOperateDlg::OnBnClickedBtnGetoletime()
{
// TODO: 在此添加控件通知处理程序代码
if (!m_bCOleDateTime)
{
COleDateTime currTime = COleDateTime::GetCurrentTime();
CString strCOleDateTime = currTime.Format(_T("%a %b %d,%Y, %H:%M:%S"));
GetDlgItem(IDC_EDIT_CURRTIME3)->SetWindowTextW(strCOleDateTime);
SetTimer(2, 1000, NULL);
m_bCOleDateTime = true;
GetDlgItem(IDC_BTN_GETOLETIME)->SetWindowText(_T("暂停"));
}
else
{
KillTimer(2);
m_bCOleDateTime = false;
GetDlgItem(IDC_BTN_GETOLETIME)->SetWindowText(_T("获取COleDateTime"));
}
}
void CMFCTimeOperateDlg::OnBnClickedBtnGetoletimespan()
{
// TODO: 在此添加控件通知处理程序代码
COleDateTime currTime = COleDateTime::GetCurrentTime();
COleDateTimeSpan oleTimeSpan = currTime - m_BaseOleDateTime;
CString strOleDateTimeSpan = oleTimeSpan.Format(_T("Days:%D,Hours:%H,Minutes:%M,Seconds:%S"));
GetDlgItem(IDC_EDIT_TIMESPAN2)->SetWindowTextW(strOleDateTimeSpan);
}
void CMFCTimeOperateDlg::OnTimer(UINT_PTR nIDEvent)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if (nIDEvent ==1)
{
CTime currTime = CTime::GetCurrentTime();
CString strCTime = currTime.Format(_T("%a %b %d, %Y,%H:%M:%S"));
GetDlgItem(IDC_EDIT_CURRTIME1)->SetWindowText(strCTime);
}
else if (nIDEvent == 2)
{
COleDateTime currTime = COleDateTime::GetCurrentTime();
CString strCOleDateTime = currTime.Format(_T("%a %b %d,%Y, %H:%M:%S"));
GetDlgItem(IDC_EDIT_CURRTIME3)->SetWindowTextW(strCOleDateTime);
}
CDialogEx::OnTimer(nIDEvent);
}