专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Symbian

控件的二阶段构造函数解决思路

发布时间:2010-05-30 00:30:56 文章来源:www.iduyao.cn 采编人员:星星草
控件的二阶段构造函数
初学Symbian编程,有一个小问题
ConstructL()函数是不是应该被设为private?

我在写一个小控件的时候
class   CSymbian1Container   :   public   CCoeControl
{
public:
static   CSymbian1Container*   NewL(const   TRect&   aRect,const   CCoeControl*   aParent);
static   CSymbian1Container*   NewLC(const   TRect&   aRect,const   CCoeControl*   aParent);
~CSymbian1Container();
void   ConstructL(const   TRect&   aRect,   const   CCoeControl*   aParent);
}

然后在另一个类CSymbian1AppUi
class   CSymbian1AppUi   :   public   CAknAppUi
{
public:
        void   ConstructL(void);
        ~CSymbian1AppUi();
}

这个类的ConstructL函数完成时出现问题
void   CSymbian1AppUi::ConstructL(void)   {
        BaseConstructL();

        iAppContainer   =   new   (ELeave)   CSymbian1Container;
        iAppContainer-> SetMopParent(   this   );
        iAppContainer-> ConstructL(   ClientRect()   );//here
        AddToStackL(   iAppContainer   );
}
调用CSymbian1Container中的ConstructL时少了一个参数,就是const   CCoeControl*   aParent这个参数,我应该怎么加上呢?ClientRect()   又是什么函数呢?
感谢回答!

------解决方案--------------------
ConstructL是否要设为private根据需要而定,取决于你怎么传递参数。如果NewL,NewLC有了ConstructL所需要的参数,就可以将ConstructL设为private;否则,ConstructL需设为public,这时NewL,NewLC便没什么用了。

就你目前的应用来说,ConstructL的第二个参数没有必要,也没有用到NewL,NewLC。
如果一定要使用第二个参数,需将你自定义的Container放在另一个Container中,即parent。

ClientRect() 顾名思义,客户区矩形,Container的可见区域。
------解决方案--------------------
你用ConstructL,就不用CSymbian1Container* NewL(C);ConstructL里的参数 "const CCoeControl* aParent "不要了
ClientRect():
Gets the area of the screen available to the application for drawing.
This does not include the space available for UI components like the menu bar.
The co-ordinates of the rectangle are relative to the whole screen area so, for example, the co-ordinate for the top, left point of the area available for drawing may be (0, 45).

友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: