Menus overlapping each other
-
Hi folks I've created a class that create dynamic menus this is the code of the method that creates hte menus:
void Menu::InsertNewMenuItem(HMENU hParentMenu, HWND hwWindowOwner, unsigned int uiMenuID, unsigned int uiMenuBehavior, char * cMenuText) { int iSize = m_uiMenuID.size(); m_uiMenuID.push_back(uiMenuID); m_uiBehavior.push_back(uiMenuBehavior); m_cMenuName.push_back(cMenuText); if(iSize <= 0) { AppendMenu(hParentMenu, m_uiBehavior[0], m_uiMenuID[0], m_cMenuName[0]); m_hSubMenu = CreateMenu(); } else { AppendMenu(m_hSubMenu, m_uiBehavior[iSize], m_uiMenuID[iSize], m_cMenuName[iSize]); AppendMenu(hParentMenu, m_uiBehavior[0], (unsigned int)m_hSubMenu, m_cMenuName[0]); } SetMenu(hwWindowOwner, hParentMenu); }
This code is in my callbackLRESULT CALLBACK WindowProcedure(HWND hwnd, UINT uiMessage, WPARAM wParam, LPARAM lParam) { HMENU hMainMenu = CreateMenu(); char * cMainName = "Principal1"; char * cName1 = "Menu 1"; char * cName2 = "Menu 2"; char * cName3 = "Menu 3"; char * cName4 = "Menu 4"; char * cName5 = "Menu 5"; char * cName6 = "Principal2"; char * cName7 = "Menu 7"; char * cName8 = "Menu 8"; char * cName9 = "Menu 9"; char * cName10 = "Menu 10"; int iIDS[] = {6000, 6001, 6002, 6003, 6004, 6005, 6006, 6007, 6008, 6009, 6010}; switch(uiMessage) { case WM_CREATE: { theMenu = new Menu(); theMenu2 = new Menu(); break; } case WM_CHAR: { switch(wParam) { case 'a': { theMenu->InsertNewMenuItem(hMainMenu, hwnd, iIDS[0], MF_STRING|MF_POPUP, cMainName); DrawMenuBar(hwnd); break; } case 's': { theMenu2->InsertNewMenuItem(hMainMenu, hwnd, iIDS[1], MF_STRING, cName1); DrawMenuBar(hwnd); break; } .....
The problem that I have is: I have 2 menus. When I call the method pressing "a", a submenu is inserted in the first menu. When I call the method pressing "s" to insert a new submenu in the OTHER menu, the first one is overlapped with the first. The same is valid when I insert a submenu in the second menu and insert a valid a submenu in the first menu. What going on? It's very strange. Am I clear enough for you? -
Hi folks I've created a class that create dynamic menus this is the code of the method that creates hte menus:
void Menu::InsertNewMenuItem(HMENU hParentMenu, HWND hwWindowOwner, unsigned int uiMenuID, unsigned int uiMenuBehavior, char * cMenuText) { int iSize = m_uiMenuID.size(); m_uiMenuID.push_back(uiMenuID); m_uiBehavior.push_back(uiMenuBehavior); m_cMenuName.push_back(cMenuText); if(iSize <= 0) { AppendMenu(hParentMenu, m_uiBehavior[0], m_uiMenuID[0], m_cMenuName[0]); m_hSubMenu = CreateMenu(); } else { AppendMenu(m_hSubMenu, m_uiBehavior[iSize], m_uiMenuID[iSize], m_cMenuName[iSize]); AppendMenu(hParentMenu, m_uiBehavior[0], (unsigned int)m_hSubMenu, m_cMenuName[0]); } SetMenu(hwWindowOwner, hParentMenu); }
This code is in my callbackLRESULT CALLBACK WindowProcedure(HWND hwnd, UINT uiMessage, WPARAM wParam, LPARAM lParam) { HMENU hMainMenu = CreateMenu(); char * cMainName = "Principal1"; char * cName1 = "Menu 1"; char * cName2 = "Menu 2"; char * cName3 = "Menu 3"; char * cName4 = "Menu 4"; char * cName5 = "Menu 5"; char * cName6 = "Principal2"; char * cName7 = "Menu 7"; char * cName8 = "Menu 8"; char * cName9 = "Menu 9"; char * cName10 = "Menu 10"; int iIDS[] = {6000, 6001, 6002, 6003, 6004, 6005, 6006, 6007, 6008, 6009, 6010}; switch(uiMessage) { case WM_CREATE: { theMenu = new Menu(); theMenu2 = new Menu(); break; } case WM_CHAR: { switch(wParam) { case 'a': { theMenu->InsertNewMenuItem(hMainMenu, hwnd, iIDS[0], MF_STRING|MF_POPUP, cMainName); DrawMenuBar(hwnd); break; } case 's': { theMenu2->InsertNewMenuItem(hMainMenu, hwnd, iIDS[1], MF_STRING, cName1); DrawMenuBar(hwnd); break; } .....
The problem that I have is: I have 2 menus. When I call the method pressing "a", a submenu is inserted in the first menu. When I call the method pressing "s" to insert a new submenu in the OTHER menu, the first one is overlapped with the first. The same is valid when I insert a submenu in the second menu and insert a valid a submenu in the first menu. What going on? It's very strange. Am I clear enough for you?The first problem I see is that you're calling
HMENU hMainMenu = CreateMenu();
for every window message, I don't think that is what you're after. You can get your window's menu with
GetMenu()
.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?