这几天想把程序变的漂亮点,就把以前的listbox改动成了CAknDoubleLargeStyleListBox类型,该动了以后的程序变动不是很大,就是改变了程序安装字符串格式的方法 和 加载了 svg图片下面就具体说下加载svg图片的步骤:
1:把svg 图片放在工程下面的gfx 目录下面
2:在group目录下面添加文件SvgImages.miflist 里面加上图片信息
/c16,1 ../gfx/qgn_menu_ATestList2.svg
/c16,1 ../gfx/todisk.svg
/c16,1 ../gfx/tonet.svg
/c16,1 ../gfx/todisk2.svg
/c16,1 ../gfx/todisk3.svg
/c16,1 ../gfx/todisk4.svg
/c16,1 ../gfx/todisk5.svg
/c16,1 ../gfx/tonet1.svg
/c16,1 ../gfx/tonet2.svg
/c16,1 ../gfx/tonet3.svg
/c16,1 ../gfx/tonet4.svg
/c16,1 ../gfx/todiskcopy.svg
2:把程序下面的xxxxx.mk改动下改成包含SvgImages.miflist文件的
RESOURCE :
mifconv $(ICONTARGETFILENAME) /h$(HEADERFILENAME) /FSvgImages.miflist
4:在inf目录下面加上mk文件,这样就可以进行编译
5:PRJ_PLATFORMS
WINSCW ARMV5 GCCE
PRJ_EXPORTS
PRJ_MMPFILES
gnumakefile icons_aif_scalable_dc.mk
ATestList2.mmp
6:在pkg文件里加上文件打包信息"$(EPOCROOT)epoc32/data/z/resource/apps/ATestList2_aif.mif" -"!:/resource/apps/ATestList2_aif.mif"
"$(EPOCROOT)epoc32/data/z/resource/apps/ATestList2.mbm" -"!:/resource/apps/ATestList2.mbm"
不加的话在模拟器上调试是没有任何问题的,但是到了真机上就会出现问题,找不到资源了 我因为这个原因找了一天半 比较郁闷
以上步骤以后我们就可以正常使用了: 下面是关键的类:
bld.inf:
PRJ_PLATFORMS WINSCW ARMV5 GCCE PRJ_EXPORTS PRJ_MMPFILES gnumakefile icons_aif_scalable_dc.mk ATestList2.mmp
Icons_aif_scalable_dc.mk 文件:
# ============================================================================ # Name : Icons_aif_scalable_dc.mk # Part of : ATestList2 # # Description: # # ============================================================================ ifeq (WINS,$(findstring WINS, $(PLATFORM))) ZDIR=$(EPOCROOT)epoc32/release/$(PLATFORM)/$(CFG)/Z else ZDIR=$(EPOCROOT)epoc32/data/z endif # ---------------------------------------------------------------------------- # TODO: Configure these # ---------------------------------------------------------------------------- TARGETDIR=$(ZDIR)/resource/apps ICONTARGETFILENAME=$(TARGETDIR)/ATestList2_aif.mif HEADERDIR=$(EPOCROOT)epoc32/include HEADERFILENAME=$(HEADERDIR)/ATestList2_aif.mbg ICONDIR=../gfx do_nothing : @rem do_nothing MAKMAKE : do_nothing BLD : do_nothing CLEAN : do_nothing LIB : do_nothing CLEANLIB : do_nothing # ---------------------------------------------------------------------------- # TODO: Configure these. # # NOTE 1: DO NOT DEFINE MASK FILE NAMES! They are included automatically by # MifConv if the mask detph is defined. # # NOTE 2: Usually, source paths should not be included in the bitmap # definitions. MifConv searches for the icons in all icon directories in a # predefined order, which is currently /s60/icons, /s60/bitmaps2. # The directory /s60/icons is included in the search only if the feature flag # __SCALABLE_ICONS is defined. # ---------------------------------------------------------------------------- # NOTE: if you have JUSTINTIME enabled for your S60 3rd FP1 or newer SDK # and this command crashes, consider adding "/X" to the command line. # See <http://forum.nokia.com/document/Forum_Nokia_Technical_Library_v1_35/contents/FNTL/Build_process_fails_at_mif_file_creation_in_S60_3rd_Ed_FP1_SDK.htm> # ---------------------------------------------------------------------------- RESOURCE : mifconv $(ICONTARGETFILENAME) /h$(HEADERFILENAME) /FSvgImages.miflist FREEZE : do_nothing SAVESPACE : do_nothing RELEASABLES : @echo $(ICONTARGETFILENAME) FINAL : do_nothing
SvgImages.miflist
/c16,1 ../gfx/qgn_menu_ATestList2.svg /c16,1 ../gfx/todisk.svg /c16,1 ../gfx/tonet.svg /c16,1 ../gfx/todisk2.svg /c16,1 ../gfx/todisk3.svg /c16,1 ../gfx/todisk4.svg /c16,1 ../gfx/todisk5.svg /c16,1 ../gfx/tonet1.svg /c16,1 ../gfx/tonet2.svg /c16,1 ../gfx/tonet3.svg /c16,1 ../gfx/tonet4.svg /c16,1 ../gfx/todiskcopy.svg
ATestList2.pkg
; ATestList2.pkg ; This is an auto-generated PKG file by Carbide. ; This file uses variables specific to Carbide builds that will not work ; on command-line builds. If you want to use this generated PKG file from the ; command-line tools you will need to modify the variables with the appropriate ; values: $(EPOCROOT), $(PLATFORM), $(TARGET) ; Also, the resource file entries should be changed to match the language ; used in the build. For example, if building for LANGUAGE_01, change the file ; extensions .rsc to .r01. ; ;Language - standard language definitions &EN ; standard SIS file header #{"ATestList2"},(0xEE8D6E0D),1,0,0 ;Localised Vendor name %{"Vendor-EN"} ;Unique Vendor name :"Vendor" ;Supports Series 60 v 3.0 [0x101F7961], 0, 0, 0, {"Series60ProductID"} ;Files to install ;You should change the source paths to match that of your environment ;<source> <destination> "$(EPOCROOT)Epoc32/release/$(PLATFORM)/$(TARGET)/ATestList2.exe" -"!:/sys/bin/ATestList2.exe" "$(EPOCROOT)Epoc32/data/z/resource/apps/ATestList2.r01" -"!:/resource/apps/ATestList2.r01" "$(EPOCROOT)Epoc32/data/z/private/10003a3f/apps/ATestList2_reg.r01" -"!:/private/10003a3f/import/apps/ATestList2_reg.r01" "$(EPOCROOT)epoc32/data/z/resource/apps/ATestList2_aif.mif" -"!:/resource/apps/ATestList2_aif.mif" "$(EPOCROOT)epoc32/data/z/resource/apps/ATestList2.mbm" -"!:/resource/apps/ATestList2.mbm" ; Add any installation notes if applicable ;"ATestList2.txt" -"!:/private/0xEE8D6E0D/ATestList2.txt"
文件使用类:ATestList2ListBox.h
/* ======================================================================== Name : ATestList2ListBox.h Author : SMSExampleParser Copyright : Your copyright notice Description : ======================================================================== */ #ifndef ATESTLIST2LISTBOX_H #define ATESTLIST2LISTBOX_H // [[[ begin generated region: do not modify [Generated Includes] #include <coecntrl.h> #include <akniconutils.h> #include <gulicon.h> // ]]] end generated region [Generated Includes] // [[[ begin [Event Handler Includes] // ]]] end [Event Handler Includes] // [[[ begin generated region: do not modify [Generated Forward Declarations] class MEikCommandObserver; class CAknDoubleLargeStyleListBox; class CEikTextListBox; // ]]] end generated region [Generated Forward Declarations] /** * Container class for ATestList2ListBox * * @class CATestList2ListBox ATestList2ListBox.h */ class CATestList2ListBox : public CCoeControl { public: // constructors and destructor CATestList2ListBox(); static CATestList2ListBox* NewL( const TRect& aRect, const CCoeControl* aParent, MEikCommandObserver* aCommandObserver ); static CATestList2ListBox* NewLC( const TRect& aRect, const CCoeControl* aParent, MEikCommandObserver* aCommandObserver ); void ConstructL( const TRect& aRect, const CCoeControl* aParent, MEikCommandObserver* aCommandObserver ); virtual ~CATestList2ListBox(); public: // from base class CCoeControl TInt CountComponentControls() const; CCoeControl* ComponentControl( TInt aIndex ) const; TKeyResponse OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType ); void HandleResourceChange( TInt aType ); protected: // from base class CCoeControl void SizeChanged(); private: // from base class CCoeControl void Draw( const TRect& aRect ) const; private: void InitializeControlsL(); void LayoutControls(); CCoeControl* iFocusControl; MEikCommandObserver* iCommandObserver; // [[[ begin generated region: do not modify [Generated Methods] public: static void AddListBoxItemL( CEikTextListBox* aListBox, const TDesC& aString ); static RArray< TInt >* GetSelectedListBoxItemsLC( CEikTextListBox* aListBox ); static void DeleteSelectedListBoxItemsL( CEikTextListBox* aListBox ); CAknDoubleLargeStyleListBox* ListBox(); static void CreateListBoxItemL( TDes& aBuffer, TInt aIconIndex, const TDesC& aMainText, const TDesC& aSecondaryText ); void AddListBoxResourceArrayItemL( TInt aResourceId, TInt aIconIndex ); void SetupListBoxIconsL(); static CGulIcon* LoadAndScaleIconL( const TDesC& aFileName, TInt aBitmapId, TInt aMaskId, TSize* aSize, TScaleMode aScaleMode , TInt i); TBool HandleMarkableListCommandL( TInt aCommand ); // ]]] end generated region [Generated Methods] // [[[ begin generated region: do not modify [Generated Type Declarations] public: // ]]] end generated region [Generated Type Declarations] // [[[ begin generated region: do not modify [Generated Instance Variables] private: CAknDoubleLargeStyleListBox* iListBox; // ]]] end generated region [Generated Instance Variables] // [[[ begin [Overridden Methods] protected: // ]]] end [Overridden Methods] // [[[ begin [User Handlers] protected: // ]]] end [User Handlers] public: enum TControls { // [[[ begin generated region: do not modify [Generated Contents] EListBox, // ]]] end generated region [Generated Contents] // add any user-defined entries here... ELastControl }; enum TListBoxImages { // [[[ begin generated region: do not modify [Generated Enums] EListBoxAtestlist2List_iconIndex = 0, EListBoxAtestlist2List_iconIndex1, EListBoxAtestlist2List_iconIndex2, EListBoxAtestlist2List_iconIndex3, EListBoxAtestlist2List_iconIndex4, EListBoxAtestlist2List_iconIndex5, EListBoxAtestlist2List_iconIndex6, EListBoxAtestlist2List_iconIndex7, EListBoxAtestlist2List_iconIndex8, EListBoxAtestlist2List_iconIndex9, EListBoxAtestlist2List_iconIndex10, EListBoxFirstUserImageIndex // ]]] end generated region [Generated Enums] }; }; #endif // ATESTLIST2LISTBOX_H
ATestList2ListBox.cpp
/* ======================================================================== Name : ATestList2ListBox.cpp Author : SMSExampleParser Copyright : Your copyright notice Description : ======================================================================== */ // [[[ begin generated region: do not modify [Generated System Includes] #include <barsread.h> #include <stringloader.h> #include <aknlists.h> #include <eikenv.h> #include <akniconarray.h> #include <eikclbd.h> #include <aknviewappui.h> #include <eikappui.h> #include <ATestList2.mbg> #include <ATestList2_aif.mbg>//swb 真有啊 天啊 #include <ATestList2.rsg> // ]]] end generated region [Generated System Includes] // [[[ begin generated region: do not modify [Generated User Includes] #include "ATestList2ListBox.h" #include "ATestList2ListBoxView.h" #include "ATestList2.hrh" // ]]] end generated region [Generated User Includes] // [[[ begin generated region: do not modify [Generated Constants] _LIT( KATestList2File, "//resource//apps//ATestList2.mbm" ); _LIT(KATestList2SVGFile, "//resource//apps//ATestList2_aif.mbm"); // ]]] end generated region [Generated Constants] /** * First phase of Symbian two-phase construction. Should not * contain any code that could leave. */ CATestList2ListBox::CATestList2ListBox() { // [[[ begin generated region: do not modify [Generated Contents] iListBox = NULL; // ]]] end generated region [Generated Contents] } /** * Destroy child controls. */ CATestList2ListBox::~CATestList2ListBox() { // [[[ begin generated region: do not modify [Generated Contents] delete iListBox; iListBox = NULL; // ]]] end generated region [Generated Contents] } /** * Construct the control (first phase). * Creates an instance and initializes it. * Instance is not left on cleanup stack. * @param aRect bounding rectangle * @param aParent owning parent, or NULL * @param aCommandObserver command observer * @return initialized instance of CATestList2ListBox */ CATestList2ListBox* CATestList2ListBox::NewL( const TRect& aRect, const CCoeControl* aParent, MEikCommandObserver* aCommandObserver ) { CATestList2ListBox* self = CATestList2ListBox::NewLC( aRect, aParent, aCommandObserver ); CleanupStack::Pop( self ); return self; } /** * Construct the control (first phase). * Creates an instance and initializes it. * Instance is left on cleanup stack. * @param aRect The rectangle for this window * @param aParent owning parent, or NULL * @param aCommandObserver command observer * @return new instance of CATestList2ListBox */ CATestList2ListBox* CATestList2ListBox::NewLC( const TRect& aRect, const CCoeControl* aParent, MEikCommandObserver* aCommandObserver ) { CATestList2ListBox* self = new ( ELeave ) CATestList2ListBox(); CleanupStack::PushL( self ); self->ConstructL( aRect, aParent, aCommandObserver ); return self; } /** * Construct the control (second phase). * Creates a window to contain the controls and activates it. * @param aRect bounding rectangle * @param aCommandObserver command observer * @param aParent owning parent, or NULL */ void CATestList2ListBox::ConstructL( const TRect& aRect, const CCoeControl* aParent, MEikCommandObserver* aCommandObserver ) { if ( aParent == NULL ) { CreateWindowL(); } else { SetContainerWindowL( *aParent ); } iFocusControl = NULL; iCommandObserver = aCommandObserver; InitializeControlsL(); SetRect( aRect ); ActivateL(); // [[[ begin generated region: do not modify [Post-ActivateL initializations] // ]]] end generated region [Post-ActivateL initializations] } /** * Return the number of controls in the container (override) * @return count */ TInt CATestList2ListBox::CountComponentControls() const { return ( int ) ELastControl; } /** * Get the control with the given index (override) * @param aIndex Control index [0...n) (limited by #CountComponentControls) * @return Pointer to control */ CCoeControl* CATestList2ListBox::ComponentControl( TInt aIndex ) const { // [[[ begin generated region: do not modify [Generated Contents] switch ( aIndex ) { case EListBox: return iListBox; } // ]]] end generated region [Generated Contents] // handle any user controls here... return NULL; } /** * Handle resizing of the container. This implementation will lay out * full-sized controls like list boxes for any screen size, and will layout * labels, editors, etc. to the size they were given in the UI designer. * This code will need to be modified to adjust arbitrary controls to * any screen size. */ void CATestList2ListBox::SizeChanged() { CCoeControl::SizeChanged(); LayoutControls(); // [[[ begin generated region: do not modify [Generated Contents] // ]]] end generated region [Generated Contents] } // [[[ begin generated function: do not modify /** * Layout components as specified in the UI Designer */ void CATestList2ListBox::LayoutControls() { iListBox->SetExtent( TPoint( 0, 0 ), iListBox->MinimumSize() ); } // ]]] end generated function /** * Handle key events. */ TKeyResponse CATestList2ListBox::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType ) { // [[[ begin generated region: do not modify [Generated Contents] if ( aKeyEvent.iCode == EKeyLeftArrow || aKeyEvent.iCode == EKeyRightArrow ) { // Listbox takes all events even if it doesn't use them return EKeyWasNotConsumed; } // ]]] end generated region [Generated Contents] if ( iFocusControl != NULL && iFocusControl->OfferKeyEventL( aKeyEvent, aType ) == EKeyWasConsumed ) { return EKeyWasConsumed; } return CCoeControl::OfferKeyEventL( aKeyEvent, aType ); } // [[[ begin generated function: do not modify /** * Initialize each control upon creation. */ void CATestList2ListBox::InitializeControlsL()//这个就是初始化控件的方法 { iListBox = new ( ELeave ) CAknDoubleLargeStyleListBox;//初始化listBox iListBox->SetContainerWindowL( *this );//设置list的 { TResourceReader reader;//一个资源解析器 iEikonEnv->CreateResourceReaderLC( reader, R_ATEST_LIST2_LIST_BOX_LIST_BOX );//读取资源 iListBox->ConstructFromResourceL( reader );//构造资源 CleanupStack::PopAndDestroy(); // reader internal state } // the listbox owns the items in the list and will free them iListBox->Model()->SetOwnershipType( ELbmOwnsItemArray );//这个是说list拥有item并且负责处理他们 // setup the icon array so graphics-style boxes work//设置list的图标 SetupListBoxIconsL(); // add list items AddListBoxResourceArrayItemL( R_ATEST_LIST2_LIST_BOX_LISTBOX_ITEM1, EListBoxAtestlist2List_iconIndex ); AddListBoxResourceArrayItemL( R_ATEST_LIST2_LIST_BOX_LISTBOX_ITEM2, EListBoxAtestlist2List_iconIndex1 ); AddListBoxResourceArrayItemL( R_ATEST_LIST2_LIST_BOX_LISTBOX_ITEM3, EListBoxAtestlist2List_iconIndex2 ); AddListBoxResourceArrayItemL( R_ATEST_LIST2_LIST_BOX_LISTBOX_ITEM4, EListBoxAtestlist2List_iconIndex3 ); AddListBoxResourceArrayItemL( R_ATEST_LIST2_LIST_BOX_LISTBOX_ITEM5, EListBoxAtestlist2List_iconIndex4 ); AddListBoxResourceArrayItemL( R_ATEST_LIST2_LIST_BOX_LISTBOX_ITEM6, EListBoxAtestlist2List_iconIndex5 ); AddListBoxResourceArrayItemL( R_ATEST_LIST2_LIST_BOX_LISTBOX_ITEM7, EListBoxAtestlist2List_iconIndex6 ); AddListBoxResourceArrayItemL( R_ATEST_LIST2_LIST_BOX_LISTBOX_ITEM8, EListBoxAtestlist2List_iconIndex7 ); AddListBoxResourceArrayItemL( R_ATEST_LIST2_LIST_BOX_LISTBOX_ITEM9, EListBoxAtestlist2List_iconIndex8 ); AddListBoxResourceArrayItemL( R_ATEST_LIST2_LIST_BOX_LISTBOX_ITEM10, EListBoxAtestlist2List_iconIndex9 ); AddListBoxResourceArrayItemL( R_ATEST_LIST2_LIST_BOX_LISTBOX_ITEM11, EListBoxAtestlist2List_iconIndex10 ); iListBox->SetFocus( ETrue );// 获得交点 iFocusControl = iListBox; } // ]]] end generated function /** * Handle global resource changes, such as scalable UI or skin events (override) */ void CATestList2ListBox::HandleResourceChange( TInt aType ) { CCoeControl::HandleResourceChange( aType ); SetRect( iAvkonViewAppUi->View( TUid::Uid( EATestList2ListBoxViewId ) )->ClientRect() ); // [[[ begin generated region: do not modify [Generated Contents] // ]]] end generated region [Generated Contents] } /** * Draw container contents. */ void CATestList2ListBox::Draw( const TRect& aRect ) const { // [[[ begin generated region: do not modify [Generated Contents] CWindowGc& gc = SystemGc(); gc.Clear( aRect ); // ]]] end generated region [Generated Contents] } // [[[ begin generated function: do not modify /** * Add a list box item to a list. */ void CATestList2ListBox::AddListBoxItemL( CEikTextListBox* aListBox, const TDesC& aString ) { CTextListBoxModel* model = aListBox->Model();//得到listbox的model CDesCArray* itemArray = static_cast< CDesCArray* > ( model->ItemTextArray() );//得到ilistbox 的数组 itemArray->AppendL( aString );//添加本数组 aListBox->HandleItemAdditionL();//当listbox的model改变的时候 用这个功能来改变他们内在的这个状态 } // ]]] end generated function // [[[ begin generated function: do not modify /** * Get the array of selected item indices, with respect to the list model. * The array is sorted in ascending order. * The array should be destroyed with two calls to CleanupStack::PopAndDestroy(), * the first with no argument (referring to the internal resource) and the * second with the array pointer. * @return newly allocated array, which is left on the cleanup stack; * or NULL for empty list. */ RArray< TInt >* CATestList2ListBox::GetSelectedListBoxItemsLC( CEikTextListBox* aListBox ) { CAknFilteredTextListBoxModel* model = static_cast< CAknFilteredTextListBoxModel *> ( aListBox->Model() ); if ( model->NumberOfItems() == 0 ) return NULL; // get currently selected indices const CListBoxView::CSelectionIndexArray* selectionIndexes = aListBox->SelectionIndexes(); TInt selectedIndexesCount = selectionIndexes->Count(); if ( selectedIndexesCount == 0 ) return NULL; // copy the indices and sort numerically RArray<TInt>* orderedSelectedIndices = new (ELeave) RArray< TInt >( selectedIndexesCount ); // push the allocated array CleanupStack::PushL( orderedSelectedIndices ); // dispose the array resource CleanupClosePushL( *orderedSelectedIndices ); // see if the search field is enabled CAknListBoxFilterItems* filter = model->Filter(); if ( filter != NULL ) { // when filtering enabled, translate indices back to underlying model for ( TInt idx = 0; idx < selectedIndexesCount; idx++ ) { TInt filteredItem = ( *selectionIndexes ) [ idx ]; TInt actualItem = filter->FilteredItemIndex ( filteredItem ); orderedSelectedIndices->InsertInOrder( actualItem ); } } else { // the selection indices refer directly to the model for ( TInt idx = 0; idx < selectedIndexesCount; idx++ ) orderedSelectedIndices->InsertInOrder( ( *selectionIndexes ) [ idx ] ); } return orderedSelectedIndices; } // ]]] end generated function // [[[ begin generated function: do not modify /** * Delete the selected item or items from the list box. */ void CATestList2ListBox::DeleteSelectedListBoxItemsL( CEikTextListBox* aListBox ) { CAknFilteredTextListBoxModel* model = static_cast< CAknFilteredTextListBoxModel *> ( aListBox->Model() ); if ( model->NumberOfItems() == 0 ) return; RArray< TInt >* orderedSelectedIndices = GetSelectedListBoxItemsLC( aListBox ); if ( !orderedSelectedIndices ) return; // Delete selected items from bottom up so indices don't change on us CDesCArray* itemArray = static_cast< CDesCArray* > ( model->ItemTextArray() ); TInt currentItem = 0; for ( TInt idx = orderedSelectedIndices->Count(); idx-- > 0; ) { currentItem = ( *orderedSelectedIndices )[ idx ]; itemArray->Delete ( currentItem ); } // dispose the array resources CleanupStack::PopAndDestroy(); // dispose the array pointer CleanupStack::PopAndDestroy( orderedSelectedIndices ); // refresh listbox's cursor now that items are deleted AknListBoxUtils::HandleItemRemovalAndPositionHighlightL( aListBox, currentItem, ETrue ); } // ]]] end generated function // [[[ begin generated function: do not modify /** * Get the listbox. */ CAknDoubleLargeStyleListBox* CATestList2ListBox::ListBox() { return iListBox; } // ]]] end generated function // [[[ begin generated function: do not modify /** * Create a list box item with the given column values. */ void CATestList2ListBox::CreateListBoxItemL( TDes& aBuffer, TInt aIconIndex, const TDesC& aMainText, const TDesC& aSecondaryText ) { _LIT ( KStringHeader, "%d/t%S/t%S" ); aBuffer.Format( KStringHeader(), aIconIndex, &aMainText, &aSecondaryText );//字符串格式是这样的 图片位置,上面位置 下面位置 } // ]]] end generated function // [[[ begin generated function: do not modify /** * Add an item to the list by reading the text items from the array resource * and setting a single image property (if available) from an index * in the list box's icon array. * @param aResourceId id of an ARRAY resource containing the textual * items in the columns * @param aIconIndex the index in the icon array, or -1 */ void CATestList2ListBox::AddListBoxResourceArrayItemL( TInt aResourceId, TInt aIconIndex ) { CDesCArray* array = iCoeEnv->ReadDesCArrayResourceL( aResourceId );//通过资源ID来读取资源 CleanupStack::PushL( array ); // This is intended to be large enough, but if you get // a USER 11 panic, consider reducing string sizes. TBuf<512> listString; //这个是调整格式 CreateListBoxItemL( listString, aIconIndex, ( *array ) [ 0 ], ( *array ) [ 1 ] );//得到每一个item //这个是添加格式 AddListBoxItemL( iListBox, listString ); CleanupStack::PopAndDestroy( array ); } // ]]] end generated function // [[[ begin generated function: do not modify /** * Set up the list's icon array. */ void CATestList2ListBox::SetupListBoxIconsL() { CArrayPtr< CGulIcon >* icons = NULL; //定义图象数组 icons = new (ELeave) CAknIconArray( 11 );//初始化图象 CleanupStack::PushL( icons ); CGulIcon* icon;//创建图标对象 // for EListBoxAtestlist2List_iconIndex for(int i=0;i<11;i++) { icon = LoadAndScaleIconL( KATestList2File, EMbmAtestlist2List_icon, EMbmAtestlist2List_icon_mask, NULL, EAspectRatioPreserved,i );//创建图标 CleanupStack::PushL( icon ); icons->AppendL( icon ); CleanupStack::Pop( icon ); } CleanupStack::Pop( icons ); if ( icons != NULL ) { iListBox->ItemDrawer()->ColumnData()->SetIconArray( icons );//设置图片的图标数组 这样在以后的地方就好用了 } } /** * Handle commands relating to markable lists. */ TBool CATestList2ListBox::HandleMarkableListCommandL( TInt aCommand ) { return EFalse; } // ]]] end generated function // [[[ begin generated function: do not modify /** * This routine loads and scales a bitmap or icon. * * @param aFileName the MBM or MIF filename * @param aBitmapId the bitmap id * @param aMaskId the mask id or -1 for none * @param aSize the TSize for the icon, or NULL to use real size * @param aScaleMode one of the EAspectRatio* enums when scaling * */ CGulIcon* CATestList2ListBox::LoadAndScaleIconL( const TDesC& aFileName, TInt aBitmapId, TInt aMaskId, TSize* aSize, TScaleMode aScaleMode,TInt i) { //icon = LoadAndScaleIconL( // KATestList2File, EMbmAtestlist2List_icon, EMbmAtestlist2List_icon_mask, // NULL, EAspectRatioPreserved ); CFbsBitmap* bitmap; CFbsBitmap* mask; if(i==0) { AknIconUtils::CreateIconL( bitmap, mask, KATestList2SVGFile, EMbmAtestlist2_aifTodisk, EMbmAtestlist2_aifTodisk_mask ); } if(i==1) { AknIconUtils::CreateIconL( bitmap, mask, KATestList2SVGFile, EMbmAtestlist2_aifTonet, EMbmAtestlist2_aifTonet_mask ); } if(i==2) { AknIconUtils::CreateIconL( bitmap, mask, KATestList2SVGFile, EMbmAtestlist2_aifTodisk2, EMbmAtestlist2_aifTonet2_mask ); } if(i==3) { AknIconUtils::CreateIconL( bitmap, mask, KATestList2SVGFile, EMbmAtestlist2_aifTodisk3, EMbmAtestlist2_aifTodisk3_mask ); } if(i==4) { AknIconUtils::CreateIconL( bitmap, mask, KATestList2SVGFile, EMbmAtestlist2_aifTodisk4, EMbmAtestlist2_aifTodisk4_mask ); } if(i==5) { AknIconUtils::CreateIconL( bitmap, mask, KATestList2SVGFile, EMbmAtestlist2_aifTodisk5, EMbmAtestlist2_aifTodisk5_mask ); } if(i==6) { AknIconUtils::CreateIconL( bitmap, mask, KATestList2SVGFile, EMbmAtestlist2_aifTonet1, EMbmAtestlist2_aifTonet1_mask ); } if(i==7) { AknIconUtils::CreateIconL( bitmap, mask, KATestList2SVGFile, EMbmAtestlist2_aifTonet2, EMbmAtestlist2_aifTonet2_mask ); } if(i==8) { AknIconUtils::CreateIconL( bitmap, mask, KATestList2SVGFile, EMbmAtestlist2_aifTonet3, EMbmAtestlist2_aifTonet3_mask ); } if(i==9) { AknIconUtils::CreateIconL( bitmap, mask, KATestList2SVGFile, EMbmAtestlist2_aifTonet4, EMbmAtestlist2_aifTonet4_mask ); } if(i==10) { AknIconUtils::CreateIconL( bitmap, mask, KATestList2SVGFile, EMbmAtestlist2_aifTodisk3, EMbmAtestlist2_aifTodisk3_mask ); } // AknIconUtils::CreateIconL( bitmap, mask, aFileName, aBitmapId, aMaskId ); TSize size; if ( aSize == NULL ) { // Use size from the image header. In case of SVG, // we preserve the image data for a while longer, since ordinarily // it is disposed at the first GetContentDimensions() or SetSize() call. AknIconUtils::PreserveIconData( bitmap );//得到图象数据 AknIconUtils::GetContentDimensions( bitmap, size );//得到上下文的尺寸 这里就改变了size 晕 不知道如何作到的 } else { size = *aSize;//NULL } AknIconUtils::SetSize( bitmap, size, aScaleMode );//添加图象 AknIconUtils::SetSize( mask, size, aScaleMode );//添加mask EAspectRatioPreserved if ( aSize == NULL ) { AknIconUtils::DestroyIconData( bitmap ); } return CGulIcon::NewL( bitmap, mask );// } // ]]] end generated function
资源文件ATestList2ListBox.rssi
/* ======================================================================== Name : ATestList2ListBox.rssi Author : SMSExampleParser Copyright : Your copyright notice Description : ======================================================================== */ #include "ATestList2ListBox.loc" RESOURCE AVKON_VIEW r_atest_list2_list_box_atest_list2_list_box_view { cba = R_AVKON_SOFTKEYS_OPTIONS_EXIT; menubar = r_atest_list2_list_box_options_menu; toolbar = 0; } RESOURCE MENU_BAR r_atest_list2_list_box_options_menu { } RESOURCE STATUS_PANE_APP_MODEL r_atest_list2_list_box_status_pane { panes = { SPANE_PANE { id = EEikStatusPaneUidTitle; type = EAknCtTitlePane; resource = r_atest_list2_list_box_title_resource; } }; } RESOURCE TITLE_PANE r_atest_list2_list_box_title_resource { txt = STR_ATestList2ListBoxView_3; } RESOURCE LISTBOX r_atest_list2_list_box_list_box { flags = EAknListBoxSelectionList; } RESOURCE ARRAY r_atest_list2_list_box_listbox_item1 { items = { LBUF { txt = STR_ATestList2ListBoxView_4; }, LBUF { txt = STR_ATestList2ListBoxView_5; } }; } RESOURCE ARRAY r_atest_list2_list_box_listbox_item2 { items = { LBUF { txt = STR_ATestList2ListBoxView_6; }, LBUF { txt = STR_ATestList2ListBoxView_7; } }; } RESOURCE ARRAY r_atest_list2_list_box_listbox_item3 { items = { LBUF { txt = STR_ATestList2ListBoxView_8; }, LBUF { txt = STR_ATestList2ListBoxView_9; } }; } RESOURCE ARRAY r_atest_list2_list_box_listbox_item4 { items = { LBUF { txt = STR_ATestList2ListBoxView_10; }, LBUF { txt = STR_ATestList2ListBoxView_11; } }; } RESOURCE ARRAY r_atest_list2_list_box_listbox_item5 { items = { LBUF { txt = STR_ATestList2ListBoxView_12; }, LBUF { txt = STR_ATestList2ListBoxView_13; } }; } RESOURCE ARRAY r_atest_list2_list_box_listbox_item6 { items = { LBUF { txt = STR_ATestList2ListBoxView_14; }, LBUF { txt = STR_ATestList2ListBoxView_15; } }; } RESOURCE ARRAY r_atest_list2_list_box_listbox_item7 { items = { LBUF { txt = STR_ATestList2ListBoxView_16; }, LBUF { txt = STR_ATestList2ListBoxView_17; } }; } RESOURCE ARRAY r_atest_list2_list_box_listbox_item8 { items = { LBUF { txt = STR_ATestList2ListBoxView_18; }, LBUF { txt = STR_ATestList2ListBoxView_19; } }; } RESOURCE ARRAY r_atest_list2_list_box_listbox_item9 { items = { LBUF { txt = STR_ATestList2ListBoxView_20; }, LBUF { txt = STR_ATestList2ListBoxView_21; } }; } RESOURCE ARRAY r_atest_list2_list_box_listbox_item10 { items = { LBUF { txt = STR_ATestList2ListBoxView_22; }, LBUF { txt = STR_ATestList2ListBoxView_23; } }; } RESOURCE ARRAY r_atest_list2_list_box_listbox_item11 { items = { LBUF { txt = STR_ATestList2ListBoxView_24; }, LBUF { txt = STR_ATestList2ListBoxView_25; } }; }