📄 createappui.cpp
字号:
/* 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -