在没有窗口的程序中,使用定时器:
#include <windows.h>
#include <iostream>
using namespace std;
DWORD dwTimeId = 0;
VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
if(dwTimeId == idEvent)
{
static DWORD i = 0;
cout<<"Timer Proc : "<<++i<<endl;
if(i == 10)
{
KillTimer(NULL, dwTimeId);
cout<<"Timer End!!"<<endl;
PostQuitMessage(0);
}
}
}
int main()
{
dwTimeId = SetTimer(NULL, 1, 500, TimerProc);
MSG msg;
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
cout<<"Process End!!"<<endl;
return 0;
}