Use of timers inside C + +

Source: Internet
Author: User

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

    1. clock_t start = clock ();
    2. /*code to be tested*/
    3. clock_t end = Clock ();
    4. 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 + +

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.