在头文件中代码:
void SetMTimer(UINT nEventID,UINT nElapse);
void KillMTimer(UINT nEventID);
static void CALLBACK MTimerProc(HWND hwnd,UINT uMsg,UINT nTimerID,DWORD dwTime,plugclass* pthis);
源文件代码:
先声明一个全局类指针 static plugclass* pClass;
void plugclass::SetMTimer(UINT nEventID,UINT nElapse)
{
CGTDemoDlg *pMainDlg = (CGTDemoDlg*)AfxGetApp()->m_pMainWnd; //使用主窗体的Handle
HWND hand = pMainDlg->m_hWnd;
SetTimer(hand,nEventID,nElapse,(TIMERPROC)MTimerProc); //自己定义SetTimer 的 CALLBACK Function
}
void plugclass::KillMTimer(UINT nEventID)
{
CGTDemoDlg *pMainDlg = (CGTDemoDlg *)AfxGetApp()->m_pMainWnd; //使用主窗体的Handle
HWND hand = pMainDlg->m_hWnd;
KillTimer(hand,nEventID);
}
void CALLBACK plugclass::MTimerProc(HWND hwnd,UINT uMsg,UINT nTimerID,DWORD dwTime,plugclass* pthis)
{
pthis = pClass; //这里传入当前类指针
switch (nTimerID)
{
case 0:
pthis->GetTimerID(nTimerID);
break;
default:
break;
}
}
void plugclass::GetTimerID(UINT nTimerID)
{
switch(nTimerID)
{
case 0:
{
AfxmessageBox(L"0");
}
break;
default:
break;
}
}
调用方法
SetMTimer(0,1000*60);
KillMTimer(0);