Creating dynamic menu items

This is a discussion on Creating dynamic menu items within the Windows Programming forums, part of the Platform Specific Boards category; Im learning to make dynamic menues for an application I'm writing, btu this code from petzold doesnt create the proper ...

  1. #1
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189

    Creating dynamic menu items

    Im learning to make dynamic menues for an application I'm writing, btu this code from petzold doesnt create the proper result. Perhaps I'm missing something.

    Code:
    hMenu = CreateMenu();
    hMenuPopup = CreateMenu();
    pOption = (UINT_PTR)&Option;
    Option = 40001;
    AppendMenu(hMenuPopup , MF_STRING , 40001 , "E&xit");
    Option = (UINT)hMenuPopup;
    AppendMenu(hMenu , MF_POPUP , pOption , "&File");
    SetMenu(hwnd , hMenu);
    



    all it creates is the File menu, but with no popup item in it.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  2. #2
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    hMenuPopup needs to be a handle to CreatePopupMenu(). Otherwise the way you have it now it creates two menus, one File and one Exit, and you are only showing the File one.
    Code:
    HMENU hMenu = CreateMenu();
    HMENU hSubMenu = CreatePopupMenu();
    
    AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File");
    
    AppendMenu(hSubMenu, MF_STRING, FILE_EXIT, "E&xit       Alt+F4");

  3. #3
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    Thanks, after a bit of tweaking that worked fine.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 10:38 AM
  2. using app config to create a dynamic menu
    By dana_cc1 in forum C# Programming
    Replies: 2
    Last Post: 04-30-2008, 12:29 AM
  3. Showing & hiding menu items
    By geek@02 in forum Windows Programming
    Replies: 1
    Last Post: 06-07-2005, 07:28 PM
  4. Menu Item Caption - /a for right aligned Accelerator?
    By JasonD in forum Windows Programming
    Replies: 6
    Last Post: 06-25-2003, 12:14 PM
  5. Enabling menu items
    By chomper in forum Windows Programming
    Replies: 2
    Last Post: 02-20-2002, 08:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21