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 creation problem

Menus creation problem

Scheduled Pinned Locked Moved C / C++ / MFC
comhelpquestion
3 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 fellows. I created an app that have 2 menus. The code for these menus are below: hMenu1 = CreateMenu(); hMenu2 = CreateMenu(); hSubMenu1 = CreateMenu(); hSubMenu2 = CreateMenu(); unsigned int uiParams[5]; unsigned int uiNums[5]; unsigned int uiSize = 5; char cNames[][256] = {"&Menu", "&Estudo Anatômico", "M&odelo com Transparência", "", "&Sair"}; uiParams[0] = MF_STRING|MF_POPUP; uiParams[1] = uiParams[2] = uiParams[4] = MF_STRING; uiParams[3] = MF_SEPARATOR; uiNums[0] = 0; uiNums[1] = 1; uiNums[2] = 2; uiNums[3] = 3; uiNums[4] = 4; MenuCreator(hMenu1, hSubMenu1, uiParams, uiNums, cNames, uiSize); SetMenu(hwnd, hMenu1); DrawMenuBar(hwnd); char cNames2[][256] = {"&Controles", "&Habilitar/Desabilitar Controles"}; uiParams[0] = MF_STRING|MF_POPUP; uiParams[1] = MF_STRING; uiNums[0] = 5; uiNums[1] = 6; uiSize = 2; MenuCreator(hMenu2, hSubMenu2, uiParams, uiNums, cNames2, uiSize); SetMenu(hwnd, hMenu2); I have a function that create menus dynamically. Here it is: void MenuCreator(HMENU hParentMenu, HMENU hChildMenu, unsigned int uiBehaviors[], unsigned int uiIDItems[], char cNameItems[][256], unsigned int uiSize) { if(hParentMenu == NULL || (hParentMenu == NULL && hChildMenu != NULL)) { MessageBox(NULL, "Menu pai não pode ser nulo", "Erro", MB_OK|MB_ICONERROR); return; } if(hParentMenu != NULL && hChildMenu != NULL) { for(int i = 1 ; i < uiSize ; i++)AppendMenu(hChildMenu, uiBehaviors[i], uiIDItems[i], cNameItems[i]); AppendMenu(hParentMenu, uiBehaviors[0], (unsigned int)hChildMenu, cNameItems[0]); return; } if(hParentMenu != NULL && hChildMenu == NULL) { for(int i = 0 ; i < uiSize ; i++) { AppendMenu(hChildMenu, uiBehaviors[i], uiIDItems[i], cNameItems[i]); } return; } } when I insert the first menu, works fine. When I insert the other, the first menu isn't there, just the second. What I want to do is to have 2 or more menus at the same time, like File|Edit|View. What's going on? Thanks

    A S 2 Replies Last reply
    0
    • A Alex Cutovoi

      Hi fellows. I created an app that have 2 menus. The code for these menus are below: hMenu1 = CreateMenu(); hMenu2 = CreateMenu(); hSubMenu1 = CreateMenu(); hSubMenu2 = CreateMenu(); unsigned int uiParams[5]; unsigned int uiNums[5]; unsigned int uiSize = 5; char cNames[][256] = {"&Menu", "&Estudo Anatômico", "M&odelo com Transparência", "", "&Sair"}; uiParams[0] = MF_STRING|MF_POPUP; uiParams[1] = uiParams[2] = uiParams[4] = MF_STRING; uiParams[3] = MF_SEPARATOR; uiNums[0] = 0; uiNums[1] = 1; uiNums[2] = 2; uiNums[3] = 3; uiNums[4] = 4; MenuCreator(hMenu1, hSubMenu1, uiParams, uiNums, cNames, uiSize); SetMenu(hwnd, hMenu1); DrawMenuBar(hwnd); char cNames2[][256] = {"&Controles", "&Habilitar/Desabilitar Controles"}; uiParams[0] = MF_STRING|MF_POPUP; uiParams[1] = MF_STRING; uiNums[0] = 5; uiNums[1] = 6; uiSize = 2; MenuCreator(hMenu2, hSubMenu2, uiParams, uiNums, cNames2, uiSize); SetMenu(hwnd, hMenu2); I have a function that create menus dynamically. Here it is: void MenuCreator(HMENU hParentMenu, HMENU hChildMenu, unsigned int uiBehaviors[], unsigned int uiIDItems[], char cNameItems[][256], unsigned int uiSize) { if(hParentMenu == NULL || (hParentMenu == NULL && hChildMenu != NULL)) { MessageBox(NULL, "Menu pai não pode ser nulo", "Erro", MB_OK|MB_ICONERROR); return; } if(hParentMenu != NULL && hChildMenu != NULL) { for(int i = 1 ; i < uiSize ; i++)AppendMenu(hChildMenu, uiBehaviors[i], uiIDItems[i], cNameItems[i]); AppendMenu(hParentMenu, uiBehaviors[0], (unsigned int)hChildMenu, cNameItems[0]); return; } if(hParentMenu != NULL && hChildMenu == NULL) { for(int i = 0 ; i < uiSize ; i++) { AppendMenu(hChildMenu, uiBehaviors[i], uiIDItems[i], cNameItems[i]); } return; } } when I insert the first menu, works fine. When I insert the other, the first menu isn't there, just the second. What I want to do is to have 2 or more menus at the same time, like File|Edit|View. What's going on? Thanks

      A Offline
      A Offline
      Alex Cutovoi
      wrote on last edited by
      #2

      Problem solved, I was create 2 main menus. So, when I insert the other main menu it was overlapping the other. I deleted the other main menu and add the items in only 1 main menu

      1 Reply Last reply
      0
      • A Alex Cutovoi

        Hi fellows. I created an app that have 2 menus. The code for these menus are below: hMenu1 = CreateMenu(); hMenu2 = CreateMenu(); hSubMenu1 = CreateMenu(); hSubMenu2 = CreateMenu(); unsigned int uiParams[5]; unsigned int uiNums[5]; unsigned int uiSize = 5; char cNames[][256] = {"&Menu", "&Estudo Anatômico", "M&odelo com Transparência", "", "&Sair"}; uiParams[0] = MF_STRING|MF_POPUP; uiParams[1] = uiParams[2] = uiParams[4] = MF_STRING; uiParams[3] = MF_SEPARATOR; uiNums[0] = 0; uiNums[1] = 1; uiNums[2] = 2; uiNums[3] = 3; uiNums[4] = 4; MenuCreator(hMenu1, hSubMenu1, uiParams, uiNums, cNames, uiSize); SetMenu(hwnd, hMenu1); DrawMenuBar(hwnd); char cNames2[][256] = {"&Controles", "&Habilitar/Desabilitar Controles"}; uiParams[0] = MF_STRING|MF_POPUP; uiParams[1] = MF_STRING; uiNums[0] = 5; uiNums[1] = 6; uiSize = 2; MenuCreator(hMenu2, hSubMenu2, uiParams, uiNums, cNames2, uiSize); SetMenu(hwnd, hMenu2); I have a function that create menus dynamically. Here it is: void MenuCreator(HMENU hParentMenu, HMENU hChildMenu, unsigned int uiBehaviors[], unsigned int uiIDItems[], char cNameItems[][256], unsigned int uiSize) { if(hParentMenu == NULL || (hParentMenu == NULL && hChildMenu != NULL)) { MessageBox(NULL, "Menu pai não pode ser nulo", "Erro", MB_OK|MB_ICONERROR); return; } if(hParentMenu != NULL && hChildMenu != NULL) { for(int i = 1 ; i < uiSize ; i++)AppendMenu(hChildMenu, uiBehaviors[i], uiIDItems[i], cNameItems[i]); AppendMenu(hParentMenu, uiBehaviors[0], (unsigned int)hChildMenu, cNameItems[0]); return; } if(hParentMenu != NULL && hChildMenu == NULL) { for(int i = 0 ; i < uiSize ; i++) { AppendMenu(hChildMenu, uiBehaviors[i], uiIDItems[i], cNameItems[i]); } return; } } when I insert the first menu, works fine. When I insert the other, the first menu isn't there, just the second. What I want to do is to have 2 or more menus at the same time, like File|Edit|View. What's going on? Thanks

        S Offline
        S Offline
        Sachinpatole
        wrote on last edited by
        #3

        The application must call the "DrawMenuBar" function whenever a menu changes, whether or not the menu is in a displayed window.

        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