Results 1 to 12 of 12

Thread: Menu

  1. #1

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    I'm using this code to show a menu, but it doesn't appear...

    Code:
    // INCLUDES ////////////////////
    #define WIN32_LEAN_AND_MEAN
    #include <windows.h>
    #include <windowsx.h>
    #include <stdio.h>
    #include <math.h>
    #include "mymenu.h"
    // DEFINES ////////////////////
    // defines for windows
    #define WINDOW_CLASS_NAME "WINCLASS1"       // <------ WINDOW not WINDOWS
    // GLOBALS ///////////////////
    HWND main_window_handle = NULL; // save the window handle       // <------ window not windows
    // FUNCTIONS ////////////////
    LRESULT CALLBACK WindowProc(HWND hwnd,
    									UINT msg, WPARAM wparam, LPARAM lparam)
    {
    // this is the main message handler of the system
    PAINTSTRUCT ps; // used in WM_AINT
    HDC hdc;
    // find out what the message is
    switch(msg)
    	{
    	case WM_CREATE:
    				{
    
    				// do initialization stuff here
    				return(0);
    				} break;
    	case WM_PAINT:
    				{
    				// simply validate the window
    				hdc = BeginPaint(hwnd,&ps);
    				EndPaint(hwnd,&ps);       // <------ needed a pointer
    				return(0);
    				} break;
    	case WM_DESTROY:                      // <------ spelling mistake
    				{
    
    				// kill the application
    				PostQuitMessage(0);
    				return(0);
    				} break;
    
    
    	default: break;
    	} // end switch
    // process any messages that you didn't take care of
    return (DefWindowProc(hwnd,msg,wparam,lparam));
    } // end WinProc
    // WINMAIN ///////////////////
    int WINAPI WinMain(HINSTANCE hinstance,
    						HINSTANCE previnstance,      // <------ spelling mistake
    						LPSTR lpcmdline,
    						int ncmdshow)
    {
    WNDCLASS winclass; // this will hold the class you create        // <------ missing semicolon
    HWND hwnd; // generic window handle
    MSG  msg; // generic message
    // first, fill in the window class structure
    winclass.style = CS_DBLCLKS | CS_OWNDC |
    					  CS_HREDRAW | CS_VREDRAW;
    winclass.lpfnWndProc = WindowProc;
    winclass.cbClsExtra = 0;
    winclass.cbWndExtra = 0;
    winclass.hInstance = hinstance;
    winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
    winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);     // <------ void* needs an explicit cast
    winclass.lpszMenuName = NULL;
    winclass.lpszClassName = WINDOW_CLASS_NAME;
    // register the following class
    if (!RegisterClass(&winclass))
    	return(0);
    // create window
    if (!(hwnd = CreateWindow(WINDOW_CLASS_NAME,
    		"Hello Carsten! The C++ Programmer!", // Title
    		WS_OVERLAPPEDWINDOW | WS_VISIBLE, // Flags
    		500,500, // x,y
    		320,200, // width, height
    		NULL, // Handle to parent
    		NULL, // Handle to menu
    		hinstance, // instance                           // <------ hinstance not hInstance
    		NULL))) // creation parameters
    return(0);
    // save the window handle in a global
    main_window_handle = hwnd;
    SetMenu(hwnd,LoadMenu(hinstance, "MYMENU"));
    //enter main event loop
    while(1)
    		{
    		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
    		{
    		// test whether this is a quit
    			if (msg.message == WM_QUIT) break;      // <------ typo
    			//translate any accelerator keys
    			TranslateMessage(&msg);
    			// send the message to the window proc
    			DispatchMessage(&msg);
    			} // end if
    		// main game processing here
    		
    
    } // end while
    return(msg.wParam);
    } // end WinMain
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  2. #2
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Its kinda hard to tell from your code, but I am guessing you want your menu to be on you window so you need to change to:

    This works if you have your menu as a resource.

    Code:
    winclass.lpszMenuName = NULL;
    winclass.lpszMenuName = LoadMenu(hinstance, MAKEINTRESOURCE(IDI_YOURMENUNAME);
    If not then you would have to use CreateWindowEX.

    Also use:
    Code:
    case WM_COMMAND:
        switch(LOWORD(wparam))
           {
                 case IDR_YOURMENUCHOICE:
            }
    To run your code when a menu choice is made
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  3. #3

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    It generates errors....

    Undefined symbol 'MYMENU' in WinMain
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  4. #4
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    umm yeah...........I put that so you could input your menu name.

    Did you make your menu as a resource?
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  5. #5

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    Yes I did...
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  6. #6
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Ok....I see now my bad. You need to add

    Code:
    #include "resource.h"  //Or whatever your resource file header is called
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  7. #7

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    I have done that:
    Code:
    #include "mymenu.h"
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  8. #8
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Can you post the code in mymenu.h
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  9. #9

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    Here you go!
    Code:
    // MYMENU.H - header with menu id's
    // Notice the clean naming I used for the id's you
    // can very quickly figure out the menu, sub menu, and item
    
    #define ID_MYMENU_FILE_OPEN   1000
    #define ID_MYMENU_FILE_CLOSE  1001
    #define ID_MYMENU_FILE_EXIT   1002
    #define ID_MYMENU_HELP_ABOUT  2000
    
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  10. #10
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    I dont see the define for the top level of the menu. Like my menu:

    Code:
    #define IDR_RCLKMENU                          1
    #define IDR_RCLKMENU_File_Open        100
    #define IDR_RCLKMENU_File_Close        200
    #define IDR_RCLKMENU_File_Exit           300
    And thats what you would call:

    Code:
    winclass.lpszMenuName = LoadMenu(hinstance, MAKEINTRESOURCE(IDR_RCLKMENU);
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  11. #11

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    Hi again!
    Now I get another error:
    Function call ) missing in function WinMain.
    I don't know where to place the "close" )
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  12. #12
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Can you please post just your WinMain function
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width