>First of all ... Yes I want to change these texts at run-time.
>
>I'm well aware of the fact that you can change the window title with
>FrmSetTitle and change the button texts with CtlSetLabel (I do it all the
>time in my normal forms) but.... this requires me to have a FormPtr and I
>only have an Alert ID.
>
>Now how do I get from Alert ID to a FormPtr ?
>I've tried several things like GetFormPtr and passing the Alert ID instead
>of a Form ID but that doesn't seem to work.
>Maybe a code snippet would be helpfull ?
Sorry, I didn't think about the fact that alerts are inherently
modal. So off the top of my head, the easiest solution to dynamically
set alert buttons and titles is (ugly!) to patch FrmDoDialog(), which
gets called with the alert form pointer. Assuming this code is only
run when you've got globals, here's what you might do (danger!
untested code):
typedef UInt16 (FrmDoDialogProcPtr) (FormType* formP);
static FrmDoDialogProcPtr pOldFrmDoDialogProc = NULL;
static UInt16 MyFrmDoDialog(FormType* formP)
{
<set up form title & buttons>
return(pOldFrmDoDialogProc(formP));
} // MyFrmDoDialog
static void DoCustomizedAlert(UInt16 alertID)
{
// WARNING! Assumes you can access the pOldFrmDoDialogProc global.
pOldFrmDoDialogProc = SysGetTrapAddress(sysTrapFrmDoDialog);
SysSetTrapAddress(sysTrapFrmDoDialog, MyFrmDoDialog);
FrmAlert(alertID);
SysSetTrapAddress(sysTrapFrmDoDialog, pOldFrmDoDialogProc);
} // DoCustomizedAlert
Note that this hack relies on the fact that _currently_ the ROM calls
FrmDoDialog to actual display/handle an alert. If and when this
changes in the future, your code will no longer function properly. So
I'd still advise using the method of opening up one of a set of PRCs
that contain localized versions of the various alerts, versus trying
to set the title/buttons at run-time.
-- Ken
> > -----Original Message-----
> > From: Ken Krugler [mailto:[EMAIL PROTECTED]]
> > Sent: Thursday, August 17, 2000 17:31
> > To: [EMAIL PROTECTED]
> > Cc: [EMAIL PROTECTED]
> > Subject: Re: Change text on Alerts
> >
> >
> > At 12:00am -0700 00-08-17, Palm Developer Forum digest wrote:
> > >Subject: Change text on Alerts
> > >From: Rob Mermans <[EMAIL PROTECTED]>
> > >Date: Wed, 16 Aug 2000 10:44:56 +0200
> > >X-Message-Number: 180
> > >
> > >Hello,
> > >
> > >I'm working on an app that supports multi-language.
> >
> > Do you mean your app is localized into multiple languages, or you
> > have to be able to switch between languages at run-time? I'm assuming
> > the latter, otherwise it's just a build problem/resource file
> > management issue.
> >
> > >I'm using the default Alerts from Constructor and changing
> > the messages by
> > >using FrmCustomAlert and
> > >the ^1 ^2 ^3 trick. I also want to change the text on the
> > buttons and the
> > >text on the title of the alert.
> > >All this has to be done on the fly and I'd rather not make
> > all the alerts in
> > >all the languages.
> > >
> > >Any ideas on how to do this ?
> >
> > FrmSetTitle is the easy way to set the alert title. If you're OK with
> > having fixed width buttons, then you can call CtlSetLabel to change
> > the button text. Note that both of these calls "grab" the string
> > pointer you pass in, so you have to make sure the localized string
> > data sticks around for the duration of the alert.
> >
> > Another option is to have separate PRCs with contain the localizable
> > resources, one for each language. At launch time, open the
> > appropriate PRC based on the language the user has selected. This
> > adds the PRC to the top of the resource DB chain, so subsequent calls
> > to FrmCustomAlert (assuming you pass a valid resource ID) will work
> > just fine.
> >
> > -- Ken
> >
> > Ken Krugler
> > TransPac Software, Inc.
> > <http://www.transpac.com>
> > +1 530-470-9200
> >
Ken Krugler
TransPac Software, Inc.
<http://www.transpac.com>
+1 530-470-9200
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/