http://blog.csdn.net/linzhiji/archive/2010/02/25/5321898.aspx
询问对话框
继承自CAknQueryDialog,询问对话框有两种:Local和Global。Local只在该应用内可显示;全局
的在任何时候都会显示,包括将该应用切换到后台。
本地询问对话框
分为三类:1. 确认对话框 2. 数据请求对话框 3. 列表请求对话框 4. 多选列表请求框
1. 确认对话框
RESOURCE DIALOG r_aknexquery_confirmation_query
{
flags = EGeneralQueryFlags;
buttons = R_AVKON_SOFTKEYS_YES_NO;
items =
{
DLG_LINE
{
type = EAknCtQuery;
id = EGeneralQuery;
control = AVKON_CONFIRMATION_QUERY
{
layout = EConfirmationQueryLayout;
label = qtn_aknexquery_con_label_text;
bmpfile = AKNEXQUERY_BMPFILE_NAME;
bmpid = EMbmAknexqueryLshellicon;
bmpmask = AKNEXQUERY_BITMAP_MASK_FLAG;
};
}
};
}
TBuf<256> msg(_L("Delete note?"));
CAknQueryDialog* dlg = CAknQueryDialog::NewL( );
if ( dlg->ExecuteLD(R_AKNEXQUERY_CONFIRMATION_QUERY, msg))
{
// yes/ok pressed
}
2. 数据请求对话框
文本请求对话框
RESOURCE DIALOG r_demo_data_query
{
flags = EGeneralQueryFlags;
buttons = R_AVKON_SOFTKEYS_OK_CANCEL;
items =
{
DLG_LINE
{
type = EAknCtQuery;
id = EGeneralQuery;
control = AVKON_DATA_QUERY
{
layout = EDataLayout;
label = ""; // prompt text
control = EDWIN
{
width = 5;
lines = 1;
maxlength = 15;
};
};
}
};
}
AVKON_DATA_QUERY资源包含了layout,label和请求对话框中控件。layout和空间的映射关系
如下:
文本请求对话框对应的类是:CAknTextQueryDialog。下面代码示例之:
// The descriptor used for the editor
TBuf<128> text;
// The descriptor contained the prompt text for the query. The prompt // text can also be defined in the
resource structure of the query
TBuf<128> prompt(_L("Enter data:"));
// create dialog instance
CAknTextQueryDialog* dlg = new( ELeave ) CAknTextQueryDialog( text, prompt );
// Prepares the dialog, constructing it from the specified resource
dlg->PrepareLC( R_DEMO_DATA_QUERY );
// Sets the maximum length of the text editor
dlg->SetMaxLength(10);
// Launch the dialog
if (dlg->RunLD())
{
// ok pressed, text is the descriptor containing the entered text // in the editor.
}
数字请求对话框
RESOURCE DIALOG r_aknexquery_number_layout
{
flags = EGeneralQueryFlags;
buttons = R_AVKON_SOFTKEYS_OK_CANCEL;
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;
};
};
}
};
}
数字请求对话框对应的类是:CAknNumberQueryDialog。下面代码示例之:
#include <aknQueryDialog.h> // all the query dialog listed here
TInt number(123456);
// create dialog instance; number is the descriptor that is used for // the editor
CAknNumberQueryDialog* dlg = new (ELeave) CAknNumberQueryDialog (number);
// Prepares the dialog, constructing it from the specified resource
dlg->PrepareLC(R_AKNEXQUERY_NUMBER_LAYOUT);
// Set maximum and minimum to editor. This overrides values given in // resource. - optional
dlg->SetMinimumAndMaximum( 0, 1000000 );
// Launch the dialog
if (dlg->RunLD())
{
// ok pressed, number is the entered number in the editor.
}
时间/日期请求对话框
RESOURCE DIALOG r_aknexquery_time_query
{
flags = EGeneralQueryFlags;
buttons = R_AVKON_SOFTKEYS_OK_CANCEL;
items =
{
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;
};
};
}
};
}
时间/日期请求对话框对应的类是:CAknTimeQueryDialog。下面代码示例之:
TTime time(_L("20000111:200600.000000"));
// The prompt text for the query
TBuf<128> prompt(_L("Enter Time:"));
// create dialog instance; time is a reference to TTime object that is // used for the editor
CAknTimeQueryDialog* dlg =CAknTimeQueryDialog::NewL( time, CAknQueryDialog::ENoTone);
CleanupStack::PushL(dlg);
// set prompt text for query. This will override text given in resource
dlg->SetPromptL(prompt);
CleanupStack::Pop(); //dlg
// launch the dialog with resource
if (dlg->ExecuteLD(R_AKNEXQUERY_TIME_QUERY))
{
// ok pressed, time is a Ttime object containing the entered time // in the editor.
}
持续时间请求对话框
持续时间请求对话框跟时间/日期请求对话框类似,区别是它的layout是EDurationLayout,control是DURATION_EDITOR
RESOURCE DIALOG r_aknexquery_duration_layout
{
flags = EGeneralQueryFlags;
buttons = R_AVKON_SOFTKEYS_OK_CANCEL;
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;
};
};
}
};
}
其中:
STRUCT DURATION_EDITOR
{
STRUCT minDuration; // DURATION
STRUCT maxDuration; // DURATION
BYTE flags=0; // permitted flags:
// EEikTimeWithout[Seconds][Hours]Field
}
STRUCT DURATION
{
LONG seconds=0; // must be greater than or equal to zero
}
持续时间请求对话框对应的类是:CAknDurationQueryDialog。下面代码示例之:
TTimeIntervalSeconds duration;
// create dialog instance; duration is a reference to
// TTimeIntervalSeconds object that is used for the editor
CAknDurationQueryDialog* dlg = CAknDurationQueryDialog::NewL(duration, CAknQueryDialog::ENoTone );
// launch the dialog with resource
if (dlg->ExecuteLD(R_AKNEXQUERY_DURATION_LAYOUT))
{
// ok pressed, duration is a TtimeIntervalSeconds object
// containing the entered duration in the editor.
}
浮点数请求对话框
RESOURCE DIALOG r_demo_floating_query
{
flags = EGeneralQueryFlags;
buttons = R_AVKON_SOFTKEYS_OK_CANCEL;
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;
};
};
}
};
}
STRUCT FLPTED
{
WORD maxlength=18;
DOUBLE min=-9.9e99;
DOUBLE max=9.9e99;
DOUBLE default=0; // if !(min<=default<=max), default = min.
}
浮点数请求对话框对应的类是:CAknFloatingPointQueryDialog。下面代码示例之:
TReal value = 2.12345;
// create dialog instance; value is a TReal reference that is used for // the editor
CAknFloatingPointQueryDialog* dlg =new (ELeave) CAknFloatingPointQueryDialog (value);
// launch the dialog with resource R_DEMO_FLOATING_QUERY
if (dlg->ExecuteLD( R_DEMO_FLOATING_QUERY ))
{
// ok pressed, value is the entered floating point number in the // editor.
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/linzhiji/archive/2010/02/25/5321898.aspx