Thread: Menu not showing

  1. #1
    Registered User
    Join Date
    Feb 2006
    Location
    Leiden, NL
    Posts
    12

    Question Menu not showing

    Hi everybody,

    I started with Visual C++ and stumbled upon a small problem.

    I began with the tutorial which can be found here: Link.
    This all works well. I'm getting my application with the text in the middle. Perfect.
    Now I want a menu with an option to close the application. I created a menu with the resource editor in Visual C++. After that I got a header file and a script file.

    The header file contains:
    Code:
    //{{NO_DEPENDENCIES}}
    // Microsoft Developer Studio generated include file.
    // Used by recource.rc
    //
    #define IDR_MENU1                       101
    
    // Next default values for new objects
    // 
    #ifdef APSTUDIO_INVOKED
    #ifndef APSTUDIO_READONLY_SYMBOLS
    #define _APS_NEXT_RESOURCE_VALUE        102
    #define _APS_NEXT_COMMAND_VALUE         40001
    #define _APS_NEXT_CONTROL_VALUE         1000
    #define _APS_NEXT_SYMED_VALUE           101
    #endif
    #endif
    And the most important parts in the script are:
    Code:
    #include "resource.h"
    
    IDR_MENU1 MENU DISCARDABLE 
    BEGIN
        MENUITEM "&File",                       65535
    END
    I know, this doesn't close the application, but I wanted to see if the menu would show up at all.

    I was under the assumption that I can make the menu visible by simple stating:
    Code:
    windowClass.lpszMenuName = MAKEINTRESOURCE("IDR_MENU1");
    But..... This isn't the case.

    What am I doing wrong here?

    Any help is much appreciated.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Don't use quotes around the menu identifier.
    Code:
    windowClass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
    If you haven't already, "resource.h" needs to be included in the .c or .cpp file as well as the resource file.

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    You can designate your menu resource with a numeric identifier or a string but not both.

    Since your menu resource is identified with a number (101) then use that with MAKEINTRESOURCE, ie remove the quotes:
    Code:
    windowClass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
    If your menu was identified with a string then you wouldn't need to use the MAKEINTRESOURCE macro at all, you would just use the string identifier.

    edit: beaten by 'tmouse.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  4. #4
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    Code:
    case WM_CREATE:
                {   
                    HMENU hMenu, hSubMenu;
                    HICON hIcon, hIconSm;
    
                    hMenu = CreateMenu();
    
                    hSubMenu = CreatePopupMenu();
                    AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File");
                
    
                    SetMenu(hwnd, hMenu);
                }
                break;
    Something like that.
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

  5. #5
    Registered User
    Join Date
    Feb 2006
    Location
    Leiden, NL
    Posts
    12

    @Ideswa

    Your method works. Thanks.
    Using quotes or not, I can't get the menu to work by using the other method. Ah well, as long as it works now....

    Thnx

  6. #6
    Registered User
    Join Date
    Feb 2006
    Location
    Leiden, NL
    Posts
    12

    Talking fixed it

    Hi, fixed the menu... I didn't add the file to my project (silly mistake to make)... Figured it was included automatically... Guess not...

    Thnx for the replies!

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, 10: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