学习SYMBIAN 对话框(二)

5、询问对话框
询问对话框用到的类:
CAknQueryDialog
头文件:AknQueryDialog.h
lib:avkon.lib

使用方法:

Code:
CAknQueryDialog* dlg;
dlg = CAknQueryDialog::NewL( CAknQueryDialog::ENoTone );
dlg->PrepareLC( R_RESOURCE_QUERY_DIALOG ); //从资源文件构造对话框,资源见下面的定义
TInt ret = dlg->RunLD();    //若用户选择“是”,返回非0,选择“否”,则返回0

RESOURCE DIALOG R_RESOURCE_QUERY_DIALOG    //询问对话框资源
      {
      flags = EGeneralQueryFlags;
      buttons = R_AVKON_SOFTKEYS_YES_NO;    //CBA显示“是”和“否”两个按钮
      items =
          {
          DLG_LINE
              {
              type = EAknCtQuery;
              id = EGeneralQuery;
              control = AVKON_CONFIRMATION_QUERY     //表示这是confirm询问对话框,用户选择“是”或“否”
                  {
                  layout = EConfirmationQueryLayout;
                  label = "对话框中显示的文字";
                  };
              }
          };
      }

此类对话框可以有声音提示,由NewL的const TTone& aTone参数指定,可能的值如下:

Code:
enum TTone {
      /// No tone is played
      ENoTone = 0,        
      /// A confirmation tone is played
      EConfirmationTone = EAvkonSIDConfirmationTone,
      /// A warning tone is played
      EWarningTone = EAvkonSIDWarningTone,      
      /// An error tone is played  
      EErrorTone = EAvkonSIDErrorTone         
      };

通过定义不同的询问对话框资源,可实现不同的询问对话框,如让用户输入文字的询问对话框资源定义如下:

Code:
RESOURCE DIALOG R_RESOURCE_DATA_QUERY
    {
    flags = EGeneralQueryFlags;
    buttons = R_AVKON_SOFTKEYS_OK_CANCEL;    //CBA按钮显示“确定”和“取消”
    items =
        {
        DLG_LINE
            {
            type = EAknCtQuery;
            id = EGeneralQuery;
            control = AVKON_DATA_QUERY    //表示这是data询问对话框,需要用户输入内容
                {
                layout = EDataLayout;
                label = "提示内容";
                control = EDWIN
                    {
                    flags = EEikEdwinNoHorizScrolling | EEikEdwinResizable;
                    width = 30;
                    lines = 2;
                    maxlength = 159;
                    };
                };
            }
        };
    }    

其中相应的对应关系如下:

Type               

Layout

Control

Time editor

ETimeLayout

TIME_EDITOR

Date editor

EDateLayout

DATE_EDITOR

 

Type               

Layout

Control

Alphanumeric text

EDataLayout    

EDWIN

Secret editor

ECodeLayout

SECRETED

Phone number

EPhoneLayout  

EDWIN

PIN code

EPinLayout

SECRETED

 


除此之外还有数值查询框,浮点数询问框等。

使用方法:

 

Code:
TBuf<128> msg;
CAknTextQueryDialog* dlg = new (ELeave) CAknTextQueryDialog(msg,CAknQueryDialog::ENoTone);
    TInt ret = dlg->ExecuteLD(R_RESOURCE_DATA_QUERY);

用户输入内容后按“确定”,内容就存储到msg中,函数返回非0;按“取消”,函数返回0。

这里用到的类是CAknQueryDialog的子类CAknTextQueryDialog。
CAknQueryDialog的子类有:

Code:
CAknFloatingPointQueryDialog    //This class should be used when user is reguest to enter a flotaing point number
    CAknFixedPointQueryDialog       //...
    CAknDurationQueryDialog         //This class should be used when user is reguest to enter duration
    CAknIpAddressQueryDialog        //This class should be used when user is reguest to enter IP address,@since 2.1
    CAknMultiLineDataQueryDialog    //Query Dialog with data input on more than one line (2 lines at the moment)
                   Create using NewL methods and passing parameters as appropriate.
                   Attention: When deriving from this class, you must call SetDataL during
                   second phase construction.
    CAknMultiLineIpQueryDialog      //...
    CAknNumberQueryDialog           //This class should be used when user is reguest to enter number
    CAknTextQueryDialog             //This class should be used when user is reguest to enter plain text, secret text, phonenumber or PIN-code
CAknTimeQueryDialog             //This class should be used when user is reguest to enter time or date

使用不同的类,资源文件会有所不同。

另外,在资源中定义EDWIN时,可指定输入发,如:

Code:
control = EDWIN
    {
      flags = EEikEdwinNoHorizScrolling | EEikEdwinResizable;
      width = 11;
      lines = 1;
      maxlength = 11;
    avkon_flags = EAknEditorFlagFixedCase |
          EAknEditorFlagNoT9 | EAknEditorFlagSupressShiftMenu;    //EAknEditorFlagSupressShiftMenu屏蔽切换输入法键
    allowed_input_modes = EAknEditorNumericInputMode;
    default_input_mode = EAknEditorNumericInputMode;
    numeric_keymap = EAknEditorPlainNumberModeKeymap;
    };

以上写法表示默认输入法为数字,并且屏蔽了输入法切换键,即不能通过输入法切换键来切换输入法。

数值查询类的写法:

items =

        {

        DLG_LINE

            {

            type = EAknCtQuery;

            id = EGeneralQuery;

            control= AVKON_DATA_QUERY

                {

                layout = ENumberLayout;

                label = qtn_aknexquery_num_label_text;

                control = AVKON_INTEGER_EDWIN

                    {

                    min = AKNEXQUERY_NUMBER_EDITOR_MIN;

                    max = AKNEXQUERY_NUMBER_EDITOR_MAX;

                    };

                };

            }

        };

时间询问类的资源写法:

DLG_LINE

            {

            type = EAknCtQuery;

            id = EGeneralQuery;

            control = AVKON_DATA_QUERY

                {

                layout = ETimeLayout;

                label = qtn_aknexquery_time_label_text;

                control = TIME_EDITOR

                    {

                    minTime = TIME

                        {

                        second =

                           AKNEXQUERY_TIME_EDITOR_MIN_SECOND;

                        minute =

                           AKNEXQUERY_TIME_EDITOR_MIN_MINUTE;

                        hour =

                           AKNEXQUERY_TIME_EDITOR_MIN_HOUR;

                        };

                    maxTime = TIME

                        {

                        second =

                           AKNEXQUERY_TIME_EDITOR_MAX_SECOND;

                        minute =

                           AKNEXQUERY_TIME_EDITOR_MAX_MINUTE;

                        hour =

                           AKNEXQUERY_TIME_EDITOR_MAX_HOUR;

                        };

                    flags = EEikTimeWithoutSecondsField;

                                                };

                };

            }

        };

(播放总)时间询问类的资源文件写法:

items =

        {

        DLG_LINE

            {

            type = EAknCtQuery;

            id = EGeneralQuery;

            control = AVKON_DATA_QUERY

                {

                layout = EDurationLayout;

                label = qtn_aknexquery_dura_label_text;

                control = DURATION_EDITOR

                    {

                    minDuration = DURATION

                        {

                        };

                    maxDuration = DURATION

                        {

                        seconds =

                           AKNEXQUERY_DURATION_EDITOR_MAX_SECOND;

                        };

                    flags = AKNEXQUERY_DURATION_EDITOR_FLAGS;

                    };

                };

            }

        };

浮点询问框资源写法:

items =

        {

        DLG_LINE

            {

            type = EAknCtQuery;

            id = EGeneralQuery;

            control = AVKON_DATA_QUERY

                {

                layout = EFloatingPointLayout;

                label = "Enter value :";

                control = FLPTED

                    {

                        maxlength=10;

                        min=0;

                        max=100;

                        default=0;

                    };

                };

            }

        };

6、编辑框
编辑框使用的类:
CEikGlobalTextEditor
头文件:eikgted.h

使用方法:

Code:
CEikGlobalTextEditor* iGKeyEd;
TBuf<128> iKeyText;
TResourceReader reader;
    iCoeEnv->CreateResourceReaderLC( reader, R_RESOURCE_EDITOR );    //从资源文件构造编辑框,资源见下面的定义
    iGKeyEd = new ( ELeave ) CEikGlobalTextEditor;
    iGKeyEd->SetContainerWindowL( *this );
    iGKeyEd->ConstructFromResourceL( reader );
    CleanupStack::PopAndDestroy();    // Resource reader

//设置编辑框的初始文本和位置,编辑框大小在资源中定义
TBuf<32> buf;
buf.Copy(_L("demo"));
iGKeyEd->SetTextL(&buf);
iGKeyEd->SetExtent( TPoint(5,2), iGKeyEd->MinimumSize() );
iGKeyEd->SetFocus(ETrue);
// iGKeyEd->SetReadOnly(ETrue);    //设置编辑框为只读

//使文字居中
    CParaFormat       paraFormat;
    TParaFormatMask paraFormatMask;
    paraFormatMask.SetAttrib( EAttAlignment );      // set mask
    paraFormat.iHorizontalAlignment = CParaFormat::ECenterAlign;
    iGKeyEd->ApplyParaFormatL( &paraFormat, paraFormatMask );
  
    iGKeyEd->GetText(iKeyText); //获取编辑框中的内容,保存到iKeyText中

RESOURCE GTXTED R_RESOURCE_EDITOR    //编辑框资源  
    {
      flags = EAknEditorFlagDefault;
      width = 53;
      height = 16;
      numlines = 1;
      textlimit= 1;
      fontcontrolflags = EGulFontControlAll;
      fontnameflags = EGulNoSymbolFonts;

//这里也可设置输入法
//     avkon_flags = EAknEditorFlagFixedCase |
                                    EAknEditorFlagNoT9 | EAknEditorFlagSupressShiftMenu;    //EAknEditorFlagSupressShiftMenu屏蔽切换输入法键
//      allowed_input_modes = EAknEditorNumericInputMode;
//      default_input_mode = EAknEditorNumericInputMode;
//      numeric_keymap = EAknEditorPlainNumberModeKeymap;  
    }

注意,要使编辑框正常显示,记得更改container的CountComponentControls和ComponentControl函数,正确处理控件数目和编辑框指针。另外,要使编辑框能正常接收按键事件,要显示调用编辑框的OfferKeyEventL函数,如下:

Code:
TKeyResponse CMobileGuardSetKeyContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType )
{
      return iGKeyEd->OfferKeyEventL( aKeyEvent, aType );
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

brew2003

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值