Application Code for Menus
There’s not a lot of code that needs to be added to support menus. Further, what you do add is straightforward and in some cases standard from application to application. The three routines that have some responsibility for handling menus are:
MenuHandleEvent
MyFormHandleEvent
MyFormHandleMenuEvent
There is some cookbook code to add that handles the Edit menu, and we need to handle the About menu, as well.
MenuHandleEvent
This routine is responsible for handling menu-specific events. Chapter 4, contains a description of MenuHandleEvent and its role within your main event loop. Here is an example found in a main event loop:
do {
EvtGetEvent(&event, evtWaitForever);
if (! SysHandleEvent(&event))
if (! MenuHandleEvent(0, &event, &error))
if (! ApplicationHandleEvent(&event))
FrmDispatchEvent(&event);
} while (event.eType != appStopEvent);
MyFormHandleEvent
Your
form’s event handler receives an event of type
menuEvent
if a menu item is chosen. If you have
more than one or two menu items handled by a form, it is customary to
put the menu item dispatching in a separate routine,
MyFormHandleMenuEvent. Here is our event
handler:
static Boolean MyFormHandleEvent(EventPtr event) { Boolean handled = false; #ifdef __GNUC__ CALLBACK_PROLOGUE #endif switch (event->eType) { /* code removed */ case menuEvent: handled = MyFormHandleMenuEvent(event->data.menu.itemID); break; /* code removed */ } #ifdef __GNUC__ CALLBACK_EPILOGUE #endif return handled; }
MyFormHandleMenuEvent ...
Get Palm Programming: The Developer's Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.