📄 helloappui.cpp
字号:
/*
============================================================================
Name : HelloAppUi.cpp
Author : Lion
Copyright : Your copyright notice
Description : CHelloAppUi implementation
============================================================================
*/
// INCLUDE FILES
#include <avkon.hrh>
#include <aknnotewrappers.h>
#include <stringloader.h>
#include <Hello.rsg>
#include <f32file.h>
#include <s32file.h>
#include "Hello.pan"
#include "HelloAppUi.h"
#include "HelloAppContainer.h"
#include "Hello.hrh"
_LIT( KFileName, "C:\\private\\0735B4AC\\Hello.txt" );
_LIT( KText, "Hello World!");
// ============================ MEMBER FUNCTIONS ===============================
// -----------------------------------------------------------------------------
// CHelloAppUi::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CHelloAppUi::ConstructL()
{
// Initialise app UI with standard value.
BaseConstructL();
// Create view object
iAppContainer = CHelloAppContainer::NewL( ClientRect() );
// 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
}
// -----------------------------------------------------------------------------
// CHelloAppUi::CHelloAppUi()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CHelloAppUi::CHelloAppUi()
{
// No implementation required
}
// -----------------------------------------------------------------------------
// CHelloAppUi::~CHelloAppUi()
// Destructor.
// -----------------------------------------------------------------------------
//
CHelloAppUi::~CHelloAppUi()
{
if ( iAppContainer )
{
delete iAppContainer;
iAppContainer = NULL;
}
}
// -----------------------------------------------------------------------------
// CHelloAppUi::HandleCommandL()
// Takes care of command handling.
// -----------------------------------------------------------------------------
//
void CHelloAppUi::HandleCommandL( TInt aCommand )
{
switch( aCommand )
{
case EEikCmdExit:
case EAknSoftkeyExit:
Exit();
break;
case ECommand1:
{
// Load a string from the resource file and display it
HBufC* textResource = StringLoader::LoadLC( R_COMMAND1_TEXT );
CAknInformationNote* informationNote;
informationNote = new ( ELeave ) CAknInformationNote;
// Show the information Note with
// textResource loaded with StringLoader.
informationNote->ExecuteLD( *textResource);
// Pop HBuf from CleanUpStack and Destroy it.
CleanupStack::PopAndDestroy( textResource );
}
break;
case ECommand2:
{
RFs fsSession;
RFile rFile;
// Connects a client process to the fileserver
User::LeaveIfError(fsSession.Connect());
CleanupClosePushL(fsSession);
//Open file where the stream text is
User::LeaveIfError(rFile.Open(fsSession,KFileName, EFileStreamText));//EFileShareReadersOnly));// EFileStreamText));
CleanupClosePushL(rFile);
// copy stream from file to RFileStream object
RFileReadStream inputFileStream(rFile);
CleanupClosePushL(inputFileStream);
// HBufC descriptor is created from the RFileStream object.
HBufC* fileData = HBufC::NewLC(inputFileStream, 32);
CAknInformationNote* informationNote;
informationNote = new ( ELeave ) CAknInformationNote;
// Show the information Note
informationNote->ExecuteLD( *fileData);
// Pop loaded resources from the cleanup stack
CleanupStack::PopAndDestroy(4); // filedata, inputFileStream, rFile, fsSession
fsSession.Close();
}
break;
default:
Panic( EHelloUi );
break;
}
}
// -----------------------------------------------------------------------------
// Called by the framework when the application status pane
// size is changed. Passes the new client rectangle to the
// AppContainer
// -----------------------------------------------------------------------------
//
void CHelloAppUi::HandleStatusPaneSizeChange()
{
iAppContainer->SetRect( ClientRect() );
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -