createappui.cpp

来自「symbian 可在收件箱生成5000字超长短信!」· C++ 代码 · 共 146 行

CPP
146
字号
/* Copyright (c) 2008, Nokia. All rights reserved */

#include <avkon.hrh>
#include <aknnotewrappers.h> 
#include <mtclreg.h>
#include <SMSCLNT.h>
#include <msvapi.h>
#include <txtrich.h>
#include <SMUTHDR.h>

#include <smut.h>
#include "Create.pan"
#include "CreateAppUi.h"
#include "CreateAppView.h"
#include "Create.hrh"

void CCreateAppUi::ConstructL()
    {
    BaseConstructL(EAknEnableSkin);

    iAppView = CCreateAppView::NewL(ClientRect());    
    AddToStackL(iAppView);
    }

CCreateAppUi::CCreateAppUi()                              
    {
    // add any construction that cannot leave here
    }

CCreateAppUi::~CCreateAppUi()
    {
    if (iAppView)
        {
        iEikonEnv->RemoveFromStack(iAppView);
        delete iAppView;
        iAppView = NULL;
        }
    }

void CCreateAppUi::HandleCommandL(TInt aCommand)
    {
    switch(aCommand)
        {
        case EEikCmdExit:
        case EAknSoftkeyExit:
            Exit();
            break;
        case ECreateCommand1:
            {
                CreateInboxMsg();
            }
            break;
        default:
            Panic(ECreateBasicUi);
            break;
        }
    }

void CCreateAppUi::CreateInboxMsg()
{
    _LIT(KAddress,"13300135000"); 
    _LIT(KName,"linxin");

    CMsvSession* iSession;
    iSession = CMsvSession::OpenSyncL(*this);

    CClientMtmRegistry* iClientMtmRegistry=CClientMtmRegistry::NewL(*iSession); 
    CleanupStack::PushL(iClientMtmRegistry);
    
    CSmsClientMtm* iSmsClientMtm=(CSmsClientMtm *)iClientMtmRegistry->NewMtmL(KUidMsgTypeSMS); 
    CleanupStack::PushL(iSmsClientMtm); 

    iSmsClientMtm->SwitchCurrentEntryL(KMsvGlobalInBoxIndexEntryId); 

    TMsvEntry indexEntry; 

    indexEntry.SetInPreparation(EFalse); 

    indexEntry.iMtm = KUidMsgTypeSMS; 

    indexEntry.iType = KUidMsvMessageEntry; 

    indexEntry.iServiceId = iSmsClientMtm->ServiceId(); 

    TTime nowTime;
    nowTime.HomeTime();

    //设置收到的时间
    indexEntry.iDate=nowTime; 

    //设置发件人姓名
    indexEntry.iDetails.Set(KName); 

    _LIT(KSMSBody,"MY first sms!"); 
    indexEntry.iDescription.Set(KSMSBody); 

    indexEntry.SetUnread(ETrue); 
    indexEntry.SetVisible(ETrue);

    iSmsClientMtm->Entry().CreateL(indexEntry); 

    TMsvId iSmsId = indexEntry.Id(); 

    iSmsClientMtm->SwitchCurrentEntryL(iSmsId); 

    CRichText& body = iSmsClientMtm->Body();

    body.Reset(); 

    body.InsertL(0, KSMSBody); 

    iSmsClientMtm->AddAddresseeL(KAddress,KName); 

    iSmsClientMtm->SaveMessageL(); 

    CMsvStore* messageStore = iSmsClientMtm->Entry().EditStoreL();
    CleanupStack::PushL( messageStore );

    CSmsHeader* hdr = CSmsHeader::NewL( CSmsPDU::ESmsDeliver, body );
    CleanupStack::PushL( hdr );

    hdr->SetFromAddressL(KAddress);

    hdr->Deliver().SetServiceCenterTimeStamp(nowTime);

    hdr->StoreL(*messageStore);       

    messageStore->CommitL();

    CleanupStack::PopAndDestroy(hdr);     

    CleanupStack::PopAndDestroy(messageStore);

    // 修改当前消息索引为只读,这样收件箱列表处浏览会有回复选项

    //但是如果在之前就设置ReadOnly就会导致SaveMessageL出错  
    indexEntry.SetReadOnly(ETrue);
    //消息索引提交更改
    iSmsClientMtm->Entry().ChangeL(indexEntry); 

    CleanupStack::PopAndDestroy(2); 

    delete iSession;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?