原来一个服务(用线程定时运行一个程序)例子是这样的:
void CALLBACK MyTimerProc(
HWND hwnd,
UINT uMsg,
UINT idEvent,
DWORD dwTime )
{
::MessageBox(NULL, _T("timer"), _T("SMS"), MB_OK);
} unsigned long __cdecl MyControllingFunction( LPVOID pParam )
{
g_nTimer = SetTimer(0, 0, 10 * 1000, MyTimerProc); //定时 10秒运行一次MSG msg;
while (GetMessage(&msg, 0, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
} 主程序调用
DWORD MYS_Init(DWORD dwData){
HANDLE hThread = CreateThread( 0, 0, MyControllingFunction, 0, 0, 0); } 这是10秒钟执行一次程序MessageBox ,
但我想就运行1次程序,就可以了,不要一直循环执行这个程序,
那上面的程序里要怎么改啊?
void CALLBACK MyTimerProc(
HWND hwnd,
UINT uMsg,
UINT idEvent,
DWORD dwTime )
{
::MessageBox(NULL, _T("timer"), _T("SMS"), MB_OK);
} unsigned long __cdecl MyControllingFunction( LPVOID pParam )
{
g_nTimer = SetTimer(0, 0, 10 * 1000, MyTimerProc); //定时 10秒运行一次MSG msg;
while (GetMessage(&msg, 0, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
} 主程序调用
DWORD MYS_Init(DWORD dwData){
HANDLE hThread = CreateThread( 0, 0, MyControllingFunction, 0, 0, 0); } 这是10秒钟执行一次程序MessageBox ,
但我想就运行1次程序,就可以了,不要一直循环执行这个程序,
那上面的程序里要怎么改啊?
void CALLBACK MyTimerProc(
HWND hwnd,
UINT uMsg,
UINT idEvent,
DWORD dwTime )
{
::MessageBox(NULL, _T("timer"), _T("SMS"), MB_OK);
KillTimer(idEvent);
}
void CALLBACK MyTimerProc(
HWND hwnd,
UINT uMsg,
UINT idEvent,
DWORD dwTime )
{
::MessageBox(NULL, _T("timer"), _T("SMS"), MB_OK);
KillTimer(idEvent);
}