hello everyone,
I am freshman.I wrote a project(3*3 grids),which there is one icon in each grid.
Now I got a problem,I can not display icons in 3*3 grids.
my code as follow:
I new CSimpleGridGamesGrid in "MainContainer.cpp":
void CMainContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();

// Construct the grid
iGamesGrid = new (ELeave)CSimpleGridGamesGrid;
iGamesGrid->SetContainerWindowL(*this);
iGamesGrid->ConstructL(R_SIMPLEGRID_GAMES_GRID, R_ICON_FILE_NAME);

// Observe the grid
iGamesGrid->SetListBoxObserver(this);

SetRect(aRect);
ActivateL();
}
and "MySimpleGridGamesGrid.cpp" as follow:
void CMySimpleGridGamesGrid::ConstructL(TInt aGridResource, TInt aIconFileResource)
{
// Construct the grid from resource
TResourceReader reader;
CEikonEnv::Static()->CreateResourceReaderLC(reader, aGridResource);
ConstructFromResourceL(reader);
CleanupStack::PopAndDestroy(); // reader

// Set up the icons
SetupGridIconsL (aIconFileResource);

// Draw the grid
SizeChanged();
}


void CMySimpleGridGamesGrid::SetupGridIconsL(TInt aIconFileResource)
{
// Get the name of the file containing the icons
HBufC* iconFileName;
iconFileName = StringLoader::LoadLC(aIconFileResource); // Pushes iconFileName onto the Cleanup Stack.

// Create an array of icons, reading them from the file
CArrayPtr<CGulIcon>* icons = new(ELeave) CAknIconArray(KNumberOfIcons);
CleanupStack::PushL(icons);
icons->AppendL(iEikonEnv->CreateIconL(*iconFileName, EMbmMymygridGolf));
icons->AppendL(iEikonEnv->CreateIconL(*iconFileName, EMbmMymygridSnap));
icons->AppendL(iEikonEnv->CreateIconL(*iconFileName, EMbmMymygridClock));
icons->AppendL(iEikonEnv->CreateIconL(*iconFileName, EMbmMymygridAces));
icons->AppendL(iEikonEnv->CreateIconL(*iconFileName, EMbmMymygridHearts));
icons->AppendL(iEikonEnv->CreateIconL(*iconFileName, EMbmMymygridRummy));
icons->AppendL(iEikonEnv->CreateIconL(*iconFileName, EMbmMymygridPoker));
icons->AppendL(iEikonEnv->CreateIconL(*iconFileName, EMbmMymygridHmd));
icons->AppendL(iEikonEnv->CreateIconL(*iconFileName, EMbmMymygridBmd));
CleanupStack::Pop(icons);
CleanupStack::PopAndDestroy(iconFileName);

ItemDrawer()->FormattedCellData()->SetIconArray(icons); // passing ownership of icons

}

void CMySimpleGridGamesGrid::SetMyGrid()
{
// Setup text foreground and background colours to default
AknListBoxLayouts::SetupStandardGrid(*this);


// // Get local copies of data we will need
CFormattedCellListBoxItemDrawer* itemDrawer = this->ItemDrawer();
TInt cellWidth = ColumnWidth();
TInt cellHeight = ItemHeight();


// // Set up graphics subcells
AknListBoxLayouts::SetupFormGfxCell(*this, //the grid
itemDrawer, // the grid's drawer
0, // index of the graphic within item strings
0, // left position
0, // top position
0, // right - unused
0, // bottom - unused
cellWidth, // width of graphic
KGraphicsHeight, // height of graphic
TPoint (0, 0), // start position
TPoint (0 , 0)); // end position

// // Set up text subcells
const CFont* KFont = LatinBold12();
TInt baseline = cellHeight - KFont->DescentInPixels() - 1;

AknListBoxLayouts::SetupFormTextCell(*this, // the grid
itemDrawer, // the grid's drawer
1, // index of text within item strings
KFont, // the font for the text
KTextColor, // the color of the text - N.B. although commented out in the header file, this is still used!
0, // left margin
0, // right margin - unused
baseline, // Baseline
cellWidth, // text width (would need to take margin into account if set, i.e. - lm)
CGraphicsContext::ECenter, // Alignment
TPoint (0, 0), // start position
TPoint(cellWidth, cellHeight)); // end position
}

void CMySimpleGridGamesGrid::SizeChanged()
{
CAknGrid::SizeChanged();
SetMyGrid();
}
and RSS file as follow:
// RESOURCE DEFINITIONS
RESOURCE RSS_SIGNATURE
{
}

RESOURCE TBUF r_default_document_name
{
buf="MYMY";
}

RESOURCE EIK_APP_INFO
{
menubar = r_menubar_view_main;
cba = R_AVKON_SOFTKEYS_OPTIONS_EXIT;
}


RESOURCE AVKON_VIEW r_view_main
{
menubar = r_menubar_view_main;
cba = R_AVKON_SOFTKEYS_OPTIONS_EXIT;
}
RESOURCE MENU_BAR r_menubar_view_main
{
titles =
{
MENU_TITLE {menu_pane = r_menupane_view_main;}
};
}


RESOURCE MENU_PANE r_menupane_view_main
{
items =
{
MENU_ITEM
{
command = ECommand1;
txt = qtn_command1;
},
MENU_ITEM
{
command = ECommand2;
txt = qtn_command2;
},
MENU_ITEM
{
command = EHelp;
txt = qtn_help;
},
MENU_ITEM
{
command = EAbout;
txt = qtn_about;
},
MENU_ITEM
{
command = EAknSoftkeyExit;
txt = qtn_exit;
}
};
}

RESOURCE DIALOG r_about_query_dialog
{
flags = EGeneralQueryFlags | EEikDialogFlagNoBorder | EEikDialogFlagNoShadow;
buttons = R_AVKON_SOFTKEYS_OK_EMPTY;
items=
{
DLG_LINE
{
type = EAknCtPopupHeadingPane;
id = EAknMessageQueryHeaderId;
itemflags = EEikDlgItemNonFocusing;
control = AVKON_HEADING
{
};
},
DLG_LINE
{
type = EAknCtMessageQuery;
id = EAknMessageQueryContentId;
control = AVKON_MESSAGE_QUERY
{
};
}
};
}


RESOURCE TBUF32 r_caption_string { buf=qtn_caption_string; }
RESOURCE TBUF32 r_about_dialog_title { buf=qtn_about_dialog_title; }
RESOURCE TBUF r_about_dialog_text { buf=qtn_about_dialog_text; }
RESOURCE TBUF r_command1_text { buf=qtn_command1_text; }


RESOURCE LOCALISABLE_APP_INFO r_localisable_app_info
{
short_caption = qtn_caption_string;
caption_and_icon =
CAPTION_AND_ICON_INFO
{
caption = qtn_caption_string;

number_of_icons = 1;
icon_file = "\\resource\\apps\\MyMyGrid_0xEB952DA2.mif";
};
}

RESOURCE GRID R_SIMPLEGRID_GAMES_GRID
{
array_id = r_simplegrid_games_grid_items;
flags = EAknListBoxSelectionGrid;
style=r_simplegrid_games_grid_style;
}

RESOURCE ARRAY r_simplegrid_games_grid_items
{
items =
{
LBUF
{
txt = qtn_grid_item1_text;
},
LBUF
{
txt = qtn_grid_item2_text;
},
LBUF
{
txt = qtn_grid_item3_text;
},
LBUF
{
txt = qtn_grid_item4_text;
},
LBUF
{
txt = qtn_grid_item5_text;
},
LBUF
{
txt = qtn_grid_item6_text;
},
LBUF
{
txt = qtn_grid_item7_text;
},
LBUF
{
txt = qtn_grid_item8_text;
},
LBUF
{
txt = qtn_grid_item9_text;
}

};
}



RESOURCE GRID_STYLE r_simplegrid_games_grid_style
{
layoutflags=EAknGridHorizontalOrientation| EAknGridLeftToRight | EAknGridTopToBottom;
primaryscroll= EAknGridFollowsItemsAndLoops; // horizontal scroll
secondaryscroll=EAknGridFollowsItemsAndLoops; // vertical scroll
itemsinprimaryorient=3; // number of items horizontally per screen
itemsinsecondaryorient=3; // number of items vertically per screen
gapwidth=0;
gapheight=0;
height = 80;
width = 78;
}

RESOURCE TBUF r_icon_file_name
{
buf = "\\system\\apps\\MyMyGrid.mbm";
}
and mmp file as follow:
TARGET MyMyGrid_0xEB952DA2.exe
TARGETTYPE exe
UID 0x100039CE 0xEB952DA2

SOURCEPATH ..\src
SOURCE MyMyGrid.cpp
SOURCE MyMyGridApplication.cpp
SOURCE MyMyGridAppView.cpp
SOURCE MyMyGridAppUi.cpp
SOURCE MyMyGridDocument.cpp

SOURCEPATH ..\data

START RESOURCE MyMyGrid.rss
HEADER
TARGET MyMyGrid_0xEB952DA2
TARGETPATH resource\apps
END //RESOURCE

START RESOURCE MyMyGrid_reg.rss
TARGET MyMyGrid_0xEB952DA2_reg
TARGETPATH \private\10003a3f\apps
END //RESOURCE

USERINCLUDE ..\inc
USERINCLUDE ..\help

SYSTEMINCLUDE \epoc32\include

LIBRARY euser.lib
LIBRARY apparc.lib
LIBRARY cone.lib
LIBRARY eikcore.lib
LIBRARY avkon.lib
LIBRARY commonengine.lib
LIBRARY efsrv.lib
LIBRARY estor.lib
LIBRARY aknnotify.lib
LIBRARY hlplch.lib
LIBRARY eikcoctl.lib
LIBRARY gdi.lib
LIBRARY egul.lib
LIBRARY aknicon.lib

LANG SC

VENDORID 0
SECUREID 0xEB952DA2
CAPABILITY ReadUserData

#ifdef ENABLE_ABIV2_MODE
DEBUGGABLE_UDEBONLY
#endif
// End of File
SOURCEPATH ..\src
SOURCE CMyMainView.cpp MyMainContainer.cpp MySimpleGridGamesGrid.cpp
START BITMAP MyMyGrid.mbm
HEADER
TARGETPATH \system\apps
SOURCEPATH ..\gfx
SOURCE c24 Golf.bmp snap.bmp clock.bmp aces.bmp Hearts.bmp Rummy.bmp Poker.bmp hmd.bmp bmd.bmp
END