To be blunt is the use of three functions:
SetTimer (20, 20, 0); The first 20 represents the identifier of this timer, the second 20 indicates the time you want to set, the third one without tube, set 0.
void Clms511_interfacedlg::ontimer (Uint_ptr nidevent)
{
Todo:add your message handler code here and/or call default
if (nidevent = = 20)//This 20 is the first 20.
{
DrawData ();
if (Myssocket.stopflag)
Sendserver ();
}
Cdialog::ontimer (nidevent);
}
KillTimer (20); Destroy the timer with the identifier 20
Description
The first parameter of the SetTimer () timer is the timer ID, which can be used for any integer other than 0, and the second parameter is the time interval of the timer, in milliseconds. The third parameter value can be null,
At this point wm_timer messages are added to the application's message queue, handled by the CWnd class object
For example, the time interval for SetTimer (1,1,null) is 1 milliseconds
Here's an example of the kind of timing function:
of the CWnd class
Cwnd::settimer
UINT nidevent, //identifier of the timer
UINT nelapse, //time to be timed
Here is an example of how to measure the time a program runs in C + +:
unsigned long ticks1,ticks2;
At the beginning of the test you want to write
TICKS1 = GetTickCount ();
At the end of the test section, write
Ticks2 = GetTickCount ();
TICKS2-TICKS1 is the time spent
Plus this header file Winbase.h
A method for measuring the execution time of a program is described below:
<time.h> version
- clock_t start = clock ();
- /*code to be tested*/
- clock_t end = Clock ();
- cout<<end-start<<endl;
Many people this version is probably not unfamiliar, this should be the most common execution time test method, can be accurate to the MS level.
function trace () to print to the screen while the program is running
TRACE ("Distance:%d", m_dist[i]);//output information in the output bar.
is to log information. %s is replaced with the address corresponding value when the program executes. %d replaces the error code returned by the function WSAGetLastError ().
The specific is to write to the file inside, or output to the standard output is the screen, this depends on the implementation of the trace.
There is also a timed method that is implemented with the sleep () function. Call Windows.h
Use of timers inside C + +