Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Menus overlapping each other

Menus overlapping each other

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alex Cutovoi
    wrote on last edited by
    #1

    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 callback LRESULT 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?

    M 1 Reply Last reply
    0
    • A Alex Cutovoi

      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 callback LRESULT 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?

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups