Thread: Menu not showing up.

  1. #1
    Registered User xlnk's Avatar
    Join Date
    Mar 2002
    Posts
    186

    Question Menu not showing up.

    I'm going through the Winprog tutorial and im on the part where you learn menus. I'm using the first method with a .rc file, but my menu doesn't show up.

    Here is my main source(.cpp):

    Code:
    #include <windows.h>
    #include "resource.h"
    
    const char g_szClassName[] = "myWindowClass";
    
    LRESULT CALLBACK WndProc ( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
    { 
        switch(msg)
        {
            case WM_CLOSE:
                    DestroyWindow(hwnd);
            break;
            case WM_DESTROY:
                    PostQuitMessage(0);
            break;
            default:
                    return DefWindowProc (hwnd, msg, wParam, lParam);
        }
        return 0;
    }
    
    int WINAPI WinMain ( HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR lpCmdLine,
                         int nCmdShow )
    {
        WNDCLASSEX wc;
        HWND hwnd;
        MSG Msg;
        
        wc.cbSize        = sizeof(WNDCLASSEX);
        wc.style         = 0;
        wc.lpfnWndProc   = WndProc;
        wc.cbClsExtra    = 0;
        wc.cbWndExtra    = 0;
        wc.hInstance      = hInstance;
        wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
        wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH) (COLOR_WINDOW+0);
        wc.lpszMenuName  = MAKEINTRESOURCE(IDR_MYMENU);
        wc.lpszClassName = g_szClassName;
        wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
        
        if(!RegisterClassEx(&wc))
        {
            MessageBox(NULL, "Window Registration Failed!", "Error!",
                    MB_ICONEXCLAMATION | MB_OK);
            return 0;
        }
        
        hwnd = CreateWindowEx( 0,                      //WS_EX_CLIENTEDGE
                               g_szClassName,
                               "Test",
                               WS_OVERLAPPEDWINDOW,
                               CW_USEDEFAULT, CW_USEDEFAULT, 260, 200,
                               NULL, NULL, hInstance, NULL );
                               
        if (hwnd == NULL)
        {
            MessageBox (NULL, "Window Creation Failed!", "Error!",
                    MB_ICONEXCLAMATION | MB_OK );
            return 0;
        }
        
        ShowWindow(hwnd, nCmdShow);
        UpdateWindow(hwnd);
        
        while(GetMessage(&Msg, NULL, 0, 0) > 0)
        {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
        return Msg.wParam;
    }
    resource.h:

    Code:
    #define IDR_MYMENU 101
    
    #define IF_FILE_EXIT 9001
    #define ID_STUFF_GO 9002
    re.rc:
    Code:
    #include "resource.h"
    
    IDR_MYMENU MENU
    BEGIN
        POPUP "&File"
        BEGIN
            MENUITEM "E&xit", ID_FILE_EXIT
        END
        
        POPUP "&Stuff"
        BEGIN
            MENUITEM "&Go", ID_STUFF_GO
            MENUITEM "G&o somewhere else", 0, GRAYED
        END
    END
    The .rc is included in my project. Using Dev-C++.

    Is the problem with the syntax of the bold text in the main source (.cpp)?
    Last edited by xlnk; 08-03-2002 at 06:35 PM.
    the best things in life are simple.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Try #include <windows.h> before you #include "resource.h" in your resource script (re.rc).

  3. #3
    Registered User cMADsc's Avatar
    Join Date
    Jun 2002
    Posts
    18
    LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU));

    or
    wc.lpszMenuName = NULL;
    .
    .
    .

    LRESULT CALLBACK WndProc ( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
    {
    static HINSTANCE hInstance;


    switch(msg)
    {
    case WM_CREATE:
    hInstance = ((LPCREATESTRUCT) lParam)-> hInstance;
    LoadMenu =(hInstance, MAKEINTRESOURCE(IDR_MENU));
    return 0;

    case WM_CLOSE:
    DestroyWindow(hwnd);
    break;
    case WM_DESTROY:
    PostQuitMessage(0);
    break;
    default:
    return DefWindowProc (hwnd, msg, wParam, lParam);
    }
    return
    There are those who say they can, and there are those who acutally do.

    ...you can not learn programming in a class, you have to learn it on your own

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    If you are still having trouble..

    Try a GetMenu() in WM_INIT and test the returned HMENU is not NULL (if so the problem is with the menu creation).

    If it is not NULL then the menu is in the dialog but probably needs to be painted with a DrawMenuBar() call.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    In Dev-C++, go to the project menu and choose edit resource file. Include all of your resource file at the end of the one that is displayed.

  6. #6
    Registered User
    Join Date
    Aug 2002
    Posts
    16
    You have a spelling error in resource.h

    Code:
    #define IF_FILE_EXIT 9001
    should be

    Code:
    #define ID_FILE_EXIT 9001
    Hence your re.rc won't compile into your executable and it'll never load. Once this was corrected it worked fine on my PC

    --Chorus

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. Menu not showing
    By IdunnO in forum Windows Programming
    Replies: 5
    Last Post: 03-30-2006, 02:29 AM
  5. Constructive Feed Back (Java Program)
    By xddxogm3 in forum Tech Board
    Replies: 12
    Last Post: 10-10-2004, 03:41 AM