各种资源的定义 |
各种资源的定义 一、最基本的定义格式 /* Copyright (c) 2002, Nokia. All rights reserved */ NAME HELL //资源的ID。在一个项目内保证无重复名称 #include <eikon.rh> //必须的一些内部结构和常量的定义 #include <eikon.rsg> //必须的一些内部结构和常量的定义 #include <avkon.rh> //必须的一些内部结构和常量的定义 #include <avkon.rsg> //必须的一些内部结构和常量的定义 #include "HelloWorld.hrh" //自定义的一些内部结构和常量的定义 // --------------------------------------------------------- // 以下两个不许在任何程序中做任何修改 // This resource should be empty. RESOURCE RSS_SIGNATURE { } // Default Document Name RESOURCE TBUF r_default_document_name { buf=""; } // --------------------------------------------------------- //标识菜单和快捷键的资源ID RESOURCE EIK_APP_INFO { menubar = r_helloworld_menubar; cba = R_AVKON_SOFTKEYS_OPTIONS_EXIT; } // --------------------------------------------------------- // 定义菜单 RESOURCE MENU_BAR r_helloworld_menubar { titles = { MENU_TITLE {menu_pane = r_helloworld_menu;} }; } // --------------------------------------------------------- // 定义子菜单 RESOURCE MENU_PANE r_helloworld_menu { items = { MENU_ITEM {command = EHelloWorldCommand1; txt = "Hello";}, //如果有子菜单,那么加入cascade = r_aknexlist_item_menu;这里 // RESOURCE MENU_PANE r_aknexlist_item_menu MENU_ITEM {command = EAknSoftkeyExit; txt = "Exit";} }; } /*定义了字符串资源。虽然这里是小写。但是在程序中引用时必须全部大写。这个和symbian的编译器相关。他把rss的资源串编译到<SDK_installation_directory>\include路径下,成为rsg文件。而CPP实际上#include的是这个rsg文件。*/ RESOURCE TBUF32 r_hewb_command1_text { buf=qtn_hewb_command1_text; } RESOURCE TBUF32 r_hewb_caption_string { buf=qtn_hewb_caption_string; } // End of File 二、关于对话框的定义: 1、 定义一个对话框资源 //构造方式: CMmssSendDialog* iSendDialog = new ( ELeave ) CMmssSendDialog; iSendDialog->SetMopParent( this ); iSendDialog->ExecuteLD( R_MMSSEND_DIALOG ); //------------------------------------------------------------------------------------------- RESOURCE DIALOG r_mmssend_dialog { flags = EEikDialogFlagNoDrag | // 无法拖曳 EEikDialogFlagNoTitleBar | //无标题栏 EEikDialogFlagFillAppClientRect | //将应用程序客户区填满 EEikDialogFlagCbaButtons | //使用CBA按钮 EEikDialogFlagModeless; //不接受按钮事件 //以上可以参见SDK :Developer Library ? API Reference ? C++ API reference ? UIKLAFGT buttons = R_AVKON_SOFTKEYS_OPTIONS_EXIT; form = r_mmssend_form; } // --------------------------------------------------------- //默认的单行显示模式 // --------------------------------------------------------- //可以设置为double行显示 RESOURCE FORM r_mmssend_form { flags = EEikFormEditModeOnly | EEikFormUseDoubleSpacedFormat; //Specify a style of form optionally. The default setting is single line display. //1、EEikFormUseDoubleSpacedFormat : Double line display. //2、EEikFormHideEmptyFields : To make empty data fields Invisible. //3、EEikFormShowBitmaps : To display a bitmap on a label. //4、EEikFormEditModeOnly : To display the form in edit mode only. items = { DLG_LINE { type = EEikCtEdwin; //是一个编辑文本框 Editor window //实际上这个是枚举类型,可参看SDK: //Developer Library ? API Reference ? C++ API reference ? UIKLAFGT ? UIKLAFGT Resource Constants ? TEikStockControls prompt = qtn_mmssend_recipient_prompt;// 这个控件的label显示的字符串 id = EMmsRecipientEditor; control = EDWIN { flags = EEikEdwinNoHorizScrolling | EEikEdwinResizable; width = qtn_mmssend_recipient_width; maxlength = qtn_mmssend_recipient_maxlenght; default_input_mode = EAknEditorNumericInputMode;//数字输入模式 }; }, DLG_LINE { type = EEikCtEdwin; prompt = qtn_mmssend_subject_prompt; id = EMmsSubjectEditor; control = EDWIN { flags = EEikEdwinNoHorizScrolling | EEikEdwinResizable; width = qtn_mmssend_subject_width; maxlength = qtn_mmssend_subject_maxlenght; default_input_mode = EAknEditorTextInputMode;//文本输入模式 }; } }; } 三、定义AVKON_VIEW: 该类相当于新的view函数。 构造函数的承载 BaseConstructL( R_AKNEXLIST_VIEW_COLUMNVIEW ); //--------------------------资源----------------------------------------------------- RESOURCE AVKON_VIEW r_aknexlist_view_columnview { menubar = r_aknexlist_menubar_main; hotkeys = r_aknexlist_hotkeys; } 四、定义LISTBOX: 构造LISTBOX: 1) resourceId = R_AKNEXLIST_MENULIST_SINGLE_NUMBER_HEADING; //可以用祖先 CEikFormattedCellListBox* iListBox;在类中先申明该对象。调用的使用可以根据需要创建需要的派生类。 listBox = new(ELeave)CAknSingleStyleListBox(); listBox->SetContainerWindowL( parent); TResourceReader reader; CEikonEnv::Static()->CreateResourceReaderLC(reader, aResourceId); listBox->SetObserver(observer); listBox->ConstructFromResourceL( reader ); CleanupStack::PopAndDestroy(); // resource stuffs. 2) CEikColumnListBox* iColListBox; CEikFormattedCellListBox* iForListBox; iColListBox = new (ELeave) CAknSingleStyleListBox(); iForListBox = new (ELeave) CAknDoubleGraphicStyleListBox(); iColListBox->SetContainerWindowL( *this ); iForListBox->SetContainerWindowL( *this ); //从资源文件中生成LISTBOX TResourceReader reader; CEikonEnv::Static()->CreateResourceReaderLC( reader, R_TEST_SINGLE); iColListBox->ConstructFromResourceL( reader ); CEikonEnv::Static()->CreateResourceReaderLC( reader, R_TEST_DOUBLE); iForListBox->ConstructFromResourceL( reader ); //设置SCROLLBAR iColListBox->CreateScrollBarFrameL( ETrue ); iColListBox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto ); iForListBox->CreateScrollBarFrameL( ETrue ); iForListBox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto ); //适合窗口大小 iColListBox->SetRect(Rect()); iForListBox->SetRect(Rect()); //激活 iColListBox->ActivateL(); iForListBox->ActivateL(); //--------------------------样式一览参观----------------------------------------------------------- // CAknDoubleStyleListBox //CAknDoubleNumberStyleListBox(); //CAknDoubleLargeStyleListBox() //CAknDoubleStyleListBox(); //CAknDoubleLargeStyleListBox(); //-----------------listbox属性------------------------------------------------------- RESOURCE LISTBOX r_aknexlist_menulist_single_number_heading { array_id = r_aknexlist_item_single_number_heading; flags = EAknListBoxMenuList; } RESOURCE ARRAY r_aknexlist_item_single_number_heading { items = { LBUF { txt = “item1”; }, LBUF { txt = ”item2”; }, LBUF { txt = ”item3”; }, LBUF { txt = ”item4”; }, LBUF { txt = ”item5”; }, LBUF { txt = ”item6”; } LBUF { txt = ”item7”; } }; } 五、定义Tedit: CEikLabel* iLabel2;//定义标签 CEikEdwin* iEdwin;//定义edit. CEikGlobalTextEditor* iGTextEd;//定义基本上同edit --------------------资源------------------------------------------ RESOURCE GTXTED r_aknexeditor_view1_gtexted { flags = EAknEditorFlagDefault; width = qnn_aknexeditor_view1_gtexted_width; height = qnn_aknexeditor_view1_gtexted_height; numlines = qnn_aknexeditor_view1_gtexted_numlines; textlimit= qnn_aknexeditor_view1_gtexted_textlimit; fontcontrolflags = EGulFontControlAll; fontnameflags = EGulNoSymbolFonts; } ---------------------------------------------------------------------- iCoeEnv->ReadResource( text, R_AKNEXEDITOR_VIEW1_LABEL1); ------------------------------资源------------------------------------------------------- RESOURCE TBUF32 r_aknexeditor_view1_label1 { buf = qtn_aknexeditor_label_edwin; } -------------------------------------------------------------------------------------------------- iLabel2 = new ( ELeave ) CEikLabel; iLabel2->SetContainerWindowL( *this ); //设置附着的容器 iLabel2->SetTextL( text ); iLabel2->SetExtent( GTEXTED_LABEL_POS, iLabel1->MinimumSize() ); TResourceReader reader; iCoeEnv->CreateResourceReaderLC( reader, R_AKNEXEDITOR_VIEW1_EDWIN ); //将资源数据读入 iEdwin = new ( ELeave ) CEikEdwin; iEdwin->SetContainerWindowL( *this );//设置附着的容器 iEdwin->ConstructFromResourceL( reader ); //将资源和iEdwin关联。 iEdwin ->SetExtent( position, iEdwin ->MinimumSize() ); // 其中TPoint position;设置主要的控件位置 // 以下是设置情况 Edwins iEdwins->SetAknEditorCase( EAknEditorUpperCase ); //->SetAknEditorCase( EAknEditorLowerCase ); //->SetAknEditorCase( EAknEditorTextCase ); --------------------------资源---------------------------------------------------------------------- RESOURCE EDWIN r_aknexeditor_view1_edwin { flags = EAknEditorFlagDefault; width = qnn_aknexeditor_view1_edwin_width; lines= qnn_aknexeditor_view1_edwin_height; maxlength = qnn_aknexeditor_view1_edwin_maxlength; } ------------------------------------------------------------------------------------------------------------ CleanupStack::PopAndDestroy(); // Resource reader iEdwin->SetExtent( EDWIN_POS, iEdwin->MinimumSize() ); iEdwin->SetFocus( ETrue );//设置控件的焦点。 六、字符串数组类: CDesCArrayFlat* items = iCoeEnv->ReadDesCArrayResourceL( R_AKNEXEDITOR_VIEW5_LABELS ); CleanupStack::PushL( items ); ---------------------------资源定义--------------------------------------------------------- RESOURCE ARRAY r_aknexeditor_view5_labels { items = { LBUF { txt = qtn_aknexeditor_view5_label1; }, LBUF { txt = qtn_aknexeditor_view5_label2; }, LBUF { txt = qtn_aknexeditor_view5_label3; }, LBUF { txt = qtn_aknexeditor_view5_label4; }, LBUF { txt = qtn_aknexeditor_view5_label5; }, LBUF { txt = qtn_aknexeditor_view5_label6; } }; } 七、如何控制多个面版(view) 1、 CAknNavigationControlContainer* iNaviPane; CAknTabGroup* iTabGroup; CAknNavigationDecorator* iDecoratedTabGroup; CAknTitlePane* iTitlePane; CAknExEditorScenarioManager* iScenarioManager; TUid iCurrentViewId; 2、CEikStatusPane *sp = StatusPane(); iTitlePane = static_cast<CAknTitlePane*>( sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) ); iNaviPane = ( CAknNavigationControlContainer* ) sp->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ); iDecoratedTabGroup = iNaviPane->ResourceDecorator(); if ( iDecoratedTabGroup ) { iTabGroup = ( CAknTabGroup* ) iDecoratedTabGroup->DecoratedControl(); } // 屏幕管理器 iScenarioManager = new ( ELeave ) CAknExEditorScenarioManager; 3、各种VIEW后,加入调用 // Create and add views. CAknExEditorView1* view1 = new ( ELeave ) CAknExEditorView1; CleanupStack::PushL( view1 ); view1->ConstructL(); CleanupStack::Pop(); // view1 AddViewL( view1 ); //加入调用 CAknExEditorView4* view4 = new ( ELeave ) CAknExEditorView4; CleanupStack::PushL( view4 ); view4->ConstructL(); CleanupStack::Pop(); // view4 AddViewL( view4 ); //加入调用 4、激活一个VIEW: ActivateViewL( view1->Id() ); //-----------------------实现-------------------------- void CAknExEditorAppUi::ActivateViewL( TUid aViewId ) { ActivateLocalViewL( aViewId ); iCurrentViewId = aViewId; TBuf<KTitleBufLength> newTitle; iScenarioManager->GetTitle( aViewId, &newTitle ); iTitlePane->SetTextL( newTitle ); } 5、实现前翻、后翻 void CAknExEditorAppUi::ActivateNextViewL() { TUid viewId = iScenarioManager->NextViewTo( iCurrentViewId ); if ( viewId == TUid::Uid( KScenarioNotFound ) ) { viewId = iScenarioManager->FirstViewId(); } ActivateViewL( viewId ); } // ---------------------------------------------------- // CAknExEditorAppUi::ActivatePrevViewL() // Activates previous view. // ( other items were commented in a header ). // ---------------------------------------------------- // void CAknExEditorAppUi::ActivatePrevViewL() { TUid viewId = iScenarioManager->PrevViewTo( iCurrentViewId ); if ( viewId == TUid::Uid( KScenarioNotFound ) ) { viewId = iScenarioManager->LastViewId(); } ActivateViewL( viewId ); } 八、MCoeControlObserver接口: 这个接口可以直接派生出VIEW的容器类 class CAknExEditorContainer : public CCoeControl, McoeControlObserver 这种容器类可以在view的容器上嵌入相关的edit、label等组件。而不是用 GC来直接操作这些界面元素。 在view类中如何调用: private: void DoActivateL( const TVwsViewId& /*aPrevViewId*/, TUid /*aCustomMessageId*/, const TDesC8& /*aCustomMessage*/ );//创建容器类 void DoDeactivate();//删除容器类 CAknExEditorContainer1* iContainer;//-------------------implentment--------------------- void CAknExEditorView1::DoActivateL( const TVwsViewId& /*aPrevViewId*/, TUid /*aCustomMessageId*/, const TDesC8& /*aCustomMessage*/ ) { iContainer = new ( ELeave ) CAknExEditorContainer1; iContainer->SetMopParent( this ); iContainer->ConstructL( ClientRect() ); AppUi()->AddToStackL( *this, iContainer ); } void CAknExEditorView1::DoDeactivate() { if ( iContainer ) { AppUi()->RemoveFromStack( iContainer ); } delete iContainer; iContainer = NULL; } |