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

📄 s60v22hello.cpp

📁 symbian平台进程间通信代码
💻 CPP
字号:
/*
============================================================================
 Name        : s60v22hello.cpp
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : Application source file
============================================================================

The following steps are taken when starting an application:
1. <Entry Point>::NewApplication() --> Cs60v22helloApplication
2. Cs60v22helloApplication::CreateDocument() --> Cs60v22helloDocument
3. Cs60v22helloDocument::CreateAppUiL() --> Cs60v22helloAppUi
4. Cs60v22helloAppUi::ConstructL() --> Cs60v22helloContainer

Symbian GUI applications follow the Model-View-Controller (MVC) pattern.
- Cs60v22helloDocument is the Model that holds the application data
- Cs60v22helloContainer is the View that displays the application data
- Cs60v22helloAppUi is the Controller that coordinates user actions/views
While the naming may seem a bit misleading (the names are according to the
current Symbian conventions), it is important to understand how they relate
to the MVC pattern.

Note! Normally you would have a separate file for each of these classes, but
here, for the sake of simplicity, they are all put in the same file. Having
the classes defined in separate files makes the source code easier to maintain.

*/

// INCLUDES
#include "s60v22hello.h"
#include <avkon.hrh>
#include <aknnotewrappers.h>
#include <apgtask.h>
#include <w32std.h>
#include <flogger.h>


// CONSTANTS
const TUid KUids60v22helloApp = { 0x0d18e566 }; // Application UID

// MEMBER FUNCTIONS

//----------------------------------------------------------------------------
// Application entry point
//----------------------------------------------------------------------------

// GLOBAL FUNCTIONS

// DLL entry point, needed for DLL initialization.
// Usually there is no need to initialize anything, so we just
// return that everything is ok
GLDEF_C TInt E32Dll(TDllReason /*aReason*/) {
    return KErrNone;
}

// EXPORTED FUNCTIONS

// Static function for instantiating a new application object.
// Called by the Symbian application framework.
EXPORT_C CApaApplication* NewApplication() {
    return new Cs60v22helloApplication;
}

//----------------------------------------------------------------------------
// Cs60v22helloApplication
//----------------------------------------------------------------------------

// Creates the application document (model)
// Called by the Symbian application framework when the application is started.
// Needed for all Symbian applications.
CApaDocument* Cs60v22helloApplication::CreateDocumentL() {
    return new (ELeave) Cs60v22helloDocument(*this);
}

// Specifies the application UID, needed for all Symbian applications.
TUid Cs60v22helloApplication::AppDllUid() const {
    return KUids60v22helloApp;
}

//----------------------------------------------------------------------------
// Cs60v22helloDocument (The Model of the MVC)
//----------------------------------------------------------------------------

// Creates the application document (Symbian terminology for model).
// Needed for all Symbian applications, even if the application doesn't
// save or load files.
Cs60v22helloDocument::Cs60v22helloDocument(CEikApplication& aApp) : CEikDocument(aApp) {
}

// Creates the application UI class.
// Called by the application framework when the application needs to start
// handling events.
// Needed for all Symbian GUI applications.
CEikAppUi* Cs60v22helloDocument::CreateAppUiL() {
    return new (ELeave) Cs60v22helloAppUi;
}

//----------------------------------------------------------------------------
// Cs60v22helloAppUi (The Controller of the MVC)
//----------------------------------------------------------------------------

// Second-phase construction function.
// Called by the Symbian application framework after calling
// the constructor from Cs60v22helloDocument::CreateAppUiL().
// Needed for initialising the application views.
void Cs60v22helloAppUi::ConstructL(void) {
    // Load the application resources defined in the s60v22hello.rss, e.g.
    // application menus, dialogs etc.
    BaseConstructL();

    iAppContainer = new (ELeave) Cs60v22helloContainer;
    iAppContainer->SetMopParent( this );
    iAppContainer->ConstructL( ClientRect() );
    AddToStackL( iAppContainer );
}

// Releases resources used by the application UI.
// Called when shutting down the application.
Cs60v22helloAppUi::~Cs60v22helloAppUi() {
    if (iAppContainer)
    {
        RemoveFromStack( iAppContainer );
        delete iAppContainer;
    }
}

void loggerCleanupFunc(TAny* data)
{
    RFileLogger* sg_logger = (RFileLogger*)data;
    sg_logger->CloseLog(); 
    sg_logger->Close();
}


// Handles user commands such as those associated to the menu entries.
// Called by CEikAppUi::ProcessCommandL().
// Application commands are defined in the s60v22hello.hrh file.
// Common commands are defined for instance in the uikon.hrh file, located
// under the system include directory (%EPOCROOT%\epoc32\include).
void Cs60v22helloAppUi::HandleCommandL(TInt aCommand) {
    switch (aCommand)
    {
    case EEikCmdFileOpen:
        {
            TBuf<300> buf;
            TBuf8<100> hello;
            hello.Copy(_L8("hello world!"));
            
            RWsSession& ws = CCoeEnv::Static()->WsSession();

            TInt group = 0;
            
            /*
            TApaTaskList taskList(ws);
            //TApaTask task = taskList.FindApp(TUid::Uid(0x0dd85713));
            TApaTask task = taskList.FindApp(_L("s60v22cmdas*"));
            group = task.WgId();
            */

            //group = ws.FindWindowGroupIdentifier(0, _L("s60v22cmdas*"));

            CArrayFixFlat<TInt>* list = new (ELeave) CArrayFixFlat<TInt>(10);
            CleanupStack::PushL(list);
            User::LeaveIfError(ws.WindowGroupList(list));

            RFileLogger sg_logger;
            sg_logger.Connect();
            CleanupStack::PushL(TCleanupItem(loggerCleanupFunc, &sg_logger));
            sg_logger.SetDateAndTime(EFalse, ETrue);
            sg_logger.CreateLog(_L("quxy"), _L("s60v22hello.log"), EFileLoggingModeOverwrite);

            TInt count = list->Count();
            for ( TInt i = 0; i < count; i++ )
            {
                TInt id = (*list)[i];
                TBuf<300> name;
                User::LeaveIfError(ws.GetWindowGroupNameFromIdentifier(id, name));
                sg_logger.WriteFormat(_L("id = %d, name = %S"), id, &name);
                if ( name.FindF(_L("s60v22cmdas")) >= 0 )
                {
                    group = id;
                    break;
                }
            }
            CleanupStack::PopAndDestroy(2, list);

            if ( group > 0 )
            {
                ws.SendMessageToWindowGroup(group, TUid::Uid(0x1234), hello);
                buf.AppendFormat(_L("Exists = %d"), group);
            }
            else
            {
                buf.Append(_L("not Exists"));
            }
            
            CAknInformationNote* informationNote = new ( ELeave ) CAknInformationNote;
            informationNote->ExecuteLD( buf );
            
        break;
        }
    case EAknSoftkeyBack:
    case EEikCmdExit:
        {
        Exit();
        break;
        }
    default:
        break;
    }
}

//----------------------------------------------------------------------------
// Cs60v22helloContainer (The View of the MVC)
//----------------------------------------------------------------------------

// Second-phase construction function.
// Initializes the container (creates a window, sets its bounds and activates
// it) and creates the child/nested controls (if any).
// Called from the AppUi after creating a new container object.
void Cs60v22helloContainer::ConstructL(const TRect& aRect) {
    CreateWindowL();

    iLabel = new (ELeave) CEikLabel;
    iLabel->SetContainerWindowL( *this );
    iLabel->SetTextL( _L("Example View") );

    iToDoLabel = new (ELeave) CEikLabel;
    iToDoLabel->SetContainerWindowL( *this );
    iToDoLabel->SetTextL( _L("Add Your controls\n here") );

    SetRect(aRect);
    ActivateL();
}

// Destructor used for releasing the resources used by his container.
// Called from the AppUi's destructor.
Cs60v22helloContainer::~Cs60v22helloContainer() {
    delete iLabel;
    delete iToDoLabel;
}

// Lays out the child controls (if any).
// Called when the control is resized.
void Cs60v22helloContainer::SizeChanged() {
    // TODO: Add here control resize code etc.
    iLabel->SetExtent( TPoint(10,10), iLabel->MinimumSize() );
    iToDoLabel->SetExtent( TPoint(10,100), iToDoLabel->MinimumSize() );
}

// Returns the number of child controls, 0 if none.
TInt Cs60v22helloContainer::CountComponentControls() const {
    return 2; // return nbr of controls inside this container
}

// Returns the child control at the given index, NULL if none.
CCoeControl* Cs60v22helloContainer::ComponentControl(TInt aIndex) const {
    switch ( aIndex )
    {
    case 0:
        return iLabel;
    case 1:
        return iToDoLabel;
    default:
        return NULL;
    }
}

// Draws to this controls canvas using graphics primitives.
// Note that the UI framework takes care of drawing the child controls.
void Cs60v22helloContainer::Draw(const TRect& aRect) const {
    CWindowGc& gc = SystemGc();
    // TODO: Add your drawing code here
    // example code...
    gc.SetPenStyle( CGraphicsContext::ENullPen );
    gc.SetBrushColor( KRgbGray );
    gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
    gc.DrawRect( aRect );
}

// Handles events generated by the child controls.
void Cs60v22helloContainer::HandleControlEventL(CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/) {
    // TODO: Add your control event handler code here
}

⌨️ 快捷键说明

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