Results 1 to 12 of 12

Thread: Menus again...

  1. #1

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

    Menus again...

    I'm trying to display a menu, but it doesn't seem to work....I have had this problem before, but with a different compiler....I'm now using VC++ 6.

    Here is the code:

    Code:
    #define WIN32_LEAN_AND_MEAN
    #include <windows.h>
    #include <windowsx.h>
    #include "resource.h"
    
    
    #define WINDOW_CLASS_NAME " WINCLASS1"
    
    HWND main_window_handle = NULL;
    
    LRESULT CALLBACK WindowProc(HWND hwnd,
    							UINT msg,
    							WPARAM wparam,
    							LPARAM lparam)
    {
    PAINTSTRUCT ps;
    HDC hdc;
    
    	switch(msg)
    	{
    	case WM_CREATE:
    		{
    			return 0;
    		} break;
    	case WM_PAINT:
    		{
    			hdc = BeginPaint(hwnd, &ps);
    			EndPaint(hwnd, &ps);
    			return 0;
    		} break;
    	case WM_DESTROY:
    		{
    			MessageBox(NULL, "Bye bye cruel world!", "Bye!", MB_OK | MB_ICONINFORMATION);
    			PostQuitMessage(0);
    			return 0;
    		} break;
    	default: break;
    	}
    return (DefWindowProc(hwnd, msg, wparam, lparam));
    }
    
    
    
    
    int WINAPI WinMain(HINSTANCE hinstance,
    				   HINSTANCE hPrevInstance,
    				   LPSTR lpstCmdLine, int ncmdshow)
    
    {
    WNDCLASS winclass;
    HWND hwnd;
    MSG msg;
    
    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);
    winclass.lpszMenuName = NULL;
    winclass.lpszClassName = WINDOW_CLASS_NAME;
    
    if (!RegisterClass(&winclass))
    	return 0;
    
    if (!(hwnd = CreateWindow(WINDOW_CLASS_NAME, "Hello Carsten!",
    	WS_OVERLAPPEDWINDOW | WS_VISIBLE,
    	350,200,
    	320,200,
    	NULL,
    	NULL,
    	hinstance,
    	NULL)))
    return 0;
    
    main_window_handle = hwnd;
    SetMenu(hwnd,LoadMenu(hinstance, "IDR_MENU1"));
    
    while (1)
    {
    	if (PeekMessage(&msg,  NULL, 0,0, PM_REMOVE))
    	{
    		if (msg.message == WM_QUIT) break;
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    }
    return(msg.wParam);
    }
    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
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    Just curious, what is #define WIN32_LEAN_AND_MEAN?
    Alcohol & calculus don't mix.
    Never drink & derive.

  3. #3

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    It forces various options in the windows.h file for be taken....

    You should always start every windows program like this:

    Code:
    #define WIN32_LEAN_AND_MEAN
    #include <windows.h>
    #include <windowsx.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)

  4. #4
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    Hmm, never knew that. What kinds of options? Smaller .exe file, etc.?
    Alcohol & calculus don't mix.
    Never drink & derive.

  5. #5

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    Anyone know why the code above doesn't show the menu???
    I have instructed the compiler where it can find the resources, and I have included the resource file in the main file.....
    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 HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Could you upload the resource.h header and your resource file?
    Harry.

    "From one thing, know ten thousand things."

  7. #7

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    Here they are:

    file 'res.rc':

    Code:
    //Microsoft Developer Studio generated resource script.
    //
    #include "resource.h"
    
    #define APSTUDIO_READONLY_SYMBOLS
    /////////////////////////////////////////////////////////////////////////////
    //
    // Generated from the TEXTINCLUDE 2 resource.
    //
    #include "afxres.h"
    
    /////////////////////////////////////////////////////////////////////////////
    #undef APSTUDIO_READONLY_SYMBOLS
    
    /////////////////////////////////////////////////////////////////////////////
    // Danish resources
    
    #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_DAN)
    #ifdef _WIN32
    LANGUAGE LANG_DANISH, SUBLANG_DEFAULT
    #pragma code_page(1252)
    #endif //_WIN32
    
    #ifdef APSTUDIO_INVOKED
    /////////////////////////////////////////////////////////////////////////////
    //
    // TEXTINCLUDE
    //
    
    1 TEXTINCLUDE DISCARDABLE 
    BEGIN
        "resource.h\0"
    END
    
    2 TEXTINCLUDE DISCARDABLE 
    BEGIN
        "#include ""afxres.h""\r\n"
        "\0"
    END
    
    3 TEXTINCLUDE DISCARDABLE 
    BEGIN
        "\r\n"
        "\0"
    END
    
    #endif    // APSTUDIO_INVOKED
    
    
    /////////////////////////////////////////////////////////////////////////////
    //
    // Menu
    //
    
    IDR_MENU1 MENU DISCARDABLE 
    BEGIN
        POPUP "Test"
        BEGIN
            MENUITEM "Test",                        ID_TEST_TEST
        END
    END
    
    #endif    // Danish resources
    /////////////////////////////////////////////////////////////////////////////
    
    
    
    #ifndef APSTUDIO_INVOKED
    /////////////////////////////////////////////////////////////////////////////
    //
    // Generated from the TEXTINCLUDE 3 resource.
    //
    
    
    /////////////////////////////////////////////////////////////////////////////
    #endif    // not APSTUDIO_INVOKED
    file 'resource.h'

    Code:
    //{{NO_DEPENDENCIES}}
    // Microsoft Developer Studio generated include file.
    // Used by res.rc
    //
    #define IDR_MENU1                       102
    #define ID_TEST_TEST                    40002
    
    // Next default values for new objects
    // 
    #ifdef APSTUDIO_INVOKED
    #ifndef APSTUDIO_READONLY_SYMBOLS
    #define _APS_NEXT_RESOURCE_VALUE        104
    #define _APS_NEXT_COMMAND_VALUE         40003
    #define _APS_NEXT_CONTROL_VALUE         1000
    #define _APS_NEXT_SYMED_VALUE           101
    #endif
    #endif
    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
    Member
    Join Date
    Oct 2000
    Posts
    34
    You need to set the Menu when you register the window class (WNDCLASSEX).
    Code:
    // Change this line
    winclass.lpszMenuName = NULL;
    // to this
    winclass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);

  9. #9
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    I don't think you have to. May have a point about that MAKEINTRESOURCE() thing though, you could use that in the SetMenu function.... not sure that's right though, I'm guessing really.
    Harry.

    "From one thing, know ten thousand things."

  10. #10
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Yep, that works. Change it to this:
    Code:
    SetMenu(hwnd,LoadMenu(hinstance, MAKEINTRESOURCE(IDR_MENU1)));
    Harry.

    "From one thing, know ten thousand things."

  11. #11

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    That solved the mystery! Thanks guys!
    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

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    No, parkise, we never found the answer...Since I was using DevCpp at the time, I had to include the working dir in the compiler options...
    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)

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