Window - Menu problem...

This is a discussion on Window - Menu problem... within the Windows Programming forums, part of the Platform Specific Boards category; Hey all, I'm creating my first menu but it doesn't work for some vague reason. I've tried several things, and ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    50

    Window - Menu problem...

    Hey all,

    I'm creating my first menu but it doesn't work for some vague reason.
    I've tried several things, and the code compiles just like it should, but the menu doesn't show up when I run the .exe ...

    Here's the window code and the resource:

    Window
    Code:
    #include <windows.h> 
    #include <windowsx.h> 
    
    
    
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) 
    { 
    PAINTSTRUCT ps; 
        switch (message)                  
        { 
        case WM_CREATE: 
        MessageBox(NULL,"Program is now starting up...","Attention!", MB_OK | MB_ICONQUESTION); 
        
        return (0); 
        break; 
        case WM_PAINT: 
        BeginPaint(hwnd, &ps); 
        EndPaint(hwnd, &ps); 
        return(0); 
        break; 
        case WM_DESTROY: 
     PostQuitMessage (0);    
            break; 
            default:                    
            return DefWindowProc (hwnd, message, wParam, lParam); 
        } 
    
        return 0; 
    } 
    
    char szClassName[ ] = "WINCLASS1"; 
    
    int WINAPI WinMain (HINSTANCE hThisInstance, 
                        HINSTANCE hPrevInstance, 
                        LPSTR lpcmdline, 
                        int ncmdshow) 
    
    { 
        HWND hwnd;            
        MSG msg;            
        WNDCLASSEX winclass;        
    
        
        winclass.hInstance = hThisInstance; 
        winclass.lpszClassName = szClassName; 
        winclass.lpfnWndProc = WindowProcedure;      
        winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;                  
        winclass.cbSize = sizeof (WNDCLASSEX);  
        winclass.hIcon = LoadIcon (NULL, IDI_APPLICATION); 
        winclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION); 
        winclass.hCursor = LoadCursor (NULL, IDC_ARROW); 
        winclass.lpszMenuName = "MainMenu";                  
        winclass.cbClsExtra = 0;                      
        winclass.cbWndExtra = 0;                    
        
        winclass.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH); 
    
        
        if (!RegisterClassEx (&winclass)) 
            return 0; 
    
      
        hwnd = CreateWindowEx ( 
               0,                  
               szClassName,          
               "Windows App",        
               WS_OVERLAPPEDWINDOW, 
               CW_USEDEFAULT,        
               CW_USEDEFAULT,        
               400,                
               400,                  
               HWND_DESKTOP,        
               NULL, //I've tried to change this to "MainMenu" aswell..              
               hThisInstance,        
               NULL                  
               ); 
                  
        ShowWindow (hwnd, ncmdshow); 
    
    
        while (GetMessage (&msg, NULL, 0, 0)) 
        { 
            TranslateMessage(&msg); 
    
            DispatchMessage(&msg); 
        } 
    }
    Resource
    Code:
    MainMenu MENU DISCARDABLE 
    { 
    POPUP "File" 
    { 
    MENUITEM "Open", MENU_FILE_ID_OPEN 
    MENUITEM "Close", MENU_FILE_ID_CLOSE 
    MENUITEM "Save", MENU_FILE_ID_SAVE 
    MENUITEM "Exit", MENU_FILE_ID_EXIT 
    } 
    POPUP "Help" 
    { 
    MENUITEM "About", MENU_HELP_ABOUT 
    } 
    }
    I didn't forget to add the resource to the project, so that's not the problem. In fact, this is just like it's described in the book... Can anyone please tell me why the menu doesn't show up and what I'm doing wrong?
    I dont know half as many of you half as well as I should like, and I like less than half of you half as well as you deserve...

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Presumably you have a resource header where you have defined numerical values for MENU_FILE_ID_OPEN, MENU_FILE_ID_CLOSE etc. If you have also defined a numerical value for 'MainMenu' then your menu will not be created/associated with the registered window class (see lpszMenuName of the WNDCLASSEX struct ).

    If you have done this then you could either remove the numerical define for 'MainMenu' from your resource header or, arguably better, leave it alone and replace "MainMenu' with MAKEINTRESOURCE(MainMenu) for lpszMenuName of the WNDCLASSEX struct.

    In short, you can use either a string or numerical value as resource item identifiers, not both.

    As an aside, you don't need both a 'return' and a 'break' statement within a 'case' block of a 'switch' statement; one or the other will suffice.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  2. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  3. help solve linking problem, thanks
    By Raison in forum Windows Programming
    Replies: 8
    Last Post: 05-29-2004, 11:14 AM
  4. dont want to use all params
    By stallion in forum Windows Programming
    Replies: 2
    Last Post: 02-18-2003, 07:10 AM
  5. Problem with non-functional window
    By Magos in forum Windows Programming
    Replies: 5
    Last Post: 04-14-2002, 11:32 PM

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