Menu not appearing

This is a discussion on Menu not appearing within the Windows Programming forums, part of the Platform Specific Boards category; I am trying to get a menu working & am following how I did it last time (which worked in ...

  1. #1
    HelpingYouHelpUsHelpUsAll
    Join Date
    Dec 2007
    Location
    In your nightmares
    Posts
    223

    Menu not appearing

    I am trying to get a menu working & am following how I did it last time (which worked in the same compiler) copying it exactly, the menu doesn't appear. I am using Dev-C++

    Here is the function to create the menu:
    Code:
    HMENU CreateMainMenu(HWND hwnd) {
          
          HMENU hMenu, hSubMenu;
          hMenu = CreateMenu();
          hSubMenu = CreatePopupMenu();
          AppendMenu(hSubMenu, MF_STRING, WM_CLOSE, "E&xit\tAlt+F4");
          AppendMenu(hSubMenu, MF_STRING |MF_POPUP, (UINT)hSubMenu, "&File");
          hSubMenu = CreatePopupMenu();
          AppendMenu(hSubMenu, MF_STRING | MF_UNCHECKED, 1002, "Show Postfix notation");
          AppendMenu(hSubMenu, MF_STRING |MF_POPUP, (UINT)hSubMenu, "Functions");
          SetMenu(hwnd, hMenu);
          return hMenu;
    }
    & have called it just before the call to ShowWindow in WinMain().
    long time no C; //seige
    You miss 100% of the people you don't C;
    Code:
    if (language != LANG_C && language != LANG_CPP)
        drown(language);

  2. #2
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    611

  3. #3
    HelpingYouHelpUsHelpUsAll
    Join Date
    Dec 2007
    Location
    In your nightmares
    Posts
    223
    Nope, DrawMenuBar did nothing. After debugging, SetMenu & DrawMenuBar both succeed & return a non-zero value.
    long time no C; //seige
    You miss 100% of the people you don't C;
    Code:
    if (language != LANG_C && language != LANG_CPP)
        drown(language);

  4. #4
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    611
    Looking at the code rather than the explanation, the second and fourth AppendMenu calls are appending to the wrong menu. The first parameter should be hMenu not hSubMenu. As it is currently, hMenu is empty when set to the hwnd.

    Depending on how old your copy of the SDK is, the casts on the third parameter are to the wrong type. It should be a cast to UINT_PTR if you want it to be reliable on 64-bit systems.

  5. #5
    HelpingYouHelpUsHelpUsAll
    Join Date
    Dec 2007
    Location
    In your nightmares
    Posts
    223
    Thanks, supprised I didn't notice that. Changed cast as well. Works fine now.
    long time no C; //seige
    You miss 100% of the people you don't C;
    Code:
    if (language != LANG_C && language != LANG_CPP)
        drown(language);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. Replies: 2
    Last Post: 03-05-2009, 09:25 AM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Constructive Feed Back (Java Program)
    By xddxogm3 in forum Tech Board
    Replies: 12
    Last Post: 10-10-2004, 03:41 AM

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