⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smsoperationview.cpp

📁 一个比较完整的有关移动开发的例子 vc++6.0下编译通过
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CSMSOperationView from CAknView
*  Part of  : SMSOperation
*  Copyright (c) 2003 Nokia. All rights reserved.
* ============================================================================
*/

// INCLUDE FILES
#include <aknviewappui.h>
#include <avkon.hrh>
#include <akncontext.h>	//for CAknContextPane
#include <akntitle.h>	//for CAknTitlePane
#include <aknnotewrappers.h> 
#include <eikmenup.h>		//for CEikMenuPane
#include <eikmenub.h>	// for CEikMenuBar


#include <FairyLand.rsg>
#include <FairyLand.mbg>	//for mbm
#include "FairyLand.hrh"
#include "FairyLandAppUi.h"
#include "SMSFunctionView.h"
#include "SMSOperationView.h"
#include "SMSOperationContainer.h" 
#include "MtmsEngine.h"


// ================= MEMBER FUNCTIONS =======================

// C++ default constructor can NOT contain any code, that
// might leave.
//
CSMSOperationView* CSMSOperationView::NewL()
{
    CSMSOperationView* self = NewLC();
    CleanupStack::Pop(self);
    return self;
}

CSMSOperationView* CSMSOperationView::NewLC()
{
    CSMSOperationView* self = new (ELeave) CSMSOperationView;
    CleanupStack::PushL(self);
    self->ConstructL();
    return self;
}

void CSMSOperationView::HandleMessageSentL(TInt aError)
{
}

CSMSOperationView::CSMSOperationView()
{
	m_nIndex=-1;
	m_nIsReply=0;
	m_nIsLookOver=0;
	m_pMtmsEngine = NULL;
}

// EPOC default constructor can leave.
void CSMSOperationView::ConstructL()
{
	// 	m_pMtmsEngine = CMtmsEngine::NewL(*this);
    BaseConstructL(R_SMSOPERATION_VIEW);
	//BaseConstructL();
}

// Destructor
CSMSOperationView::~CSMSOperationView()
{
	
}

void CSMSOperationView::SendSelectedIndex(const TInt aData)
{
	m_nIndex=aData;
}

void CSMSOperationView::SendEngine(CMtmsEngine* aMtmsEngine)
{
	m_pMtmsEngine=aMtmsEngine;
}

// ---------------------------------------------------------
// TUid CSMSOperationView::Id()
// Returns Id of the view.
// ---------------------------------------------------------
TUid CSMSOperationView::Id() const
{
    return KViewId14;
}


// ---------------------------------------------------------
// CSMSOperationView::HandleCommandL(TInt aCommand)
// Handles commands
// ---------------------------------------------------------
void CSMSOperationView::HandleCommandL(TInt aCommand)
{   
	switch(aCommand)
	{
	case EFairyLandCmdSend:
		{
			TBuf<11> Title;
			TBuf<70> Content;
			iContainer->GetTitle(Title);
			iContainer->GetContent(Content);
			if (Title.Length()==0)
			{
				TBuf<32> buf;
				CEikonEnv::Static( )->ReadResource( buf, R_QTN_IM_ADDRESS_NULL );
				CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
				informationNote->ExecuteLD(buf);
				break;
			}
			StartWaitDialogL();
			m_pMtmsEngine->CreateSMSMessageL(Title,Content);
			m_pMtmsEngine->ValidateCreatedSMS();
			m_pMtmsEngine->SendSMSL();
			if (iWaitDialog)
			{
				iWaitDialog->ProcessFinishedL(); // Deletes the dialog
				iWaitDialog = NULL;
			}
			AppUi()->ActivateLocalViewL(KViewId12);
		}
		break;
	case EFairyLandAddSendto:
		{
			//			AppUi()->ActivateLocalViewL(KViewId4);
		}
		break;
	case EFairyLandCmdHelp:
		{
			//			AppUi()->ActivateLocalViewL(KViewId4);
		}
		break;
	case EFairyLandReply:
		{
			m_nIsReply=1;
			TBuf<16> szAddress;
			TBuf<72> szContent;
			m_pMtmsEngine->GetAddress(m_nIndex,szAddress);
			szContent.Zero();
			iContainer->SetText(szAddress,szContent);
			m_nIsLookOver=0;
		}
		break;	
	case EFairyLandBack:
		{
			
			TBuf<16> Address;//输入的信息
			TBuf<70> Content;
			iContainer->GetTitle(Address);
			iContainer->GetContent(Content);
			if (m_nIndex>=0&&m_nIsReply==0)//非直接写信息部分
			{
				TBuf<16> szAddress;//原来的信息
				TBuf<70> szContent;
				m_pMtmsEngine->GetAddress(m_nIndex,szAddress);
				m_pMtmsEngine->GetContent(m_nIndex,szContent);
				if ((Address.Compare(szAddress)==0)&&(Content.Compare(szContent)==0))//进来时有内容且没有被修改过
				{
					AppUi()->ActivateLocalViewL(KViewId12);
					break;
				}
				else if (Address.Length()==0&&Content.Length()==0)//用户清空所有信息退出时删除信息
				{
					TBuf<32> message;
					CEikonEnv::Static()->ReadResource(message, R_QTN_IM_SMS_DEL_ALREADY);
					CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
					informationNote->ExecuteLD(message);
					m_pMtmsEngine->DeleteMessageL(m_nIndex);
					AppUi()->ActivateLocalViewL(KViewId12);
					break;
				}
				else//用户修改信息
				{
					TBuf<32> sTmpTitle;//define a descriptor for read resource of title
					CEikonEnv::Static()->ReadResource(sTmpTitle, R_QTN_IM_SAVE_YN);
					if (MessageBoxByYesNO(sTmpTitle))
					{
						m_pMtmsEngine->DeleteMessageL(m_nIndex);
						m_pMtmsEngine->CreateSMSMessageL(Address,Content);
					}
					AppUi()->ActivateLocalViewL(KViewId12);
					break;
				}
			}
			if (Address.Length()==0&&Content.Length()==0)//用户没有填写信息退出
			{
				AppUi()->ActivateLocalViewL(KViewId12);
				break;
			}
			else//用户写好信息退出
			{
				TBuf<32> sTmpTitle;//define a descriptor for read resource of title
				CEikonEnv::Static()->ReadResource(sTmpTitle, R_QTN_IM_SAVE_YN);
				if (MessageBoxByYesNO(sTmpTitle))
				{
					m_pMtmsEngine->CreateSMSMessageL(Address,Content);
				}
				AppUi()->ActivateLocalViewL(KViewId12);
			}
		}
		break;
	default:
		{
			AppUi()->HandleCommandL(aCommand);
			break;
		}
	}
}
// ---------------------------------------------------------
// CSMSOperationView::HandleClientRectChange()
// Handles client rect change.
// ---------------------------------------------------------
void CSMSOperationView::HandleClientRectChange()
{
    if (iContainer)
	{
        iContainer->SetRect(ClientRect());
	}
}

// ---------------------------------------------------------
// CSMSOperationView::DoActivateL(...)
// Creates the Container class object.
// ---------------------------------------------------------
void CSMSOperationView::DoActivateL(const TVwsViewId& /*aPrevViewId*/,
									TUid /*aCustomMessageId*/,
									const TDesC8& aCustomMessage)
{
    iContainer = new (ELeave) CSMSOperationContainer;
    iContainer->SetMopParent(this);
	
	TRect rc;
	rc.SetRect(ClientRect().iTl, TSize(176, 144));
    iContainer->ConstructL(rc);
	TBuf8<6> buf,buf1;
	buf.Copy(_L("reply"));
	buf1.Copy(_L("inbox"));
	if (m_nIndex>=0&&(aCustomMessage.Compare(buf)!=0)&&(aCustomMessage.Compare(buf1)!=0))//选中的信息不是回复也不是从收件箱过来的
	{
		TBuf<16> szAddress;
		TBuf<72> szContent;
		m_pMtmsEngine->GetAddress(m_nIndex,szAddress);
		m_pMtmsEngine->GetContent(m_nIndex,szContent);
		iContainer->SetText(szAddress,szContent);
	}
	else if (m_nIndex>=0&&(aCustomMessage.Compare(buf)==0))//选中的信息是回复
	{
		m_nIsReply=1;
		TBuf<16> szAddress;
		TBuf<72> szContent;
		m_pMtmsEngine->GetAddress(m_nIndex,szAddress);
		szContent.Zero();
		iContainer->SetText(szAddress,szContent);
	}else if (m_nIndex>=0&&aCustomMessage.Compare(buf1)==0)//选中的信息是收件箱的查看
	{
		m_nIsLookOver=1;
		TBuf<16> szAddress;
		TBuf<72> szContent;
		m_pMtmsEngine->GetAddress(m_nIndex,szAddress);
		m_pMtmsEngine->GetContent(m_nIndex,szContent);
		iContainer->SetfixedText(szAddress,szContent);
	}
    AppUi()->AddToStackL(*this, iContainer);
	
	
	//	TBuf<KMaxPath> pathMbm;
	//#ifdef __WINS__
	//	pathMbm.Copy(_L("z:\\system\\apps\\FairyLand\\FairyLand.mbm"));
	//#else
	//	CFairyLandAppUi* pApp = (CFairyLandAppUi*)CEikonEnv::Static()->AppUi();
	//	pApp->GetAppPath(pathMbm);
	//	pathMbm.Append(_L("FairyLand.mbm"));
	//#endif
	
	CEikStatusPane* statusPane = StatusPane();
	
	//set icon
	//	CAknContextPane* contextPane = (CAknContextPane*) statusPane->ControlL(TUid::Uid(EEikStatusPaneUidContext));
	//	CFbsBitmap* bitmap = iEikonEnv->CreateBitmapL(pathMbm, EMbmFairylandSMSOperation);
	//	CFbsBitmap* bitmapMask = iEikonEnv->CreateBitmapL(pathMbm, EMbmFairylandSMSOperation_mask);
	
	//contextPane->SetPicture(bitmap);
	//	contextPane->SetPicture(bitmap, bitmapMask);
	
	//set title
	// CAknTitlePane* titlePane = (CAknTitlePane*) statusPane->ControlL(TUid::Uid(EEikStatusPaneUidTitle));
	// titlePane->SetTextL(_L("Hello view!"));
	
	//load chinese words
	TBuf<32> sTmpTitle;
	CEikonEnv::Static()->ReadResource(sTmpTitle, R_QTN_SMSOPERATION_VIEW);
	
	CAknTitlePane* titlePane = (CAknTitlePane*) statusPane->ControlL(TUid::Uid(EEikStatusPaneUidTitle));
	titlePane->SetTextL(sTmpTitle);
	
	//show
	// 	CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
	// 	informationNote->ExecuteLD(sTmpTitle);
}

// ---------------------------------------------------------
// CSMSOperationView::DoDeactivate()
// Deletes the Container class object.
// ---------------------------------------------------------
void CSMSOperationView::DoDeactivate()
{
    if (iContainer)
	{
		m_nIndex=-1;//获得的选择序号必须初始化,否则下回写信息进入时显示原选择序号的内容
		m_nIsReply=0;
		m_nIsLookOver=0;
        AppUi()->RemoveFromStack(iContainer);
		delete iContainer;
		iContainer = NULL;
	}
}

void CSMSOperationView::StartWaitDialogL()
{
    if (iWaitDialog)
    {
        delete iWaitDialog;
        iWaitDialog = NULL;
    }
    iWaitDialog = new (ELeave) CAknWaitDialog((REINTERPRET_CAST(CEikDialog**, &iWaitDialog)), ETrue);
    iWaitDialog->SetTone(CAknNoteDialog::EConfirmationTone);
    iWaitDialog->ExecuteLD(R_FAIRYLAND_WAIT_NOTE); 
}

TInt CSMSOperationView::MessageBoxByYesNO(const TDesC& aMes)
{
	CAknQueryDialog* pDlog = new(ELeave)CAknQueryDialog;
	pDlog->PrepareLC(R_SMSIB_QUERY);//显示messagebox
	pDlog->SetPromptL(aMes);
	return pDlog->RunLD();
}


void CSMSOperationView::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane)
{
	if(aResourceId != R_MH_SMSOPERATION_MENU)
	{
		return;
	}
	switch(m_nIsLookOver)
	{
	case 0:
		{
			aMenuPane->SetItemDimmed(EFairyLandCmdSend, EFalse);
			aMenuPane->SetItemDimmed(EFairyLandAddSendto, EFalse);
			aMenuPane->SetItemDimmed(EFairyLandCmdHelp, EFalse);
			aMenuPane->SetItemDimmed(EFairyLandReply, ETrue);
            break;
		}
	case 1:
		{
			aMenuPane->SetItemDimmed(EFairyLandCmdSend, ETrue);
			aMenuPane->SetItemDimmed(EFairyLandAddSendto, ETrue);
			aMenuPane->SetItemDimmed(EFairyLandCmdHelp, ETrue);
			aMenuPane->SetItemDimmed(EFairyLandReply, EFalse);
			break;
		}
	default:
		{
			break;
		}
	}
}

⌨️ 快捷键说明

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