×
Namespaces

Variants
Actions

在view中发送自定义消息

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

文章
hoolee 在 04 Jun 2008 创建
最后由 hamishwillee 在 15 Dec 2011 编辑

CS000970


  • 开发伙伴平台:

S60 3rd Edition, MR


  • 详细描述

下列示例代码显示了当激活view时如何从CAknView向另一个CAknView发送自定义消息


Contents

MMP

需要下列能力和库

CAPABILITY        NONE
LIBRARY avkon.lib


头文件,发送自定义消息

#include <aknview.h>
const TUid KView1Id = {1};
const TUid KView2Id = {2};
const TUid KCustomMessageUid= {2}; // Your custom message uid
 
public:
void CFirstView::HandleCommandL(TInt aCommand);


源文件,发送自定义消息

void CFirstView::HandleCommandL(TInt aCommand)
{
switch ( aCommand )
{
case EOpenSecondView:
{
// Switch to view 2 and send a message Uid and a message
 
// Construct a message to send
TBuf8<255> customMessage;
customMessage.Copy(_L8("Message from firsto view"));
 
// Activate the second view and give the message as a parameter
AppUi()->ActivateLocalViewL(KView2Id, KCustomMessageUid, customMessage);
break;
}
}
default:
{
break;
}


头文件,接收自定义消息

#include <aknview.h>
#include "CFirstView.h"
 
public:
void CSecondView::DoActivateL(const TVwsViewId& aPrevViewId,
TUid aCustomMessageId, const TDesC8& aCustomMessage);
 
private:
HBufC8* iReceivedMessage;


源文件,接收自定义消息

void CSecondView::DoActivateL(const TVwsViewId& aPrevViewId,
TUid aCustomMessageId, const TDesC8& aCustomMessage)
{
// Create Container
if (!iContainer)
{
iContainer = new (ELeave) CMyViewContainer2;
iContainer->ConstructL( ClientRect() );
AppUi()->AddToStackL( *this, iContainer );
}
 
 
// 1. Check aCustomMessageId to handle aCustomMessage
// 2. You could check aPrevViewId if you were curious to know
// from where this view was called from.
if (aCustomMessageId==KCustomMessageUid)
{
// TODO: Do something with aCustomMessage
iReceivedMessage = aCustomMessage.AllocL();
}
}
This page was last modified on 15 December 2011, at 09:32.
53 page views in the last 30 days.
×