Hi,
I am currently developping a software where items that will be inserted
into a graphical widget ListCtrl are first defined in static array as
shown below :
enum TUiContext
{
EUiContextMain = 0,
EUiContextSched ule,
EUiContextSetti ngs,
EUiContextSubsc ription,
EUiContextCount
};
typedef struct
{
int TextId;
int ImgId;
int Param;
int nOptInfo;
TCHAR szImgName[MAX_PATH];
} ListInfo_t, *LPListInfo_t;
ListInfo_t CMainView::ms_l istInfo_Main[]=
{
// String ID, Img, Param = CmdBarId Enabled ImgName
{ IDS_MENU_BACKUP , 0, IDM_MENU_CMDBAR _BACKUP, TRUE, _T( "" ) },
{ IDS_MENU_SCHEDU LE, 2, IDM_MENU_CMDBAR _OPTIONS, TRUE, _T( "" ) },
{ IDS_MENU_RESTOR E, 1, IDM_MENU_CMDBAR _RESTORE, TRUE, _T( "" ) },
{ IDS_MENU_MANAGE _SUBSCRIPTION, -1, IDM_MENU_MANAGE _SUBSCRIPTION,
TRUE, _T( "Menu_Account_M anage.png" ) },
};
ListInfo_t CMainView::ms_l istInfo_Options[]=
{
// String ID, Img, Param = CmdBarId
{ IDS_MENU_FREQUE NCY, 0, IDM_MENU_SCHEDU LER, TRUE, _T( "" ) },
{ IDS_MENU_CONTEN T, 1, IDM_MENU_SELECT DB, TRUE, _T( "" ) },
};
....
Actually in functions of some parameters, some items won't be inserted
and the field nOptInfo is used for this purpose. If this field equals 1
it will be inserted into the List.
So I have a method called InitResources that check the config parameters
and update nOptInfo for each array.
Once this has been done, I build a vector as shown below :
void CMainView::Init Resources()
{
std::vector<Lis tInfo_tvecListI nfo;
std::map<TUiCon text, std::vector<Lis tInfo_t listMap;
// Test config parameters and update nOptInfo
...
//$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$ $$$$$$$$$$$
// Now build vector from ms_listInfo_Mai n
//$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$ $$$$$$$$$$$
vecListInfo.cle ar()
for (int i = 0; i < _countof(ms_lis tInfo_Main); i++)
{
if (ms_listInfo_Ma in[i].nOptInfo == TRUE){
vecListInfo.pus h_back(ms_listI nfo_Main[i]);
}
}
listMap[ EUiContextMain ] = vecListInfo;
//$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$ $$$$$$$$$$$
// Now build vector from ms_listInfo_Opt ions
//$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$ $$$$$$$$$$$
vecListInfo.cle ar()
for (int i = 0; i < _countof(ms_lis tInfo_Options); i++)
{
if (ms_listInfo_Op tions[i].nOptInfo == TRUE){
vecListInfo.pus h_back(ms_listI nfo_Options[i]);
}
}
listMap[ EUiContextSched ule] = vecListInfo;
...
}
I find all this code very ugly and I would like to suggestion to improve
it. I am doing all this because I am switching between different
graphical context and before to do it I save the index of current
selected item in my ListCtrl.
I am currently developping a software where items that will be inserted
into a graphical widget ListCtrl are first defined in static array as
shown below :
enum TUiContext
{
EUiContextMain = 0,
EUiContextSched ule,
EUiContextSetti ngs,
EUiContextSubsc ription,
EUiContextCount
};
typedef struct
{
int TextId;
int ImgId;
int Param;
int nOptInfo;
TCHAR szImgName[MAX_PATH];
} ListInfo_t, *LPListInfo_t;
ListInfo_t CMainView::ms_l istInfo_Main[]=
{
// String ID, Img, Param = CmdBarId Enabled ImgName
{ IDS_MENU_BACKUP , 0, IDM_MENU_CMDBAR _BACKUP, TRUE, _T( "" ) },
{ IDS_MENU_SCHEDU LE, 2, IDM_MENU_CMDBAR _OPTIONS, TRUE, _T( "" ) },
{ IDS_MENU_RESTOR E, 1, IDM_MENU_CMDBAR _RESTORE, TRUE, _T( "" ) },
{ IDS_MENU_MANAGE _SUBSCRIPTION, -1, IDM_MENU_MANAGE _SUBSCRIPTION,
TRUE, _T( "Menu_Account_M anage.png" ) },
};
ListInfo_t CMainView::ms_l istInfo_Options[]=
{
// String ID, Img, Param = CmdBarId
{ IDS_MENU_FREQUE NCY, 0, IDM_MENU_SCHEDU LER, TRUE, _T( "" ) },
{ IDS_MENU_CONTEN T, 1, IDM_MENU_SELECT DB, TRUE, _T( "" ) },
};
....
Actually in functions of some parameters, some items won't be inserted
and the field nOptInfo is used for this purpose. If this field equals 1
it will be inserted into the List.
So I have a method called InitResources that check the config parameters
and update nOptInfo for each array.
Once this has been done, I build a vector as shown below :
void CMainView::Init Resources()
{
std::vector<Lis tInfo_tvecListI nfo;
std::map<TUiCon text, std::vector<Lis tInfo_t listMap;
// Test config parameters and update nOptInfo
...
//$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$ $$$$$$$$$$$
// Now build vector from ms_listInfo_Mai n
//$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$ $$$$$$$$$$$
vecListInfo.cle ar()
for (int i = 0; i < _countof(ms_lis tInfo_Main); i++)
{
if (ms_listInfo_Ma in[i].nOptInfo == TRUE){
vecListInfo.pus h_back(ms_listI nfo_Main[i]);
}
}
listMap[ EUiContextMain ] = vecListInfo;
//$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$ $$$$$$$$$$$
// Now build vector from ms_listInfo_Opt ions
//$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$ $$$$$$$$$$$
vecListInfo.cle ar()
for (int i = 0; i < _countof(ms_lis tInfo_Options); i++)
{
if (ms_listInfo_Op tions[i].nOptInfo == TRUE){
vecListInfo.pus h_back(ms_listI nfo_Options[i]);
}
}
listMap[ EUiContextSched ule] = vecListInfo;
...
}
I find all this code very ugly and I would like to suggestion to improve
it. I am doing all this because I am switching between different
graphical context and before to do it I save the index of current
selected item in my ListCtrl.
Comment