定时器回调函数中的奇怪问题?
下面是一个定时器的回调函数以及调用它的函数:
void CGameApp2View::OnCallback1()
{
SetTimer(1,1000,timeup1);
}
void CALLBACK CGameApp2View::timeup1(HWND hWnd, UINT nMsg, UINT nIDEvent, DWORD dwTime)
{
CGameApp2View *pWnd; //声明窗口的函数
pWnd=(CGameApp2View*)AfxGetMainWnd(); //取得窗口指针
char buffer [33];
itoa (pWnd->picnum,buffer,10);
::MessageBox(NULL,buffer,"警告",MB_ICONWARNING);
pWnd->picnum++;
if(pWnd->picnum>=3)
{
pWnd->KillTimer(1);
return;
}
}
其中picnum是一个CGameApp2View类中的一个成员变量(int类型的数,初始化为0)
现在我想测试一下在这个定时器的回调函数中picnum的数值如何,就用了上面的代码
现在出现了两个问题:
(1)弹出的数值是6113304,6113305...,而不是0,1,2...
(2) pWnd->KillTimer(1); 这句话不起作用,数值会一直加下去,没有停止,说明
定时器并没有被消灭
这到底是怎么回事?该怎么写那?
请高手指教。