Symbian添加一个控件的基本步骤

来源:百度文库 编辑:神马文学网 时间:2024/04/29 08:26:32
Symbian添加一个控件的基本步骤 
 这是对于复杂视图模型来说的添加一个控件的基本步骤
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;在容器中添加控件时没怎么考虑关于内存的问题,好像把控件塞进容器中就不用太费心了。控件用到的一些资源定义在rss中,字符串之类的定义在loc中。