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

📄 mylistboxappui.cpp

📁 symbian界面设计.关于LISTBOX的经典的例子,适合所有初学者和爱好SYMBIAN的工程师
💻 CPP
字号:
/*
============================================================================
 Name		: MyListBoxAppUi.cpp
 Author	  : davey
 Copyright   : It is a software by davey
 Description : CMyListBoxAppUi implementation
============================================================================
*/

// INCLUDE FILES
#include <avkon.hrh>
#include <aknmessagequerydialog.h>
#include <aknnotewrappers.h>
#include <stringloader.h>
#include <f32file.h>
#include <s32file.h>
#include <hlplch.h>

#include <MyListBox_0xEAC811C0.rsg>

#include "MyListBox_0xEAC811C0.hlp.hrh"
#include "MyListBox.hrh"
#include "MyListBox.pan"
#include "MyListBoxApplication.h"
#include "MyListBoxAppUi.h"
#include "MyListBoxAppView.h"

_LIT( KFileName, "C:\\private\\EAC811C0\\MyListBox.txt" );
_LIT( KText, "message++ pro");

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


// -----------------------------------------------------------------------------
// CMyListBoxAppUi::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CMyListBoxAppUi::ConstructL()
	{
	// Initialise app UI with standard value.
	BaseConstructL(CAknAppUi::EAknEnableSkin);

	// Create view object
	iAppView = CMyListBoxAppView::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) && (KErrAlreadyExists != 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
	
	AddToStackL(iAppView);
	//AddToStackL(iAppView->ListBox());

	}
// -----------------------------------------------------------------------------
// CMyListBoxAppUi::CMyListBoxAppUi()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CMyListBoxAppUi::CMyListBoxAppUi()
	{
	// No implementation required
	}

// -----------------------------------------------------------------------------
// CMyListBoxAppUi::~CMyListBoxAppUi()
// Destructor.
// -----------------------------------------------------------------------------
//
CMyListBoxAppUi::~CMyListBoxAppUi()
	{
	if ( iAppView )
		{
		//RemoveFromStack(iAppView->ListBox());
		RemoveFromStack(iAppView);
		delete iAppView;
		iAppView = NULL;
		}

	}

/*void CMyListBoxAppUi::DynInitMenuPaneL(TInt aResourceId,
		   CEikMenuPane* aMenuPane)
{
if (R_MYLISTBOX_MENU == aResourceId)
{
if (iAppView->IsDoubleLine())
{
aMenuPane->SetItemButtonState(ECmdMyListBoxDoubleLine,
EEikMenuItemSymbolOn);
}
else
{
aMenuPane->SetItemButtonState(ECmdMyListBoxDoubleLine,
EEikMenuItemSymbolIndeterminate);
}
}

#ifdef __WINS__
// This gives us the option to close down our application, letting the framework
// check for memory and resource leaks. This menu option should not exist in
// released versions, thus the ifdef
if (R_MYLISTBOX_MENU == aResourceId)
{
_LIT(KCloseMenu, "Close (debug)");
CEikMenuPaneItem::SData itemData;
itemData.iText      = KCloseMenu;
itemData.iCommandId = EEikCmdExit;
itemData.iFlags     = 0;
itemData.iCascadeId = 0;
aMenuPane->AddMenuItemL(itemData);
}
#endif // __S60__
}*/

// -----------------------------------------------------------------------------
// CMyListBoxAppUi::HandleCommandL()
// Takes care of command handling.
// -----------------------------------------------------------------------------
//
void CMyListBoxAppUi::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;
		case EHelp:
			{
			
			CArrayFix<TCoeHelpContext>* buf = CCoeAppUi::AppHelpContextL();
			HlpLauncher::LaunchHelpApplicationL(iEikonEnv->WsSession(), buf);
			}
			break;
		case EAbout:
			{
			
			CAknMessageQueryDialog* dlg = new (ELeave)CAknMessageQueryDialog(); 
			dlg->PrepareLC(R_ABOUT_QUERY_DIALOG);
			HBufC* title = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TITLE);
			dlg->QueryHeading()->SetTextL(*title);
			CleanupStack::PopAndDestroy(); //title
			HBufC* msg = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TEXT);
			dlg->SetMessageTextL(*msg);
			CleanupStack::PopAndDestroy(); //msg
			dlg->RunLD(); 
			}
			break;
		default:
			Panic( EMyListBoxUi );
			break;
		}
	}
// -----------------------------------------------------------------------------
//  Called by the framework when the application status pane
//  size is changed.  Passes the new client rectangle to the
//  AppView
// -----------------------------------------------------------------------------
//
void CMyListBoxAppUi::HandleStatusPaneSizeChange()
	{
	iAppView->SetRect( ClientRect() );
	} 

CArrayFix<TCoeHelpContext>* CMyListBoxAppUi::HelpContextL() const
	{
	#warning "Please see comment about help and UID3..."
	// Note: help will not work if the application uid3 is not in the
	// protected range.  The default uid3 range for projects created
	// from this template (0xE0000000 - 0xEFFFFFFF) are not in the protected range so they
	// can be self signed and installed on the device during testing.
	// Once you get your official uid3 from Symbian Ltd. and find/replace
	// all occurrences of uid3 in your project, the context help will
	// work.
	CArrayFixFlat<TCoeHelpContext>* array = new(ELeave)CArrayFixFlat<TCoeHelpContext>(1);
	CleanupStack::PushL(array);
	array->AppendL(TCoeHelpContext(KUidMyListBoxApp, KGeneral_Information));
	CleanupStack::Pop(array);
	return array;
	}

// End of File

⌨️ 快捷键说明

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