#include
#include
using namespace std;
The int function ()
{
return 0;
}
Int main ()
{
The SetTimer (NULL, 0, 0, & amp; Function);//error
system("pause");
return 0;
}
How do I make the function function cycle
CodePudding user response:
1, the parameters of the callback function, the statement is wrong, please check the MSDN.2, there is no call GetMessage and DispatchMessage
CodePudding user response:
Is not so easy to use, need to add a message loop, because the SetTimer is based on message loop mechanism, and your back off function parameter is also wrong, suggest you write a first base win32 application window again to solve this problemCodePudding user response:
Use MFC automatically carry a lookCodePudding user response:
Fyi:# pragma comment (lib, "user32")
#include
#include
#include
#include
Char datestr [16].
Char timestr [16].
Char MSS [4].
Void the log (char * s) {
* struct tm now;
Struct timeb TB;
Ftime (& amp; TB);
Now=localtime (& amp; TB. Time);
Sprintf (datestr, "% d % % 4 d - 02-02 d", now - & gt; Tm_year + 1900, now - & gt; Tm_mon + 1, now - & gt; Tm_mday);
Sprintf (timestr, "02 02 02 % d: % d: % d", now - & gt; Tm_hour, now - & gt; Tm_min, now - & gt; Tm_sec);
Sprintf (MSS, "% 3 d", TB. Millitm);
Printf (" % s % s. % s % s ", datestr, timestr, MSS, s);
}
VOID CALLBACK myTimerProc1 (
HWND HWND,//handle of the window for the timer messages
UINT uMsg,//WM_TIMER message
UINT idEvent,//timer identifier
DWORD dwTime//the current system time
) {
The log (" In myTimerProc1 \ n ");
}
VOID CALLBACK myTimerProc2 (
HWND HWND,//handle of the window for the timer messages
UINT uMsg,//WM_TIMER message
UINT idEvent,//timer identifier
DWORD dwTime//the current system time
) {
The log (" In myTimerProc2 \ n ");
}
Int main () {
int i;
MSG MSG.
SetTimer (NULL, 0, 0100 myTimerProc1);
SetTimer (NULL, 0, 0200 myTimerProc2);
for (i=0; i<20; I++) {
Sleep (500);
The log (In the main "\ n");
If (GetMessage (& amp; MSG, NULL, 0, 0)) {
TranslateMessage (& amp; MSG);
DispatchMessage (& amp; MSG);
}
}
return 0;
}
//the 2012-07-26 17:29:06. 375 In the main
//the 2012-07-26 17:29:06. 875 In myTimerProc1
//the 2012-07-26 17:29:07. 375 In the main
//the 2012-07-26 17:29:07. 875 In myTimerProc2
//the 2012-07-26 17:29:08. 375 In the main
//the 2012-07-26 17:29:08. 375 In myTimerProc1
//the 2012-07-26 17:29:08. 875 In the main
//the 2012-07-26 17:29:08. 875 In myTimerProc1
//the 2012-07-26 17:29:09. 375 In the main
//the 2012-07-26 17:29:09. 890 In myTimerProc2
//the 2012-07-26 17:29:10. 390 In the main
//the 2012-07-26 17:29:10. 390 In myTimerProc1
//the 2012-07-26 17:29:10. 890 In the main
//the 2012-07-26 17:29:10. 890 In myTimerProc1
//the 2012-07-26 17:29:11. 390 In the main
//the 2012-07-26 17:29:11. 890 In myTimerProc2
//the 2012-07-26 17:29:12. 390 In the main
//the 2012-07-26 17:29:12. 390 In myTimerProc1
//the 2012-07-26 17:29:12. 890 In the main
//the 2012-07-26 17:29:12. 890 In myTimerProc1
//the 2012-07-26 17:29:13. 390 In the main
//the 2012-07-26 17:29:13. 890 In myTimerProc2
//the 2012-07-26 17:29:14. 390 In the main
//the 2012-07-26 17:29:14. 390 In myTimerProc1
//the 2012-07-26 17:29:14. 890 In the main
//the 2012-07-26 17:29:14. 890 In myTimerProc1
//the 2012-07-26 17:29:15. 390 In the main
//the 2012-07-26 17:29:15. 890 In myTimerProc2
//the 2012-07-26 17:29:16. 390 In the main
//the 2012-07-26 17:29:16. 390 In myTimerProc1
//the 2012-07-26 17:29:16. 890 In the main
//the 2012-07-26 17:29:16. 890 In myTimerProc1
//the 2012-07-26 17:29:17. 390 In the main
//the 2012-07-26 17:29:17. 890 In myTimerProc2
//the 2012-07-26 17:29:18. 390 In the main
//the 2012-07-26 17:29:18. 390 In myTimerProc1
//the 2012-07-26 17:29:18. 890 In the main
//the 2012-07-26 17:29:18. 890 In myTimerProc1
//the 2012-07-26 17:29:19. 390 In the main
//the 2012-07-26 17:29:19. 890 In myTimerProc2
CodePudding user response:
Int main (){
While (TRUE)
{
,,,,,,,
}
return 0;
}
CodePudding user response: