Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3349516
  • 博文数量: 1450
  • 博客积分: 11163
  • 博客等级: 上将
  • 技术积分: 11101
  • 用 户 组: 普通用户
  • 注册时间: 2005-07-25 14:40
文章分类

全部博文(1450)

文章存档

2017年(5)

2014年(2)

2013年(3)

2012年(35)

2011年(39)

2010年(88)

2009年(395)

2008年(382)

2007年(241)

2006年(246)

2005年(14)

分类: C/C++

2009-07-02 10:48:47

第一步,让类文件继承 CCoeControl 类
例如:
class CTestAppView : public CCoeControl
{
......
}

第二步,在类中声明一个控件
例如:

class CEikLabel; //先声明引用的类
class CTestAppView : public CCoeControl
{
......

private:
    CEikLabel iLabel;
}

第三步, 在类中必须填加的方法

class CEikLabel; //先声明引用的类
class CTestAppView : public CCoeControl
{
......

public://继承自 CCoeControl
virtual void SizeChanged();
       virtual CCoeControl* ComponentControl( TInt aIndex ) const;
   virtual TInt CountComponentControls() const;

private:
CEikLabel iLabel;
}

第四步, 实现部分

先在文件头填加控件的头文件
#include  

下面的各个方法的实现部分

void CtestdrawcontrolAppView::ConstructL(const TRect& aRect)
{
// Create a window for this application view
CreateWindowL();
//=====================
 //     在这里添加控件
 //=======================
iLabel = new (ELeave)CEikLabel();
iLabel->SetContainerWindowL(*this);
iLabel->SetTextL(_L("play"));

// Set the windows size
SetRect(aRect);

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

CtestdrawcontrolAppView::~CtestdrawcontrolAppView()
{
//==================
// 在这里释放控件资源
//====================
delete iLabel;
iLabel = NULL;
// No implementation required
}

//当大小发生变化时,调用该函数
void CtestdrawcontrolAppView::SizeChanged()
{
TPoint startPoint(20, 30);
iLabel->SetExtent(startPoint, iLabel->MinimumSize());
DrawNow();
}

//返回所使用的控件
CCoeControl* CtestdrawcontrolAppView::ComponentControl( TInt aIndex ) const
{
switch(aIndex)
{
case 0:
return iLabel;
}
}

//返回控件的数量
TInt CtestdrawcontrolAppView::CountComponentControls() const
{
return 1;
}
阅读(589) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~