FrmDoDialog was very attractive since it has it's own event loop to control its form. And, in fact, it usually works. The problem occurs when the other application has events still in the queue, specifically frmLoadEvent and frmOpenEvent. FrmDoDialog processes these other events, and gets hopelessly confused.
If you set up your own event handler for FrmDoDialog, you can do whatever you want with those events, including remove them from the queue.
When I use FrmDoDialog, I usually surround it with something like the following. It gives you pretty good control over what's going on. If you throw in some code to clear out the queue, it might get you what you need:
UInt16 UTDisplayDialog ( UInt16 dlgID, // ( in ) the ID of the dialog to do MemPtr dlHandler, // ( in ) pointer to an event handler void ( * initFunc ) () // ( in ) pointer to an initialization function )
FormActiveStateType curFrmState; FrmSaveActiveState ( &curFrmState ); FormPtr oldFrmP = FrmGetActiveForm (); UInt16 response;
// Check to make sure that the dialog resource ID doesn't conflict // with the resource ID of the currently active form.
UInt16 oldFrmID = FrmGetActiveFormID ();
ErrNonFatalDisplayIf ( oldFrmID == dlgID, "UTDisplayDialog: resource # conflict" );
// Don't let any events go to anyone else
FrmSetActiveForm ( NULL );
// Initialize the dialog
FormPtr frmP = FrmInitForm ( dlgID );
if ( frmP )
{// Draw the form and activate it
FrmSetActiveForm ( frmP );
FrmDrawForm ( frmP );// Set an event handler if one exists
if ( dlHandler )
{
FrmSetEventHandler ( frmP, ( FormEventHandlerType * ) dlHandler );
}
// Initialize any objects that need to be initialized
if ( initFunc )
{
initFunc ();
}// Do the dialog. Refetch the form pointer in case the initialization
// function added any dynamic objects to the form, invalidating the old pointer.
frmP = FrmGetFormPtr ( dlgID );
response = FrmDoDialog ( frmP );// Do the post processing. Get the pointer _again_ in case the // event handling does any dynamic object fiddling.
frmP = FrmGetFormPtr ( dlgID );
FrmEraseForm ( frmP );
FrmDeleteForm ( frmP );
}if ( oldFrmP )
{
FrmSetActiveForm ( oldFrmP );
}
FrmRestoreActiveState ( &curFrmState );# # # -- Regards, Steve Mann --- steve-at-slorevo.com Available for Contract Work
-- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
