Hi,
I want to dynamiccally create a menu. Code is straigtforward and like this:All my datastructures are working correctly. I can see that the AppendMenu() calls get the correct string and UINT.Code:std::vector<CFunction*> funcs = m_pUserGroupFunctions->GetAllFunctions(); int group; CMenu* newMenu; newMenu = new CMenu(); newMenu->CreateMenu(); CMenu* pSubMenu; for(int n = 0 ; n < groupcount ; n++) { pSubMenu = new CMenu(); VERIFY(pSubMenu->CreatePopupMenu()); for (UINT i = 0 ; i < funcs.size() ; i++) { menuNames.Lookup(funcs.at(i)->GetGroupId(),group); if (group == n) pSubMenu->AppendMenu(MF_STRING|MF_OWNERDRAW, funcs.at(i)->GetUint(), (LPCTSTR)funcs.at(i)->GetName()); } newMenu->AppendMenu(MF_POPUP|MF_OWNERDRAW, (UINT) pSubMenu->m_hMenu); }
The problem is that the following statements do not work:
What does work is the GetMenuItemCount, the GetSubMenu and the GetMenuItemCount on the submenus.Code://does not work!! CMenu tMenu; tMenu.Attach(newMenu->m_hMenu); tMenu.GetMenuString (nIndex, m_strBtn, MF_BYPOSITION); tMenu.Detach(); //does not work TCHAR szText[256] ; MENUITEMINFO info; ::memset(&info, 0, sizeof(MENUITEMINFO)); info.cbSize = sizeof(MENUITEMINFO); info.fMask = MIIM_ID | MIIM_TYPE ; info.dwTypeData = szText; info.cch = sizeof(szText); ::GetMenuItemInfo(hMenu, nIndex, TRUE, &info); m_strBtn = CString(szText); //does not work CMenuItemInfo info; info.cbSize = sizeof(CMenuItemInfo); info.dwTypeData = NULL; info.fType = MFT_STRING; info.fMask = MIIM_STRING; ::GetMenuItemInfo(hMenu, nIndex, TRUE, (MENUITEMINFO *) &info); char* lpBuffer; lpBuffer = (char*) malloc(info.cch + 1); info.dwTypeData = lpBuffer; info.cch = info.cch + 1; ::GetMenuItemInfo(hMenu, nIndex, TRUE, (MENUITEMINFO *) &info); m_strBtn = CString(lpBuffer); //some other CMenu methods don't work either
What can be wrong in this code?




Reply With Quote