symbian定義了幾個提示類,分別是:
confirm類:CAknConfirmationNote
info類: CAknInformationNote
warning類:CAknWarningNote
error類: CAknErrorNote
頭文件:aknnotewrappers.h
lib:avkon.lib eikcdlg.lib eikctl.lib
使用方法:
Code:
TBuf<32> buf; buf.Copy(_L("info note")); CAknInformationNote* iInfoNote = new (ELeave) CAknInformationNote; iInfoNote->ExecuteLD(buf);
2、阻塞提示框
void CEikonEnv::AlertWin(const TDesC& aMsg);
void CEikonEnv::AlertWin(const TDesC& aMsg1,const TDesC& aMsg2);
static void CEikonEnv::InfoWinL(const TDesC& aFirstLine,const TDesC& aSecondLine);
AlertWin爲CEikonEnv類的非靜態成員函數,InfoWinL爲CEikonEnv類的靜態成員函數。
AlertWin只能在ui、view和container中使用,使用方法如下:
Code:
iEikonEnv->AlertWin(_L("text"));
Code:
CEikonEnv::Static()->InfoWinL(_L("note:"), _L("text"));
Code:
#define DEBUG_DIALOG(x) iEikonEnv->AlertWin(##x); #define DEBUG_DIALOG1(x) CEikonEnv::Static()->InfoWinL(_L("note:"), ##x); #define DEBUG_DIALOG2(x,y) CEikonEnv::Static()->InfoWinL(##x, ##y); 可以這麼使用: TBuf<32> buf; buf.Copy(_L("test")); DEBUG_DIALOG(buf); DEBUG_DIALOG1(buf); DEBUG_DIALOG2(buf,_L("text"));
3、進度條對話框
進度條對話框類爲:
CAknProgressDialog
頭文件:aknprogressdialog.h
lib: avkon.lib eikcdlg.lib eikctl.lib
使用方法:
Code:
//初始化進度條 CAknProgressDialog* iProgressDialog; CEikProgressInfo* iProgressInfo; iProgressDialog = new ( ELeave ) CAknProgressDialog( reinterpret_cast <CEikDialog**> ( &iProgressDialog ) ); iProgressDialog->SetCallback( this ); iProgressDialog->PrepareLC( R_RESOURCE_PROGRESS_NOTE ); //從資源文件構造對話框,資源見下面的定義 iProgressInfo = iProgressDialog->GetProgressInfoL(); iProgressInfo->SetFinalValue( aMaxValue ); //設置進度條的最大值(結束值) iProgressDialog->RunLD(); //更新進度條 iProgressInfo->IncrementAndDraw( aStep ); //結束進度條 iProgressDialog->ProcessFinishedL(); delete iProgressDialog; RESOURCE DIALOG R_RESOURCE_PROGRESS_NOTE //進度條對話框資源 { flags = EAknProgressNoteFlags; buttons = R_AVKON_SOFTKEYS_CANCEL; items = { DLG_LINE { type = EAknCtNote; id = EMagicBoxCtrlIdProgressNote; control = AVKON_NOTE { layout = EProgressLayout; singular_label = "對話框中顯示的文字"; plural_label = "download"; imagefile = AVKON_BMPFILE_NAME; //第二版中 圖標文件爲 #define AVKON_BMPFILE_NAME "z://system//data//avkon.mbm" imageid = EMbmAvkonQgn_note_sml; //這兩項可更改顯示不同圖標 imagemask = EMbmAvkonQgn_note_sml_mask; }; } }; }
等待對話框要用到的類:
CAknGlobalNote
頭文件:aknglobalnote.h
lib:aknnotify.lib eiksrv.lib
使用方法:
Code:
//顯示等待對話框 CAknGlobalNote* globalNote = CAknGlobalNote::NewL(); CleanupStack::PushL( globalNote ); TInt iWaitNoteId = globalNote->ShowNoteL( EAknGlobalWaitNote, _L("對話框中顯示的文字") ); CleanupStack::PopAndDestroy(); //結束等待對話框 CAknGlobalNote * note = CAknGlobalNote::NewL(); CleanupStack::PushL( note ); note->CancelNoteL( iWaitNoteId ); CleanupStack::PopAndDestroy();
CAknGlobalNote類除了顯示等待對話框外還可顯示多種類型的全局對話框,具體類型可通過ShowNoteL的第一個參數指定,可能的類型如下:
Code:
enum TAknGlobalNoteType { EAknGlobalInformationNote = 1, EAknGlobalWarningNote, EAknGlobalConfirmationNote, EAknGlobalErrorNote, EAknGlobalChargingNote, EAknGlobalWaitNote, EAknGlobalPermanentNote, EAknGlobalNotChargingNote, EAknGlobalBatteryFullNote, EAknGlobalBatteryLowNote, EAknGlobalRechargeBatteryNote, EAknCancelGlobalNote, EAknGlobalTextNote };
詢問對話框用到的類:
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 = "對話框中顯示的文字"; }; } }; }
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);
這裏用到的類是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; };
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( ¶Format, 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; }
Code:
TKeyResponse CMobileGuardSetKeyContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType ) { return iGKeyEd->OfferKeyEventL( aKeyEvent, aType ); }