MiniGUI API Reference (MiniGUI-Standalone)  v3.2.0
A mature and proven cross-platform GUI system for embedded and smart IoT devices
Macros | Typedefs | Functions
Timer operations

Macros

#define SetTimer(hwnd, id, speed)   SetTimerEx(hwnd, id, speed, NULL)
 The backward compatibility version of SetTimerEx. More...
 
#define ResetTimer(hwnd, id, speed)   ResetTimerEx(hwnd, id, speed, (TIMERPROC)INV_PTR)
 The backward compatibility version of ResetTimerEx. More...
 

Typedefs

typedef BOOL(* TIMERPROC) (HWND, LINT, DWORD)
 Type of the timer callback procedure. More...
 

Functions

MG_EXPORT BOOL GUIAPI SetTimerEx (HWND hWnd, LINT id, DWORD speed, TIMERPROC timer_proc)
 Creates a timer with the specified timeout value. More...
 
MG_EXPORT int GUIAPI KillTimer (HWND hWnd, LINT id)
 Destroys a timer. More...
 
MG_EXPORT BOOL GUIAPI ResetTimerEx (HWND hWnd, LINT id, DWORD speed, TIMERPROC timer_proc)
 Adjusts a timer with a different timeout value or different timer callback procedure. More...
 
MG_EXPORT DWORD GUIAPI GetTickCount (void)
 Retrieves the tick counts that have elapsed since MiniGUI was started. More...
 
MG_EXPORT BOOL GUIAPI IsTimerInstalled (HWND hWnd, LINT id)
 Determines whether a timer is installed. More...
 
MG_EXPORT BOOL GUIAPI HaveFreeTimer (void)
 Determines whether there is any free timer slot in the system. More...
 

Detailed Description

Macro Definition Documentation

#define ResetTimer (   hwnd,
  id,
  speed 
)    ResetTimerEx(hwnd, id, speed, (TIMERPROC)INV_PTR)

The backward compatibility version of ResetTimerEx.

See also
ResetTimerEx

Definition at line 7752 of file window.h.

#define SetTimer (   hwnd,
  id,
  speed 
)    SetTimerEx(hwnd, id, speed, NULL)

The backward compatibility version of SetTimerEx.

See also
SetTimerEx

Definition at line 7699 of file window.h.

Typedef Documentation

typedef BOOL(* TIMERPROC)(HWND, LINT, DWORD)

Type of the timer callback procedure.

This is the prototype of the callback procedure of a timer created by SetTimerEx. MiniGUI will call the timer procedure instead of sending MSG_TIMER message.

If the return value of a timer procedure is FALSE, the timer will be killed by MiniGUI automatically. This can be used to implement a one-shot timer.

See also
SetTimerEx
Note
The prototype had changed since MiniGUI v3.2; the old one: BOOL (* TIMERPROC)(HWND, int, unsigned int)

Definition at line 7652 of file window.h.

Function Documentation

DWORD GUIAPI GetTickCount ( void  )

Retrieves the tick counts that have elapsed since MiniGUI was started.

This function retrieves the tick counts that have elapsed since MiniGUI was started. It is limited to the resolution of the system timer, i.e. for a general Linux box, the returned tick count value is in unit of 10ms.

Returns
The tick counts value that have elapsed since MiniGUI was started.
Note
The prototype had changed since MiniGUI v3.2; The old one: unsinged int GUIAPI GetTickCount (void);
BOOL GUIAPI HaveFreeTimer ( void  )

Determines whether there is any free timer slot in the system.

This function determines whether there is any free timer slot in the system.

Returns
TRUE for yes, otherwise FALSE.
See also
IsTimerInstalled
BOOL GUIAPI IsTimerInstalled ( HWND  hWnd,
LINT  id 
)

Determines whether a timer is installed.

This function determines whether a timer with identifier id of a window hwnd has been installed.

Parameters
hWndThe window owns the timer.
idThe identifier of the timer.
Returns
TRUE for installed, otherwise FALSE.
See also
SetTimer, HaveFreeTimer
Note
The prototype had changed since MiniGUI v3.2; the old one: BOOL GUIAPI IsTimerInstalled (HWND hWnd, int id)
int GUIAPI KillTimer ( HWND  hWnd,
LINT  id 
)

Destroys a timer.

This function destroys the specified timer id.

Parameters
hWndThe window owns the timer.
idThe identifier of the timer. If id equals 0, this function will kill all timers in the system.
Returns
The number of actually killed timer.
See also
SetTimer
Note
The prototype had changed since MiniGUI v3.2; the old one: int GUIAPI KillTimer (HWND hWnd, int id)
BOOL GUIAPI ResetTimerEx ( HWND  hWnd,
LINT  id,
DWORD  speed,
TIMERPROC  timer_proc 
)

Adjusts a timer with a different timeout value or different timer callback procedure.

This function resets a timer with the specified timeout speed value.

Parameters
hWndThe window owns the timer.
idThe identifier of the timer.
speedThe new timeout value.
timer_procThe new timer callback procedure. If timer_proc is INV_PTR, the setting of timer callback procedure will not change.
Returns
TRUE on success, FALSE on error.
See also
SetTimerEx
Note
The prototype had changed since MiniGUI v3.2; the old one: BOOL GUIAPI ResetTimerEx (HWND hWnd, int id, unsigned int speed, TIMERPROC timer_proc)
BOOL GUIAPI SetTimerEx ( HWND  hWnd,
LINT  id,
DWORD  speed,
TIMERPROC  timer_proc 
)

Creates a timer with the specified timeout value.

This function creates a timer with the specified timeout value speed. Note that the timeout value is in unit of 10 ms. When the timer expires, an MSG_TIMER message will be send to the window hWnd if timer_proc is NULL, otherwise MiniGUI will call timer_proc by passing hWnd, id, and the tick count when this timer had expired to this callback procedure.

Parameters
hWndThe window receives the MSG_TIMER message. If timer_proc is not NULL, MiniGUI will call timer_proc instead sending MSG_TIMER message to this window. If you use timer callback procedure, hWnd can be any value you can pass.
idThe identifier of the timer, will be passed to the window with MSG_TIMER message as the first parameter of the message.
speedThe timeout value of the timer. Note that the timeout value is in unit of 10 ms.
timer_procThe timer callback procedure. If this argument is NULL, MiniGUI will send MSG_TIMER to the window procedure of hWnd.
Returns
TRUE on success, FALSE on error.
See also
SetTimer, ResetTimerEx, KillTimer, MSG_TIMER
Note
You should set, reset, and kill a timer in the same thread if your MiniGUI is configured as MiniGUI-Threads.
The prototype had changed since MiniGUI v3.2; the old one: BOOL GUIAPI SetTimerEx (HWND hWnd, int id, unsigned int speed, TIMERPROC timer_proc);

Example:

/*
* A typical handling of timer.
*/
LRESULT FlyingGUIWinProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) {
case MSG_CREATE:
/* create a timer which expires every 100 ms, and whose id is 100. */
#ifdef _MGTIMER_UNIT_10MS
SetTimer (hWnd, 100, 10);
#else
SetTimer (hWnd, 100, 100);
#endif
break;
/* handling the MSG_TIMER message. */
case MSG_TIMER:
if (wParam == 100) /* if it is the timer whose id is 100. */
break;
case MSG_CLOSE:
/* kill the timer whose id is 100. */
KillTimer (hWnd, 100);
return 0;
}
return DefaultMainWinProc(hWnd, message, wParam, lParam);
}