Create a dialog box with time for the title bar

Source: Internet
Author: User
Tags string format

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 ();}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.