Using a timer in the console cannot be a simple settimer. This settimer method in the console is a little troublesome and requires you to write messages cyclically to deliver wm_timer messages. In fact, you can use the multimedia clock in the console for timing:
Example:
// Start the timer
Mmresult nidtimerevent = timesetevent (
1000, // 1 second delay
0,
Timeproc,
0,
(Uint) time_periodic );
If (nidtimerevent = 0)
Cout <"Startup timer failed" <Endl;
// Callback process (when the clock arrives, the callback function is automatically called by the System)
Void callback timeproc (
Uint uid,
Uint umsg,
DWORD dwuser,
DWORD dw1,
DWORD dw2
)
{
Cout <"clock arrival" <Endl;
}
Of course, if you are used to settimer, use settimer:
The following is an example of using settimer in the console:
# Include <windows. h>
# Include <iostream>
Using namespace STD;
Void callback timeproc (
Hwnd,
Uint message,
Uint idtimer,
DWORD dwtime );
Int main ()
{
Settimer (null, 1,1000, timeproc );
MSG;
While (getmessage (& MSG, null, 0, 0 ))
{
If (msg. Message = wm_timer)
{
Dispatchmessage (& MSG );
}
}
Return 0;
}
Void callback timeproc (
Hwnd,
Uint message,
Uint idtimer,
DWORD dwtime)
{
Cout <"a timer comming" <Endl;
}