
Dynamically changing the menu
Hi,
I read some names from tools from the registry and want to place them in the
tools menu. I like to do this at startup time. When I do this in the
OnCreate function from the main frame.
the following function reads the values (using an CRegistry class which is
not relevant here) and adds them to the tools menu.
When I call the function below from a menuitem after the program is started
it works fine. But at startup I call this function from within the OnCreate
function it doesn't work! Any ideas?
Thanks,
Remon
void CMainFrame::CreateToolsMenu()
{
CRegistry Registry;
CString strKey = "Software\\Remon\\Programmers Code Editor\\Tools";
CString strCurrentKey;
CString strMenuValue;
CString strTemp;
CMenu* pMenu = GetMenu()->GetSubMenu(3);
int nIndex = 0;
while (pMenu->DeleteMenu(MF_BYCOMMAND, ID_TOOLS_TOOL1 + nIndex))
nIndex++;
nIndex = 0;
while (1)
{
strCurrentKey.Format("MenuText_%d", nIndex);
if (!Registry.LoadKey(strKey, strCurrentKey, strMenuValue))
break;
if (nIndex == 0)
pMenu->AppendMenu(MF_SEPARATOR);
strTemp.Format("%d ", nIndex + 1);
strMenuValue = "&" + strTemp + strMenuValue + "\tCtrl+" + strTemp;
pMenu->AppendMenu(MF_STRING, ID_TOOLS_TOOL1 + nIndex, strMenuValue);
nIndex++;
}
DrawMenuBar();
Quote:
}