关于Timer的回调函数的问题
VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
MessageBox(NULL, L"Timer2 Arrive", NULL, NULL);
}
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
SetTimer(NULL, 100, 5000, TimerProc);
//用while循环阻塞
while(1)
{Sleep(100);}
return 0;
}
这里Timer的callback一直不会被调用。
但用MessageBox阻塞,Timer的callback就会被调到
code如下:
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
SetTimer(NULL, 100, 5000, TimerProc);
//用while循环阻塞
MessageBox(NULL, L"Timer", NULL, NULL);
return 0;
}
那是不是说明要调用Timer就一定要有消息循环?那如果在没有消息循环的情况下想用Timer怎么办?只能建线程sleep么?