First create an MFC dialog box program, and then add the following members to the dialog box class
Private
CTime m_begintime;//Software startup time
CTime m_endtime;//Software End time
Then add the following code in the initialization dialog function OnInitDialog ()
M_begintime = Ctime::getcurrenttime ();//give the current software start time
SetTimer (1,1000,null)//Set Clock
Create two message events Wm_timer and Wm_close
[CPP] View Plain copy print? Void cmyclockdlg::ontimer (uint nidevent) { //Create a current time Ctime ctime = ctime::getcurrenttime (); CString strTime; //string format time Strtime.format ("Current time:%d years%d months%d days%d%d seconds", Ctime.getyear (), Ctime.getmonth (), Ctime.getday (), Ctime.gethour (), Ctime.getminute (), Ctime.getsecond ()); //Set the current window caption setwindowtext (strtime); cdialog::ontimer (nidevent); } void Cmyclockdlg::ontimer (UINT Nidevent) {//Create a current time CTime CTime = Ctime::getcurrenttime (); CString Strtime; String format time Strtime.format ("whenPrevious time:%d years%d months%d days%d%d seconds, ctime.getyear (), Ctime.getmonth (), Ctime.getday (), Ctime.gethour (), Ctime.getminute (), Ctime.getsecond ()); Sets the current window title SetWindowText (strtime); Cdialog::ontimer (nidevent); }
[CPP] View Plain copy print? Void cmyclockdlg::onclose () { // will timer 1 delete killtimer (1); / /Give software end time m_endtime = ctime::getcurrenttime (); //the number of seconds to get software from start to finish CTimeSpan ctSpan = m_EndTime - m_beginTime; CString strTime; //format elapsed time Strtime.format ("Software run Time:%d%d times%d minutes%d seconds", ctspan.getdays (), ctspan.gethours (), Ctspan.getminutes (), Ctspan.getseconds ( ); //Output MessageBox (strtime); cdialog::onclose (); } void Cmyclockdlg::onclose () {//Remove Timer 1 KillTimer (1);//Give software end time M_endtime = Ctime::getcurrenttim E (); The number of seconds to get software from beginning to end ctimespan Ctspan = M_endtime-m_begintime; CString Strtime; Format Elapsed Time Strtime.format ("Software run Time:%d%d times%d seconds", ctspan.getdays (), ctspan.gethours (), Ctspan.getminutes (), Ctspan.getseconds ()); Output MessageBox (strtime); Cdialog::onclose (); }
First create an MFC dialog box program, and then add the following members to the dialog class Private:ctime m_begintime;//software start time CTime m_endtime;//software end time Then add the following code in the initialization dialog function OnInitDialog () M_begintime = Ctime::getcurrenttime ();//give the current software start time SetTimer (1,1000,null);//Set Clock Establish two message events Wm_timer and Wm_close [CPP] View plaincopyprint?void cmyclockdlg::ontimer (UINT nidevent) {//Create a current time CTime CTime = Ctime::getcurrenttime (); CString Strtime; String format time Strtime.format ("Current time:%d%d months%d days%d%d seconds", Ctime.getyear (), Ctime.getmonth (), Ctime.getday (), Ctime.gethour (), Ctime.getminute (), Ctime.getsecond ()); Sets the current window title SetWindowText (strtime); Cdialog::ontimer (nidevent); } void Cmyclockdlg::ontimer (UINT nidevent) {//Create a current time CTime CTime = Ctime::getcurrenttime (); CString Strtime; String format time Strtime.format ("Current time:%d%d months%d days%d%d seconds", Ctime.getyear (), Ctime.getmonth (), Ctime.getday (), Ctime.gethour (), Ctime.getminute (), Ctime.getsecond ()); Sets the current window title SetWindowText (strtime); Cdialog::ontimer (nidevent);} [CPP] View plaincopyprint?void cmyclockdlg::onclose () {//Remove Timer 1 KillTimer (1);Give software end time M_endtime = Ctime::getcurrenttime (); The number of seconds to get software from beginning to end ctimespan Ctspan = M_endtime-m_begintime; CString Strtime; Format Elapsed Time Strtime.format ("Software run Time:%d%d times%d seconds", ctspan.getdays (), ctspan.gethours (), Ctspan.getminutes (), Ctspan.getseconds ()); Output MessageBox (strtime); Cdialog::onclose (); } void Cmyclockdlg::onclose () {//Remove Timer 1 KillTimer (1);//Give software end time M_endtime = Ctime::getcurrenttime ();// The number of seconds to get software from beginning to end ctimespan Ctspan = M_endtime-m_begintime; CString Strtime; Format Elapsed Time Strtime.format ("Software run Time:%d%d times%d seconds", ctspan.getdays (), ctspan.gethours (), Ctspan.getminutes (), Ctspan.getseconds ()); Output MessageBox (Strtime); Cdialog::onclose ();}