這不是Hello World!!!(大泣)

瀏覽: 2093
回覆: 4
共1頁
發文數:3243
發表時間:2011-04-01 04:24:00
這是我這禮拜一直在琢磨的東東...

功能嘛~只是顯示一段文字而已...

但是為什麼要搞得那麼複雜= =


/*
============================================================================
Name : Hello_World_GUI.cpp
Author :
Copyright : Made by Vdragon for testing usage.
Description : Main application class
============================================================================
*/

// INCLUDE FILES
#include <eikstart.h>
#include "Hello_World_GUIApplication.h"

LOCAL_C CApaApplication* NewApplication()
{
return new CHello_World_GUIApplication;
}

GLDEF_C TInt E32Main()
{
return EikStart::RunApplication(NewApplication);
}

/*
============================================================================
Name : Hello_World_GUIApplication.cpp
Author :
Copyright : Made by Vdragon for testing usage.
Description : Main application class
============================================================================
*/

// INCLUDE FILES
#include "Hello_World_GUI.hrh"
#include "Hello_World_GUIDocument.h"
#include "Hello_World_GUIApplication.h"

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

// -----------------------------------------------------------------------------
// CHello_World_GUIApplication::CreateDocumentL()
// Creates CApaDocument object
// -----------------------------------------------------------------------------
//
CApaDocument* CHello_World_GUIApplication::CreateDocumentL()
{
// Create an Hello_World_GUI document, and return a pointer to it
return CHello_World_GUIDocument::NewL(*this);
}

// -----------------------------------------------------------------------------
// CHello_World_GUIApplication::AppDllUid()
// Returns application UID
// -----------------------------------------------------------------------------
//
TUid CHello_World_GUIApplication::AppDllUid() const
{
// Return the UID for the Hello_World_GUI application
return KUidHello_World_GUIApp;
}

// End of File

/*
============================================================================
Name : Hello_World_GUIAppUi.cpp
Author :
Copyright : Made by Vdragon for testing usage.
Description : CHello_World_GUIAppUi 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 <Hello_World_GUI_0xEBFEC32C.rsg>

#ifdef _HELP_AVAILABLE_
#include "Hello_World_GUI_0xEBFEC32C.hlp.hrh"
#endif
#include "Hello_World_GUI.hrh"
#include "Hello_World_GUI.pan"
#include "Hello_World_GUIApplication.h"
#include "Hello_World_GUIAppUi.h"
#include "Hello_World_GUIAppView.h"

_LIT( KFileName, "C:\\private\\EBFEC32C\\Hello_World_GUI.txt" );
_LIT( KText, "Hello World!");

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


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

// Create view object
iAppView = CHello_World_GUIAppView::NewL(ClientRect());

// Create a file to write the text to
TInt err = CCoeEnv::Static()->FsSession().MkDirAll(KFileName);
if ((KErrNone != err) && (KErrAlreadyExists != err))
{
return;
}

RFile file;
err = file.Replace(CCoeEnv::Static()->FsSession(), KFileName, EFileWrite);
CleanupClosePushL(file);
if (KErrNone != err)
{
CleanupStack::PopAndDestroy(1); // file
return;
}

RFileWriteStream outputFileStream(file);
CleanupClosePushL(outputFileStream);
outputFileStream << KText;

CleanupStack::PopAndDestroy(2); // outputFileStream, file

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

// -----------------------------------------------------------------------------
// CHello_World_GUIAppUi::~CHello_World_GUIAppUi()
// Destructor.
// -----------------------------------------------------------------------------
//
CHello_World_GUIAppUi::~CHello_World_GUIAppUi()
{
if (iAppView)
{
delete iAppView;
iAppView = NULL;
}

}

// -----------------------------------------------------------------------------
// CHello_World_GUIAppUi::HandleCommandL()
// Takes care of command handling.
// -----------------------------------------------------------------------------
//
void CHello_World_GUIAppUi::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:
{
RFile rFile;

//Open file where the stream text is
User::LeaveIfError(rFile.Open(CCoeEnv::Static()->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(3); // filedata, inputFileStream, rFile
}
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( EHello_World_GUIUi);
break;
}
}
// -----------------------------------------------------------------------------
// Called by the framework when the application status pane
// size is changed. Passes the new client rectangle to the
// AppView
// -----------------------------------------------------------------------------
//
void CHello_World_GUIAppUi::HandleStatusPaneSizeChange()
{
iAppView->SetRect(ClientRect());
}

CArrayFix<TCoeHelpContext>* CHello_World_GUIAppUi::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 that 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. Alternatively, a patch now exists for the versions of
// HTML help compiler in SDKs and can be found here along with an FAQ:
// http://www3.symbian.com/faq.nsf/AllByDate/E9DF3257FD565A658025733900805EA2?OpenDocument
#ifdef _HELP_AVAILABLE_
CArrayFixFlat<TCoeHelpContext>* array = new(ELeave)CArrayFixFlat<TCoeHelpContext>(1);
CleanupStack::PushL(array);
array->AppendL(TCoeHelpContext(KUidHello_World_GUIApp, KGeneral_Information));
CleanupStack::Pop(array);
return array;
#else
return NULL;
#endif
}

// End of File

/*
============================================================================
Name : Hello_World_GUIAppView.cpp
Author :
Copyright : Made by Vdragon for testing usage.
Description : Application view implementation
============================================================================
*/

// INCLUDE FILES
#include <coemain.h>
#include "Hello_World_GUIAppView.h"

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

// -----------------------------------------------------------------------------
// CHello_World_GUIAppView::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CHello_World_GUIAppView* CHello_World_GUIAppView::NewL(const TRect& aRect)
{
CHello_World_GUIAppView* self = CHello_World_GUIAppView::NewLC(aRect);
CleanupStack::Pop(self);
return self;
}

// -----------------------------------------------------------------------------
// CHello_World_GUIAppView::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CHello_World_GUIAppView* CHello_World_GUIAppView::NewLC(const TRect& aRect)
{
CHello_World_GUIAppView* self = new (ELeave) CHello_World_GUIAppView;
CleanupStack::PushL(self);
self->ConstructL(aRect);
return self;
}

// -----------------------------------------------------------------------------
// CHello_World_GUIAppView::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CHello_World_GUIAppView::ConstructL(const TRect& aRect)
{
// Create a window for this application view
CreateWindowL();

// Set the windows size
SetRect(aRect);

// Activate the window, which makes it ready to be drawn
ActivateL();
}

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

// -----------------------------------------------------------------------------
// CHello_World_GUIAppView::~CHello_World_GUIAppView()
// Destructor.
// -----------------------------------------------------------------------------
//
CHello_World_GUIAppView::~CHello_World_GUIAppView()
{
// No implementation required
}

// -----------------------------------------------------------------------------
// CHello_World_GUIAppView::Draw()
// Draws the display.
// -----------------------------------------------------------------------------
//
void CHello_World_GUIAppView::Draw(const TRect& /*aRect*/) const
{
// Get the standard graphics context
CWindowGc& gc = SystemGc();

// Gets the control's extent
TRect drawRect(Rect());

// Clears the screen
gc.Clear(drawRect);

}

// -----------------------------------------------------------------------------
// CHello_World_GUIAppView::SizeChanged()
// Called by framework when the view size is changed.
// -----------------------------------------------------------------------------
//
void CHello_World_GUIAppView::SizeChanged()
{
DrawNow();
}

// -----------------------------------------------------------------------------
// CHello_World_GUIAppView::HandlePointerEventL()
// Called by framework to handle pointer touch events.
// Note: although this method is compatible with earlier SDKs,
// it will not be called in SDKs without Touch support.
// -----------------------------------------------------------------------------
//
void CHello_World_GUIAppView::HandlePointerEventL(
const TPointerEvent& aPointerEvent)
{

// Call base class HandlePointerEventL()
CCoeControl::HandlePointerEventL(aPointerEvent);
}

// End of File

/*
============================================================================
Name : Hello_World_GUIDocument.cpp
Author : V字龍
Copyright : Made by Vdragon for testing usage.
Description : CHello_World_GUIDocument implementation
============================================================================
*/

// INCLUDE FILES
#include "Hello_World_GUIAppUi.h"
#include "Hello_World_GUIDocument.h"

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

// -----------------------------------------------------------------------------
// CHello_World_GUIDocument::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CHello_World_GUIDocument* CHello_World_GUIDocument::NewL(CEikApplication& aApp)
{
CHello_World_GUIDocument* self = NewLC(aApp);
CleanupStack::Pop(self);
return self;
}

// -----------------------------------------------------------------------------
// CHello_World_GUIDocument::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CHello_World_GUIDocument* CHello_World_GUIDocument::NewLC(CEikApplication& aApp)
{
CHello_World_GUIDocument* self =
new (ELeave) CHello_World_GUIDocument(aApp);

CleanupStack::PushL(self);
self->ConstructL();
return self;
}

// -----------------------------------------------------------------------------
// CHello_World_GUIDocument::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CHello_World_GUIDocument::ConstructL()
{
// No implementation required
}

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

// ---------------------------------------------------------------------------
// CHello_World_GUIDocument::~CHello_World_GUIDocument()
// Destructor.
// ---------------------------------------------------------------------------
//
CHello_World_GUIDocument::~CHello_World_GUIDocument()
{
// No implementation required
}

// ---------------------------------------------------------------------------
// CHello_World_GUIDocument::CreateAppUiL()
// Constructs CreateAppUi.
// ---------------------------------------------------------------------------
//
CEikAppUi* CHello_World_GUIDocument::CreateAppUiL()
{
// Create the application user interface, and return a pointer to it;
// the framework takes ownership of this object
return new (ELeave) CHello_World_GUIAppUi;
}

// End of File


/*
============================================================================
Name : Hello_World_GUIApplication.h
Author :
Copyright : Made by Vdragon for testing usage.
Description : Declares main application class.
============================================================================
*/

#ifndef __HELLO_WORLD_GUIAPPLICATION_H__
#define __HELLO_WORLD_GUIAPPLICATION_H__

// INCLUDES
#include <aknapp.h>
#include "Hello_World_GUI.hrh"

// UID for the application;
// this should correspond to the uid defined in the mmp file
const TUid KUidHello_World_GUIApp =
{
_UID3
};

// CLASS DECLARATION

/**
* CHello_World_GUIApplication application class.
* Provides factory to create concrete document object.
* An instance of CHello_World_GUIApplication is the application part of the
* AVKON application framework for the Hello_World_GUI example application.
*/
class CHello_World_GUIApplication : public CAknApplication
{
public:
// Functions from base classes

/**
* From CApaApplication, AppDllUid.
* @return Application's UID (KUidHello_World_GUIApp).
*/
TUid AppDllUid() const;

protected:
// Functions from base classes

/**
* From CApaApplication, CreateDocumentL.
* Creates CHello_World_GUIDocument document object. The returned
* pointer in not owned by the CHello_World_GUIApplication object.
* @return A pointer to the created document object.
*/
CApaDocument* CreateDocumentL();
};

#endif // __HELLO_WORLD_GUIAPPLICATION_H__
// End of File

/*
============================================================================
Name : Hello_World_GUIAppUi.h
Author :
Copyright : Made by Vdragon for testing usage.
Description : Declares UI class for application.
============================================================================
*/

#ifndef __HELLO_WORLD_GUIAPPUI_h__
#define __HELLO_WORLD_GUIAPPUI_h__

// INCLUDES
#include <aknappui.h>

// FORWARD DECLARATIONS
class CHello_World_GUIAppView;

// CLASS DECLARATION
/**
* CHello_World_GUIAppUi application UI class.
* Interacts with the user through the UI and request message processing
* from the handler class
*/
class CHello_World_GUIAppUi : public CAknAppUi
{
public:
// Constructors and destructor

/**
* ConstructL.
* 2nd phase constructor.
*/
void ConstructL();

/**
* CHello_World_GUIAppUi.
* C++ default constructor. This needs to be public due to
* the way the framework constructs the AppUi
*/
CHello_World_GUIAppUi();

/**
* ~CHello_World_GUIAppUi.
* Virtual Destructor.
*/
virtual ~CHello_World_GUIAppUi();

private:
// Functions from base classes

/**
* From CEikAppUi, HandleCommandL.
* Takes care of command handling.
* @param aCommand Command to be handled.
*/
void HandleCommandL(TInt aCommand);

/**
* HandleStatusPaneSizeChange.
* Called by the framework when the application status pane
* size is changed.
*/
void HandleStatusPaneSizeChange();

/**
* From CCoeAppUi, HelpContextL.
* Provides help context for the application.
* size is changed.
*/
CArrayFix<TCoeHelpContext>* HelpContextL() const;

private:
// Data

/**
* The application view
* Owned by CHello_World_GUIAppUi
*/
CHello_World_GUIAppView* iAppView;

};

#endif // __HELLO_WORLD_GUIAPPUI_h__
// End of File

/*
============================================================================
Name : Hello_World_GUIAppView.h
Author :
Copyright : Made by Vdragon for testing usage.
Description : Declares view class for application.
============================================================================
*/

#ifndef __HELLO_WORLD_GUIAPPVIEW_h__
#define __HELLO_WORLD_GUIAPPVIEW_h__

// INCLUDES
#include <coecntrl.h>

// CLASS DECLARATION
class CHello_World_GUIAppView : public CCoeControl
{
public:
// New methods

/**
* NewL.
* Two-phased constructor.
* Create a CHello_World_GUIAppView object, which will draw itself to aRect.
* @param aRect The rectangle this view will be drawn to.
* @return a pointer to the created instance of CHello_World_GUIAppView.
*/
static CHello_World_GUIAppView* NewL(const TRect& aRect);

/**
* NewLC.
* Two-phased constructor.
* Create a CHello_World_GUIAppView object, which will draw itself
* to aRect.
* @param aRect Rectangle this view will be drawn to.
* @return A pointer to the created instance of CHello_World_GUIAppView.
*/
static CHello_World_GUIAppView* NewLC(const TRect& aRect);

/**
* ~CHello_World_GUIAppView
* Virtual Destructor.
*/
virtual ~CHello_World_GUIAppView();

public:
// Functions from base classes

/**
* From CCoeControl, Draw
* Draw this CHello_World_GUIAppView to the screen.
* @param aRect the rectangle of this view that needs updating
*/
void Draw(const TRect& aRect) const;

/**
* From CoeControl, SizeChanged.
* Called by framework when the view size is changed.
*/
virtual void SizeChanged();

/**
* From CoeControl, HandlePointerEventL.
* Called by framework when a pointer touch event occurs.
* Note: although this method is compatible with earlier SDKs,
* it will not be called in SDKs without Touch support.
* @param aPointerEvent the information about this event
*/
virtual void HandlePointerEventL(const TPointerEvent& aPointerEvent);

private:
// Constructors

/**
* ConstructL
* 2nd phase constructor.
* Perform the second phase construction of a
* CHello_World_GUIAppView object.
* @param aRect The rectangle this view will be drawn to.
*/
void ConstructL(const TRect& aRect);

/**
* CHello_World_GUIAppView.
* C++ default constructor.
*/
CHello_World_GUIAppView();

};

#endif // __HELLO_WORLD_GUIAPPVIEW_h__
// End of File

/*
============================================================================
Name : Hello_World_GUIDocument.h
Author :
Copyright : Made by Vdragon for testing usage.
Description : Declares document class for application.
============================================================================
*/

#ifndef __HELLO_WORLD_GUIDOCUMENT_h__
#define __HELLO_WORLD_GUIDOCUMENT_h__

// INCLUDES
#include <akndoc.h>

// FORWARD DECLARATIONS
class CHello_World_GUIAppUi;
class CEikApplication;

// CLASS DECLARATION

/**
* CHello_World_GUIDocument application class.
* An instance of class CHello_World_GUIDocument is the Document part of the
* AVKON application framework for the Hello_World_GUI example application.
*/
class CHello_World_GUIDocument : public CAknDocument
{
public:
// Constructors and destructor

/**
* NewL.
* Two-phased constructor.
* Construct a CHello_World_GUIDocument for the AVKON application aApp
* using two phase construction, and return a pointer
* to the created object.
* @param aApp Application creating this document.
* @return A pointer to the created instance of CHello_World_GUIDocument.
*/
static CHello_World_GUIDocument* NewL(CEikApplication& aApp);

/**
* NewLC.
* Two-phased constructor.
* Construct a CHello_World_GUIDocument for the AVKON application aApp
* using two phase construction, and return a pointer
* to the created object.
* @param aApp Application creating this document.
* @return A pointer to the created instance of CHello_World_GUIDocument.
*/
static CHello_World_GUIDocument* NewLC(CEikApplication& aApp);

/**
* ~CHello_World_GUIDocument
* Virtual Destructor.
*/
virtual ~CHello_World_GUIDocument();

public:
// Functions from base classes

/**
* CreateAppUiL
* From CEikDocument, CreateAppUiL.
* Create a CHello_World_GUIAppUi object and return a pointer to it.
* The object returned is owned by the Uikon framework.
* @return Pointer to created instance of AppUi.
*/
CEikAppUi* CreateAppUiL();

private:
// Constructors

/**
* ConstructL
* 2nd phase constructor.
*/
void ConstructL();

/**
* CHello_World_GUIDocument.
* C++ default constructor.
* @param aApp Application creating this document.
*/
CHello_World_GUIDocument(CEikApplication& aApp);

};

#endif // __HELLO_WORLD_GUIDOCUMENT_h__
// End of File

V字龍(Vdragon) 於 2015-05-25 08:59:27 修改文章內容


商業贊助
發文數:1
發表時間:2025-10-13 08:43:48
發文數:2288
發表時間:2011-04-01 06:09:00
引用『V字龍』所述:
這是我這禮拜一直在琢磨的東東...功能嘛~只是顯示一段文字而已...但是為什麼要搞得那麼複雜= =/* ============================================================================ Name : Hello_World_GUI.cpp Author : Copyright : Made by Vdragon f..........恕刪
一起哭吧XD...

小宇 於 2011-04-01 06:09:00 修改文章內容


發文數:235
發表時間:2011-04-02 11:36:00
這是最近我在琢磨的東西


這是之前我在玩的東西

Joye 於 2011-04-02 11:36:00 修改文章內容


發文數:3243
發表時間:2011-04-02 12:00:00
引用『Joye』所述:
這是最近我在琢磨的東西這是之前我在玩的東西..........恕刪
...加油

V字龍(Vdragon) 於 2011-04-02 12:00:00 修改文章內容


共1頁