Todays topic is using CAknMessageQueryDialog to build popout links. It is really easy to provide a customized "more info" link embedded in your text. This is the same technique that the licence dialog uses.
For each link in the string we can provide a callback that will be called when the user moves the cursor over it and selects it.
One note: The factory function seems to be broken, the string parameter should have been const TDesC& but it has instead been declared as TDesC& - Doh! This means it needs a cast to work with LIT and other types when using NewL
So the first thing we do is construct our message dialog. Because I did'nt want to complicate things I am using the default resource as defined by AVKON.
So lets setup the strings: IRL we would use resources and StringLoader
_LIT(KHeader, "Example Link Box");
_LIT(KLink1, "Link 1");
_LIT(KLink2, "Link 2");
_LIT(KMessageboxText, "Click here for Link 1nhere for Link 2");
//Now we can setup the bits of the message box -
NB note the cast in the NewL
void ShowLinkedMessageBox()
{
CAknMessageQueryDialog* dialog = CAknMessageQueryDialog::NewL(CONST_CAST(TDesC&, KMessageboxText()));
CleanupStack::PushL(dialog);
dialog->SetHeaderText(KHeader);
// Now setup the text that will be linked and the action to be performed when they are selected.
TCallBack callback1(CallbackText1);
dialog->SetLink(callback1);
dialog->SetLinkTextL(KLink1);
TCallBack callback2(CallbackText2);
dialog->SetLink(callback2);
dialog->SetLinkTextL(KLink2);
// Finally as its now leave-safe pop the dialog and run it
CleanupStack::Pop(dialog);
dialog->ExecuteLD(R_AVKON_MESSAGE_QUERY_DIALOG);
}
Here are the two callback functions
LOCAL_C TInt CallbackText1(TAny* /*aAny*/)
{
CAknInformationNote* msg = new (ELeave) CAknInformationNote(ETrue);
msg->ExecuteLD(_L("You clicked the first link"));
return EFalse;
}
LOCAL_C TInt CallbackText2(TAny* /*aAny*/)
{
CAknInformationNote* msg = new (ELeave) CAknInformationNote(ETrue);
msg->ExecuteLD(_L("You clicked the second link"));
return EFalse;
}
Pretty simple for such a cool effect?
You now make it simpler by reading the documentation you can specify the link text by enclosing it between <AknMessageQuery Link> and </AknMessageQuery Link>
Then you only need to call setLink for each instance.
Email me (
paul@toddsoftware.com) if you want the source for this as I hav'nt figured out how to upload zip files yet!
.
Re: Creating links in a message box
cool_li | 28/10/2006, 06:29
my e-mail: n-office@163.com