控件的二阶段构造函数

LongEr_leo 2007-07-13 04:50:10
初学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() 又是什么函数呢?
感谢回答!
...全文
128 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
isarc 2007-07-16
  • 打赏
  • 举报
回复
constructl可以不需要的。无所谓。看实际需要。
LongEr_leo 2007-07-16
  • 打赏
  • 举报
回复
谢谢大家!
anel 2007-07-13
  • 打赏
  • 举报
回复
你用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).

dyw 2007-07-13
  • 打赏
  • 举报
回复
ConstructL是否要设为private根据需要而定,取决于你怎么传递参数。如果NewL,NewLC有了ConstructL所需要的参数,就可以将ConstructL设为private;否则,ConstructL需设为public,这时NewL,NewLC便没什么用了。

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

ClientRect() 顾名思义,客户区矩形,Container的可见区域。

3,119

社区成员

发帖
与我相关
我的任务
社区描述
塞班系统(Symbian系统)是塞班公司为手机而设计的操作系统,它的前身是英国宝意昂公司的 EP ( Electronic Piece of cheese)操作系统。
社区管理员
  • Symbian社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧