timer.c
来自「开发linux应用-用gtk+和gdk开发linux图形用户界面应用--的实例」· C语言 代码 · 共 73 行
C
73 行
/* * Timer.c * * Auth: Eric Harlow * * Routines to update something every second. */#include <gtk/gtk.h>static int nSeconds = 0; static gint timer = 0;static int bTimerRunning = FALSE;void UpdateSeconds (int);/* * TimerCallback * * Every second, this will be called to update the time * in the clock window. */gint TimerCallback (gpointer data){ /* --- Another second has gone by --- */ nSeconds++; UpdateSeconds (nSeconds);}/* * StartTimer * * Starts up the time. Happens when the user first * clicks on a button. */void StartTimer (){ /* --- If the timer isn't already running --- */ if (!bTimerRunning) { /* --- Start at zero --- */ nSeconds = 0; /* --- Call function 'TimerCallback' every 1000ms --- */ timer = gtk_timeout_add (1000, TimerCallback, NULL); /* --- Timer is running. --- */ bTimerRunning = TRUE; }}/* * StopTimer * * Stops the timer. User probably hit a bomb. */void StopTimer (){ /* --- If the time is running. --- */ if (bTimerRunning) { /* --- Stop the timer. --- */ gtk_timeout_remove (timer); /* --- Fix the flag. --- */ bTimerRunning = FALSE; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?