今天翻译一篇Forum Nokia Blogs上的文章。
这篇文章使用CAknMessageQueryDialog 来创建突出的链接。通过它你可以相当简单在你的文字中的提供一个“更多”链接。同样这种技术也可以在许可对话框中使用。
当用户将光标移动到上面并选择它的时候,我们可以为每个需要链接的字符串提供一个回调函数。
注意:工厂函数貌似被破坏,字符串参数是const TDesC&,但它已经被替换成TDesC&,这意味着当使用NewL的时候需要使用LIT
那么我们要作的第一件事情是构造消息对话框。为了简单起见,我们使用了默认的资源。
让我们来设置字符串: 我们将用资源和 StringLoader
_LIT(KHeader, "Example Link Box"); _LIT(KLink1, "Link 1"); _LIT(KLink2, "Link 2"); _LIT(KMessageboxText, "Click here for Link 1\nhere 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); } 这里有两个回调函数:
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; } 是不是非常简单的实现了一个很酷的效果?
作者邮箱:paul@toddsoftware.com
源代码下载
译文出处:http://www.symbianx.cn/viewthread.php?tid=72&extra=page%3D1 |