testmenuappui.cpp
来自「symbianOS第三版开发与实用教程部分源码和部分试验」· C++ 代码 · 共 201 行
CPP
201 行
/*
============================================================================
Name : TestMenuAppUi.cpp
Author : Lion
Copyright : Your copyright notice
Description : CTestMenuAppUi implementation
============================================================================
*/
// INCLUDE FILES
#include <avkon.hrh>
#include <aknnotewrappers.h>
#include <stringloader.h>
#include <TestMenu.rsg>
#include <f32file.h>
#include <s32file.h>
#include <eikmenup.h>
#include "TestMenu.pan"
#include "TestMenuAppUi.h"
#include "TestMenuAppView.h"
#include "TestMenu.hrh"
_LIT( KFileName, "C:\\private\\05DED654\\TestMenu.txt" );
_LIT( KText, "Hello World!");
// ============================ MEMBER FUNCTIONS ===============================
// -----------------------------------------------------------------------------
// CTestMenuAppUi::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CTestMenuAppUi::ConstructL()
{
// Initialise app UI with standard value.
BaseConstructL();
// Create view object
iAppView = CTestMenuAppView::NewL( ClientRect() );
iState = EMain;
// Create a file to write the text to
RFs fsSession;
User::LeaveIfError(fsSession.Connect());
CleanupClosePushL( fsSession );
TInt err = fsSession.MkDirAll(KFileName);
if ( KErrNone != err )
{
CleanupStack::PopAndDestroy(1); // fsSession
return;
}
RFile file;
err = file.Replace(fsSession, KFileName, EFileWrite );
CleanupClosePushL( file );
if ( KErrNone != err )
{
CleanupStack::PopAndDestroy(2); // file, fsSession
return;
}
RFileWriteStream outputFileStream( file );
CleanupClosePushL( outputFileStream );
outputFileStream << KText;
CleanupStack::PopAndDestroy(3); // outputFileStream, file, fsSession
}
// -----------------------------------------------------------------------------
// CTestMenuAppUi::CTestMenuAppUi()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CTestMenuAppUi::CTestMenuAppUi()
{
// No implementation required
}
// -----------------------------------------------------------------------------
// CTestMenuAppUi::~CTestMenuAppUi()
// Destructor.
// -----------------------------------------------------------------------------
//
CTestMenuAppUi::~CTestMenuAppUi()
{
if ( iAppView )
{
delete iAppView;
iAppView = NULL;
}
}
// -----------------------------------------------------------------------------
// CTestMenuAppUi::HandleCommandL()
// Takes care of command handling.
// -----------------------------------------------------------------------------
//
void CTestMenuAppUi::HandleCommandL( TInt aCommand )
{
switch( aCommand )
{
case EExampleCmdExit:
{
if (iState == EAdd)
{
iState = EMain;
}
else if (iState == EMain)
{
Exit();
}
}
break;
case EAknSoftkeyExit:
Exit();
break;
case EExampleCmdAddMessage:
{
iState = EAdd;
// CAknInformationNote* informationNote;
//
// informationNote = new ( ELeave ) CAknInformationNote;
// Show the information Note with
// textResource loaded with StringLoader.
// informationNote->ExecuteLD( *textResource);
}
break;
case EExampleCmdAddEmail:
{
iState = EAdd;
}
break;
case EExampleCmdEdit:
{
}
break;
case EExampleCmdDel:
{
}
break;
case EExampleCmdOk:
{
iState = EMain;
CAknInformationNote* note = new (ELeave) CAknInformationNote;
note->ExecuteLD(_L("Operation Finished!"));
}
break;
default:
//Panic( ETestMenuUi );
break;
}
}
// -----------------------------------------------------------------------------
// Called by the framework when the application status pane
// size is changed. Passes the new client rectangle to the
// AppView
// -----------------------------------------------------------------------------
//
void CTestMenuAppUi::HandleStatusPaneSizeChange()
{
iAppView->SetRect( ClientRect() );
}
void CTestMenuAppUi::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane)
{
if (R_EXAMPLE_MENUPANE == aResourceId)
{
if (EMain == iState)
{
aMenuPane->SetItemDimmed(EExampleCmdAdd, EFalse);
aMenuPane->SetItemDimmed(EExampleCmdEdit, EFalse);
aMenuPane->SetItemDimmed(EExampleCmdDel, EFalse);
aMenuPane->SetItemDimmed(EExampleCmdOk, ETrue);
aMenuPane->SetItemTextL(EExampleCmdExit,_L("Exit"));
}
else if (EAdd == iState)
{
aMenuPane->SetItemDimmed(EExampleCmdAdd, ETrue);
aMenuPane->SetItemDimmed(EExampleCmdEdit, ETrue);
aMenuPane->SetItemDimmed(EExampleCmdDel, ETrue);
aMenuPane->SetItemDimmed(EExampleCmdOk, EFalse);
aMenuPane->SetItemTextL(EExampleCmdExit,_L("Cancel"));
}
}
}
// End of File
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?