helloappcontainer.cpp

来自「symbianOS第三版开发与实用教程部分源码和部分试验」· C++ 代码 · 共 141 行

CPP
141
字号
/*
============================================================================
 Name        : HelloAppContainer.cpp
 Author      : Lion
 Copyright   : Your copyright notice
 Description : Application view implementation
============================================================================
*/

// INCLUDE FILES
#include <coemain.h>
#include "HelloAppContainer.h"
#include <eiklabel.h> 
// ============================ MEMBER FUNCTIONS ===============================

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

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

// -----------------------------------------------------------------------------
// CHelloAppContainer::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CHelloAppContainer::ConstructL( const TRect& aRect )
    {
    // Create a window for this application view
    CreateWindowL();
	iLabel1 = new (ELeave) CEikLabel;
	iLabel1->SetContainerWindowL(*this);
	iLabel1->SetTextL(_L("Hello S60!"));
    
    iLabel2 = new (ELeave) CEikLabel;
	iLabel2->SetContainerWindowL(*this);
	iLabel2->SetTextL(_L("Traditional Architecture"));
    iLabel2->CropText();
    // Set the windows size
    SetRect( aRect );

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

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


// -----------------------------------------------------------------------------
// CHelloAppContainer::~CHelloAppContainer()
// Destructor.
// -----------------------------------------------------------------------------
//
CHelloAppContainer::~CHelloAppContainer()
    {
    // No implementation required
       if (iLabel1)
   {
    delete iLabel1;
   }
   if (iLabel2)
    {
    	delete iLabel2;
    }
    }


// -----------------------------------------------------------------------------
// CHelloAppContainer::Draw()
// Draws the display.
// -----------------------------------------------------------------------------
//
void CHelloAppContainer::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 );
    
  	}

// -----------------------------------------------------------------------------
// CHelloAppContainer::SizeChanged()
// Called by framework when the view size is changed.
// -----------------------------------------------------------------------------
//
void CHelloAppContainer::SizeChanged()
{
	iLabel1->SetExtent(TPoint(10,30),iLabel1->MinimumSize());
	iLabel2->SetExtent(TPoint(10,120),iLabel2->MinimumSize());
	//DrawNow();
}
TInt CHelloAppContainer::CountComponentControls() const
{
	return 2;
}
CCoeControl* CHelloAppContainer::ComponentControl(TInt aIndex) const
    {
    switch ( aIndex )
        {
        case 0:
            return iLabel1;
        case 1:
            return iLabel2;
        default:
            return NULL;
        }
    }
// End of File

⌨️ 快捷键说明

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