Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 13:54, 6 July 2008.

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

From Forum Nokia Wiki


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

概述

这个例子扩展了自定义控件例子自定义控件: 定义(一)。 在本代码片段,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: 如何使能对话框皮肤支持?

参见

自定义控件系列:

 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtopicQUqfnTopicZseriesE5f60Q
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX