| helloworld.c |
|---|
| // Include Palm prototypes, variables etc. #include <System/SysAll.h> // Entry point for palm applications DWord PilotMain(Word cmd, Ptr cmdPBP, Word launchFlags) { // Variable declarations EventType event; // Check the launch code if (cmd == sysAppLaunchCmdNormalLaunch) { // Write hello world to the screen WinDrawChars("Hello world!", 12, 20, 50); do { // Wait until something happens EvtGetEvent(&event, evtWaitForever); // Let the system handle the event SysHandleEvent(&event); // Quit if we have received an appStopEvent } while (event.eType != appStopEvent); } // cmd == sysAppLaunchCmdNormalLaunch return; } // PilotMain |
Then PilotMain is implemented. PilotMain is the entry point of a Palm application. This can be compared with the main in a usual C program. The implementation of PilotMain starts with the declaration of the variables used in the function.
The PilotMain function can be called in different ways. Usually you will start them from the Application Launcher, but if you use the find option, the PilotMain function is also called. Depending on how the PilotMain function is called, you want to preform different actions. With the cmd variable you can check how the function is called. We only want to do something if the application is normally started, that is checked with the cmd == sysAppLaunchCmdNormalLaunch statement. The program only execute it's usefull code if this statement is true, else the program just exits.
Puting text on the screen is not done with the well known C-function; printf, but with the WinDrawChar function. WinDrawChars("Hello world!", 12, 20, 50); Draws the string of 12 characters: Hello world! on the position 20, 50 on the screen.
The Palm OS is an event based system. Which means that events get generated an handeled by the program. The function EvtGetEvent(&event, evtWaitForever); waits until an event occurs. The system has the possibility to handle that event with the SysHandleEvent(&event); statement. Usualy the programs have also statements so the program can interact with the events itself. This program has nothing to do, so there is also no code.
The program keeps handling events until it gets the command to stop. while (event.eType != appStopEvent); takes care of that.
Finally the function returns.
|
Toni Cornelissen 13 September 2004 toni@dse.nl |
Daily horoscope |