MFC Timer SetTimer How to use callback function

Source: Internet
Author: User

Create Project name Testcallback

Custom callback functions defined as global functions

Defined at the beginning of the TestCallBackDlg.h file

#pragma once

void CALLBACK EXPORT Timerproc (HWND hwnd,uint nmsg,uint ntimerid,dword dwtime);

Implementing a function at the end of a TestCallBackDlg.cpp file

void CALLBACK EXPORT Timerproc (HWND hwnd,uint message,uint itimerid,dword dwtime)
{

The parameters of which I only know the role of HWND and Itimerid two parameters, the other is not very clear, the message is worth the news but what news, dwtime do not know

Also hope to have the great God pointing twos
SYSTEMTIME localtime;
Getlocaltime (&localtime);
TCHAR timebuffer[256];


wsprintf (Timebuffer, "%i year%i month%i Day%i%i minutes%i seconds", Localtime.wyear,localtime.wmonth
, Localtime.wday,localtime.whour,localtime.wminute,localtime.wsecond);


if (itimerid==1)
{
Setdlgitemtext (Hwnd,idc_edit1,timebuffer);
}
else if (itimerid==2)
{
Setdlgitemtext (Hwnd,idc_edit2,timebuffer);
}
}

Add Button1 button to start timer

void Testcallbackdlg::onbnclickedbutton1 ()
{
TODO: Add control notification Handler code here
SetTimer (1,1000,TIMERPROC); The Timerproc function is called once every 1s interval
SetTimer (2,2000,TIMERPROC);
}

Add Button2 button to turn off timer

void Cmfcapplication7dlg::onbnclickedbutton2 ()
{
TODO: Add control notification Handler code here
KillTimer (1);
KillTimer (2);
}

MFC Timer SetTimer How to use callback function

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.