询问对话框


询问对话框用到的类:
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;
                   };
               };
           }
       };
   }   
使用方法:

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;
   };

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值