Thread: Creating dynamic menu items

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

    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.

  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,195
    Thanks, after a bit of tweaking that worked fine.

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, 09:38 AM
  2. using app config to create a dynamic menu
    By dana_cc1 in forum C# Programming
    Replies: 2
    Last Post: 04-29-2008, 11:29 PM
  3. Showing & hiding menu items
    By geek@02 in forum Windows Programming
    Replies: 1
    Last Post: 06-07-2005, 06:28 PM
  4. Menu Item Caption - /a for right aligned Accelerator?
    By JasonD in forum Windows Programming
    Replies: 6
    Last Post: 06-25-2003, 11:14 AM
  5. Enabling menu items
    By chomper in forum Windows Programming
    Replies: 2
    Last Post: 02-20-2002, 08:43 PM