Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

自定义控件: 在Dialog中(六)

From Wiki
Jump to: navigation, search
Article Metadata

代码示例
文章
dougcn 在 06 Jul 2008 创建
最后由 hamishwillee 在 30 May 2013 编辑
ID CS000870 Creation date March 28, 2008
Platform S60 3rd Edition, FP1 Tested on devices Nokia N95
Category Symbian C++ Subcategory UI


Keywords (APIs, classes, methods, functions): CCoeControl, CAknDialog

Contents

概述

这个例子扩展了自定义控件例子自定义控件: 定义(一)。 在本代码片段,CMyControl自定义控件添加到CAknDialog

MMP file

添加下面这个额外的库文件,因为用到了CAknDialog

LIBRARY eikdlg.lib

创建CMyDialog

定义一个实现CEikDialog::CreateCustomControlL()方法的自定义对话框。

这个方法在对话框中创建一个控件行。其后通过标识符控件ID访问该行。控件类型由Eikon控件工厂创建。若控件类型对于Eikon控件工厂是未知的,那么控件的构造必须由CreateCustomControlL()来处理。

CMyDialog对话框资源在multiviews.rss中:

RESOURCE DIALOG r_dialog
{
flags = EAknDialogGenericFullScreen;
buttons = R_AVKON_SOFTKEYS_OK_BACK;
items =
{
DLG_LINE
{
// CMyControl custom control type (defined in multiviews.hrh)
type = KMyCustomCtl;
// CMyControl custom control id (defined in multiviews.hrh)
id = KMyCustomCtlId;
control = CUSTOMCONTROL
{
txt = STRING_r_custom_control_dialog;
};
}
};
}

CMyDialog 对话框头文件定义了所需的CreateCustomControlL()方法:

#include <akndialog.h>
 
class CMyDialog : public CAknDialog
{
public:
static TInt RunDlgLD();
void PreLayoutDynInitL();
 
private:
SEikControlInfo CreateCustomControlL(TInt aControlType);
};

CMyDialog对话框实现:

#include "cmydialog.h"
#include "cmycontrol.h"
#include <MultiViews.rsg>
#include "MultiViews.hrh"
 
TInt CMyDialog::RunDlgLD()
{
CMyDialog* dlg = new (ELeave) CMyDialog;
return dlg->ExecuteLD(R_DIALOG);
}
 
void CMyDialog::PreLayoutDynInitL()
{
CMyControl* control = (CMyControl*)Control(KMyCustomCtlId);
// TODO: tune components if needed
}
 
SEikControlInfo CMyDialog::CreateCustomControlL(TInt aControlType)
{
SEikControlInfo controlInfo;
controlInfo.iControl = NULL ;
controlInfo.iTrailerTextId = 0 ;
controlInfo.iFlags = 0 ;
 
switch (aControlType)
{
// CMyControl custom control type (defined in multiviews.hrh)
case KMyCustomCtl:
{
controlInfo.iControl = new(ELeave)CMyControl();
break;
}
default:
break;
}
return controlInfo;
}

加到multiviews.hrh中的新枚举值:

// CMyControl custom control type in resource file
enum {KMyCustomCtl = KAknCtLastControlId };
// CMyControl custom control id in resource file
enum {KMyCustomCtlId = 0x503 };

调出对话框:

CMyDialog::RunDlgLD();

后置条件

CMyDialog由对话框资源来创建,且CMyControl通过调用CMyControl::ConstructFromResourceL()创建到对话框行中。 CMyDialog实现的CEikDialog::CreateCustomControlL()虚拟方法,创建自定义控件到对话框行中。

TODO: 如何使能对话框皮肤支持?

参见

自定义控件系列:

This page was last modified on 30 May 2013, at 04:42.
100 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×