下面的程序执行没有结果#include<stdio.h>
#include<afx.h>VOID CALLBACK MyTimerProc(
HWND hwnd, // handle to window
UINT uMsg, // WM_TIMER message
UINT_PTR idEvent, // timer identifier
DWORD dwTime // current system time
)
{
printf("ok");
}
void main()
{ UINT nTimerID; nTimerID=SetTimer(
NULL, // handle to window must set NULL
NULL, // timer identifier will be ignored.
1000, // time-out value
(TIMERPROC)MyTimerProc // timer procedure
);
printf("%d",nTimerID);
}
#include<afx.h>VOID CALLBACK MyTimerProc(
HWND hwnd, // handle to window
UINT uMsg, // WM_TIMER message
UINT_PTR idEvent, // timer identifier
DWORD dwTime // current system time
)
{
printf("ok");
}
void main()
{ UINT nTimerID; nTimerID=SetTimer(
NULL, // handle to window must set NULL
NULL, // timer identifier will be ignored.
1000, // time-out value
(TIMERPROC)MyTimerProc // timer procedure
);
printf("%d",nTimerID);
}
应该可以的,用GetLastError看看错误码.
作为你的程序,在SetTimer之后,应该至少有一个非死线程继续运行
是不是要写一个
while(1)
{
...
}
DWORD dwResult;
HANDLE hEventArray[2];
HANDLE hTimerEvent = CreateEvent( NULL, FALSE, FALSE, NULL );
hEventArray[0] = m_hExitEvent;
hEventArray[1] = m_hTimerEvent;
UINT nTID = timeSetEvent( FLUSH_TIMER, 1000, (LPTIMECALLBACK)hTimerEvent,
NULL, TIME_PERIODIC|TIME_CALLBACK_EVENT_SET );
while ( m_bExitFlag )
{
dwResult = WaitForMultipleObjects( 2, hEventArray, FALSE, INFINITE );
switch (dwResult)
{
case WAIT_OBJECT_0 :
timeKillEvent( nTID );
CloseHandle( hTimerEvent);
return 0;
case WAIT_OBJECT_0 + 1:
// 这里做你定时器需要做的处理
break;
case WAIT_FAILED:
// A fatal error. Pop up a message box and break out of
// the while loop to end the thread.
::GetLastError());
continue;
case WAIT_IO_COMPLETION:
// An I/O completion routine has been executed. Cleanup
// has already occurred in SendCompFunc, so there is
// nothing left to do. Just reiterate through the loop.
continue;
}
}
timeKillEvent( nTID );
CloseHandle( hTimerEvent);