62 Building applications — Coding an application
Developer’s Guide – RIM 950 Wireless Handheld™
To set up a basic program structure
1. Implement a message loop:
Any application running on the device will need to handle messages
from the OS that will notify the application of key presses, radio
events, etc. The most efficient process is to do this is to use a message
loop.
The basic structure of the message loop is:
for(;;){
// waits until a message is given
// to the application by the OS
RimGetMessage (&message);
// processes message
}
2. An application that wishes to display data on the device’s LCD
screen must first become the foreground task.
In this example, the application should be brought to the foreground
if the user activates the application by selecting an icon on the main
screen. When the user selects the icon, the OS sends a MESSAGE to the
application from the RIBBON device, with the event set to
RIBBON_GRAB_FOREGROUND. If we get a RIBBON message, we call
RimGetCurrentTaskID() for the current task ha ndle. We bring the
application to the foreground using RimRequestForeground().
if( message.Device == DEVICE_RIBBON ) {
if( message.Event == RIBBON_GRAB_FOREGROUND ) {
// Bring this application to the foreground
// so it can use the LCD
RimRequestForeground(RimGetCurrentTaskID());
}
}
3. If the user presses a key, the OS sends a MESSAGE to the application
from the KEYPAD device. If we get a KEYPAD message, we pass the
MESSAGE to the UI Engine, which returns a result code:
if( message.Device == DEVICE_KEYPAD ) {
// Let the UI process the message
result = m_ui_engine.HandleInput( message );
//Process UI Engine result
}