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