MFC Timer Timer

Source: Internet
Author: User

Knowledge Points: Timer timer to create timer destroy timer code test one, create timer UINT SetTimer (HWND hwnd,//Specifies the window handle of the associated timer, which is omitted in the MFC versionUINT nidevent,//Timer IDUINT Uelapse,//time interval unit millisecondsTimerproc Lptimerfunc//Timer callback function address); Timer callback function format void CALLBACK Timerproc (HWND hwnd,//Handle of window for timer messagesUINT umsg,//Wm_timer MessageUINT idevent,//Timer identifierDWORD Dwtime//Current system time); second, destroy timer BOOL KillTimer (HWND hwnd,//Handle of window that installed timerThis parameter will be omitted in the MFC version of UINT Uidevent//Timer identifier); Third, code testing//Live Display current time reference C language 053 lessonstime_t T;time (&t); TM*timeinfo=localtime (&t); M_stime.format (L"%02d:%02d:%02d",timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec);//Code//Cdialog_timer message handlersvoidCALLBACK EXPORT Timerproc (HWND hwnd,//handle of CWnd that called SetTimerUINT Nmsg,//Wm_timerUINT Nidevent,//Timer IdentificationDWORD Dwtime//System Time                               ){    if(Nidevent==mytimerid)//    {        //Execute CodeTRACE ("my Timerproc%d\n", Dwtime); //Show Current Timetime_t t; Time (&t); TM*timeinfo=localtime (&t); TRACE ("%02d:%02d:%02d",timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); }}voidCdialog_timer::onbnclickedbutton1 () {//TODO: Add control notification handler code here//SetTimer (1001,1000,null);//Wm_timerSetTimer (1001, +, Timerproc);//does not produce wm_timer}lresult Cdialog_timer::windowproc (UINT message, WPARAM WPARAM, LPARAM LPARAM) {//TODO: Add private code here and/or call base class//if (message==wm_timer)//{     //if (Wparam==mytimerid)//     // {        //  //Execute Code//TRACE ("1111111111\n"); //  //Show Current Time//time_t t; //Time (&t); //TM *timeinfo=localtime (&t); //M_stime.format (L "%02d:%02d:%02d", timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); //UpdateData (FALSE); // }  //}    returncdialog::windowproc (Message, WParam, LParam);}voidCdialog_timer::onbnclickedbutton2 () {//TODO: Add control notification handler code hereKillTimer (Mytimerid);//Destroying Timers}voidCdialog_timer::ontimer (uint_ptr nidevent) {//TODO: Add Message Handler code and/or call default values here    if(Nidevent==mytimerid)//         {          //Execute CodeTRACE ("1111111111\n"); //Show Current Timetime_t t; Time (&t); TM*timeinfo=localtime (&t); M_stime.format (L"%02d:%02d:%02d",timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); UpdateData (false); } cdialog::ontimer (nidevent);}

MFC Timer Timer

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.