Line-by-line Anatomy of Hello.c
(Cont.)
EvtGetEvent( &event, evtWaitForever );
An event is a software message that indicates something has happened.
- Traditional programs follow their own control flow pattern, only sometimes changing course at branch points.
- Event-driven programs are preprogrammed with an event loop, to look repeatedly for information to process (for example, a keyboard or mouse operation) and then perform a trigger function to process it.
The function void EvtGetEvent( EventType *event, Int32 timeout ) returns the next available event.
- event:
Pointer to the structure to hold the event returned.
- timeout:
Maximum number of ticks to wait before an event is returned (
evtWaitForever
means wait indefinitely).
Pass evtWaitForever
as the timeout in most instances.
When running on the device, this makes the CPU go into doze mode until the user provides input.
SysHandleEvent( &event );
The function Boolean SysHandleEvent( EventPtr eventP ) handle defaults for system events such as hard and soft key presses.
It returns true
if the system handled the event.
Applications should call this routine immediately after calling EvtGetEvent( ).
eventP:
Pointer to an event.
} while ( event.eType != appStopEvent );
When the system wants to launch a different application than the one currently running, the event manager sends this event to request the current application to terminate by using the event reference appStopEvent.
In response, an application has to exit its event loop, close any open files and forms, and exit.