symbian 推荐好友的功能实现

来源:互联网 发布:wps数据有效性怎么添加 编辑:程序博客网 时间:2024/05/01 09:59

消息引擎--推荐好友的添加

(使用的是系统的消息的引擎)

一.首先在已有的工程下添加“推荐好友”的选项

步骤如下:以工程BlueEyes为例:

1)在 .hrh文件中添加枚举值

enum TBlueEyesIds

       {

       ECommand1 = 0x6001, // start value must not be 0

       ECommand2,

       EHelp,

       EAbout,

    ERecommend     //推荐好友    2010-4-12

       };

2)在 .rls文件中添加宏定义

#define qtn_recommend "recommend Friend"

(如果是添加中文则是在 _cn.src中添加宏定义)

3)在 .rss文件中添加菜单项

MENU_ITEM

       {

       command = ERecommend;

       txt = qtn_recommend;

       }, 

然后添加资源

//推荐好友     2010-4-12

RESOURCE TBUF32 r_global_message {buf = "This is My Friend";}

 

二.在AppUI.h添加系统的发送消息类的指针

////推荐好友     2010-4-12

   //Required capabilities:   此例必须添加的能力

   //LocalServices, NetworkServices, ReadDeviceData, WriteDeviceData, ReadUserData, WriteUserData

   CSendUi * iSendUi;       //Link against: sendui.lib

然后添加头文件

//推荐好友     2010-4-12

#include <sendui.h>

#include <cmessagedata.h>

#include <TXTRICH.H>

#include <senduiconsts.h>

添加创建和发送消息的函数

    //推荐好友     2010-4-12

    void   CreateAndSendMessageL(); //使用CSendAppUi类创建和发送消息

三.在AppUI.Cpp中添加函数的实现

1)首先在二段构造函数ConstructL()中创建指针

void CBlueEyesAppUi::ConstructL()

    {

 

    BaseConstructL(EAknEnableSkin);

   

    //推荐好友      2010-4-12

    iSendUi = CSendUi::NewL();

}

2)并在析构函数中释放指针

//推荐好友      2010-4-12

    if (iSendUi)

       {

       delete iSendUi;

       iSendUi = NULL;

       }

3)在消息响应函数HandleCommandL(TInt aCommand)中添加如下代码,当点击菜单项Erecommend的时候有响应的信息

//推荐好友      2010-4-12

       case ERecommend:

           {

           CreateAndSendMessageL();

           break;

           }  

4)实现CreateAndSendMessageL()函数

//推荐好友      2010-4-12

void CBlueEyesAppUi::CreateAndSendMessageL()

    {

    //创建一个空消息

    CMessageData* message = CMessageData::NewLC();

    //etext.lib

    CParaFormatLayer* paraFormatLayer = CParaFormatLayer::NewL(); //etext.lib

    CleanupStack::PushL(paraFormatLayer);

    CCharFormatLayer* charFormatLayer = CCharFormatLayer::NewL();

    CleanupStack::PushL(charFormatLayer);

 

    CRichText* messageBodyContent = CRichText::NewL(paraFormatLayer,

           charFormatLayer);

    CleanupStack::PushL(messageBodyContent);

 

    //预先给消息预置一个初始的正文

    HBufC* string = StringLoader::LoadLC(R_GLOBAL_MESSAGE);

    messageBodyContent->InsertL(0, *string);

 

    message->SetBodyTextL(messageBodyContent);

 

    //通过SendUi调用消息编辑器 CMessageData*

    iSendUi->CreateAndSendMessageL(KSenduiMtmSmsUid, message, KNullUid);

    CleanupStack::PopAndDestroy(5);

    }

编译运行 程序运行图