一个uiq界面设计的例子~~
源代码在线查看: myviews.cpp
#include
#include
#include
#include
#include
#include
#include "MyViews.h"
#include "MyEngine.h"
#include "MyAppUi.h"
#include "MyApp.h"
CMyViewOne::CMyViewOne()
{
}
void CMyViewOne::ConstructL(const TRect& aRect)
{
CreateWindowL();
iLabel = new (ELeave) CEikLabel;
CMyEngine* engine = static_cast(CEikonEnv::Static()->AppUi())->GetEngine();
iLabel->SetTextL(engine->GetViewOneData());
iLabel->SetContainerWindowL( *this );
SetRect(aRect);
ActivateL();
}
CMyViewOne::~CMyViewOne()
{
delete iLabel;
}
void CMyViewOne::SizeChanged()
{
// TODO: Add here control resize code etc.
iLabel->SetExtent( TPoint(10,10), iLabel->MinimumSize() );
}
TInt CMyViewOne::CountComponentControls() const
{
return 1; // return nbr of controls inside this container
}
CCoeControl* CMyViewOne::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0:
return iLabel;
default:
return NULL;
}
}
void CMyViewOne::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.SetPenStyle(CGraphicsContext::ENullPen);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);
}
void CMyViewOne::ViewDeactivated()
{
MakeVisible(EFalse);
}
void CMyViewOne::ViewActivatedL(const TVwsViewId& /*aPrevViewId*/,TUid /*aCustomMessageId*/,const TDesC8& /*aCustomMessage*/)
{
CEikMenuBar* menuBar = iEikonEnv->AppUiFactory()->MenuBar();
menuBar->ChangeMenuBarL(0, R_MYAPP_MENUBAR, EFalse);
MakeVisible(ETrue);
}
TVwsViewId CMyViewOne::ViewId() const
{
return TVwsViewId(KUidMyApp,KUidMyAppViewOne);
}
//////////////////////////////////////////////////////////
CMyViewTwo::CMyViewTwo()
{
}
void CMyViewTwo::ConstructL(const TRect& aRect)
{
CreateWindowL();
iLabel = new (ELeave) CEikLabel;
CMyEngine* engine = static_cast(CEikonEnv::Static()->AppUi())->GetEngine();
iLabel->SetTextL(engine->GetViewTwoData());
iLabel->SetContainerWindowL( *this );
SetRect(aRect);
ActivateL();
}
CMyViewTwo::~CMyViewTwo()
{
delete iLabel;
}
void CMyViewTwo::SizeChanged()
{
// TODO: Add here control resize code etc.
iLabel->SetExtent( TPoint(10,10), iLabel->MinimumSize() );
}
TInt CMyViewTwo::CountComponentControls() const
{
return 1; // return nbr of controls inside this container
}
CCoeControl* CMyViewTwo::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0:
return iLabel;
default:
return NULL;
}
}
void CMyViewTwo::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
// TODO: Add your drawing code here
// example code...
gc.SetPenStyle(CGraphicsContext::ENullPen);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);
}
void CMyViewTwo::ViewConstructL()
{
ConstructL(static_cast(CEikonEnv::Static()->AppUi())->ClientRect());
(static_cast(iCoeEnv->AppUi()))->AddToStackL(*this,this);
}
void CMyViewTwo::ViewDeactivated()
{
MakeVisible(EFalse);
}
void CMyViewTwo::ViewActivatedL(const TVwsViewId& /*aPrevViewId*/,TUid /*aCustomMessageId*/,const TDesC8& /*aCustomMessage*/)
{
CEikMenuBar* menuBar = iEikonEnv->AppUiFactory()->MenuBar();
menuBar->ChangeMenuBarL(0, R_MYAPP_VIEW2_MENUBAR, EFalse);
MakeVisible(ETrue);
}
TVwsViewId CMyViewTwo::ViewId() const
{
return TVwsViewId(KUidMyApp,KUidMyAppViewTwo);
}