Symbian 控件新增

来源:互联网 发布:acfun离线缓存mac 编辑:程序博客网 时间:2024/06/08 15:21

添加一个控件的基本步骤

  1、在container的头文件里添加控件的定义

  2、 CmyContainer::ConstructL中创建控件,并把控件加到container中

  如下:添加一个静态Label的方法

  iLabel2 = new (ELeave) CEikLabel;

  iLabel2->SetContainerWindowL( *this );

  iLabel2->SetTextL(_L("kao"));

  iLabel2->SetExtent( TPoint(10,10), iLabel2->MinimumSize());

  3、容易被忽略的一步在修改返回组件的数目

  TInt CmyContainer::CountComponentControls() const

  {

  return 3; // return nbr of controls inside this container

  }

  其实 symbian还是蛮瓜的,你得告诉它有多少个组件,然后它一个一个的调用显示

  4、在组件控制函数中添加返回组件的代码

  CCoeControl* CmyContainer::ComponentControl(TInt aIndex) const

  {

  switch ( aIndex )

  {

  case 0:

  return iLabel;

  case 1:

  return wokao;

  }

  }

  就这样而已,有时不用 case 0 之类的,而是定义一些枚举变量,更容易阅读?我觉得是更傻了

  5、最后别忘了在析构函数 CmyContainer::~CmyContainer() 中删除定义的控件指针

  delete iLabel;

原创粉丝点击