GTK timer function

Source: Internet
Author: User
Timer functions
The timer function can be used to time an operation (for example, to record how long an operation has taken ). The first step to use it is to use the G _ t I m e r _ N E W () function to create a timer, then use the G _ t I m e r _ s t a r t () function to start timing the operation, and use g _ t I m e r _ s t o p () the function stops timing the operation. Use the G _ t I m e r _ E L A P S E d () function to determine the timer running time.
Create a new Timer:
Gtimer * g_timer_new (void );
Destruction Timer:
Void g_timer_destroy (gtimer * timer );
Start timing:
Void g_timer_start (gtimer * timer );
Stop timing:
Void g_timer_stop (gtimer * timer );
Reset zero for timing:
Void g_timer_reset (gtimer * timer );
Get the timer elapsed time:
Gdouble g_timer_elapsed (gtimer * timer,
Gulong * microseconds );

Sometimes you may want to know how to enable g t k in the main cycle of g t k _ m a I n. At this time, you can create a timer (Ti m e o u t) function, which is called once every certain time (milliseconds. Ti m e o u t is similar to the timer control in other programming environments. The following function is used to add a Ti m e o u t function.
# Include <GTK/gtkmain. h>
Gint gtk_timeout_add (guint32 interval, gtkfunction function, gpointer data );
The time interval between the first parameter and the scheduled function, in milliseconds. The second parameter is the function to be called, and the third parameter is the parameter to be passed to the function. The function returns an integer "flag ". You can use the following function to stop calling a scheduled function:
# Include <GTK/gtkmain. h>
Void gtk_timeout_remove (Gint tag );
The t a g parameter is the "flag" value returned by the previous function. The callback function can also return fa l s e or 0 to stop calling the scheduled function. That is to say, to continue calling a function, you must have it return a non-0 value or t r u e. The callback function declaration for regular calls should be in the following format:
Gint timeout_callback (gpointer data );
As you can see, the Ti m e o u t function is similar to the Ti m e r control (timer) in many visual programming tools ).

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.