Join Now

Hi, I'm Paul, but you can also call me Todd and I won't get upset.

Creating links in a message box

Paul.Todd | 25 October, 2006 19:06

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.

Dialog with Link

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!

Comments

Re: Creating links in a message box

cool_li | 28/10/2006, 06:29

cool_li Oh, that's so cool, Please give me the source for this article.
my e-mail: n-office@163.com

Re: Creating links in a message box

jintian2005 | 06/05/2007, 13:09

it is nice!
Please give me the source for this article too!thanks very much!
my e-mail: jintian_OK@tom.com

gammav

gammav | 26/06/2008, 11:19

Adding setlink results in USER 130 panic. help

fixed

gammav | 26/06/2008, 11:29

Fixed, it panics if linktext is not found in message. This should be fixed by Symbian

You must login to post comments. Login
 
 
Powered by LifeType
     
     RDF Facets:
     
     
     qfnZtopicQUqfnTopicZcppQ
     qfnZtopicQUqfnTopicZseriesE5f60Q
     qfnZtypeQUqfnTypeZBlogContentQ
     qfnZtypeQUqfnTypeZBlogE45ntryQ
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX