Fehler bei WinApi Menu



  • Hallo

    Ich wollte mir ein Fenster programmieren, dass ein Menu beinhaltet. Doch es gibt einen Fehler beim folgenden Code:

    // resource.h
    //
    #define IDS_APP_NAME                    1
    #define IDR_MAIN_MENU                   101
    #define IDR_POPUP                       102
    #define IDM_FILE_EXIT                   40001
    #define IDM_SMALL                       40002
    #define IDM_MEDIUM                      40003
    #define IDM_LARGE                       40004
    #define IDM_JUMBO                       40005
    #define IDM_HELP_ABOUT                  40006
    
    // main.cpp
    //
    #include <windows.h>
    #include "resource.h"
    
    HINSTANCE hInst;
    LRESULT CALLBACK WndProcedure(HWND hWnd, UINT uMsg,
    			   WPARAM wParam, LPARAM lParam);
    
    INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine, int nCmdShow)
    {
    	MSG        Msg;
    	HWND       hWnd;
    	WNDCLASSEX WndClsEx;
    
    	hInst = hInstance;
    
    	const char *ClsName = "MenuApplied";
    	const char *WndName = "Techniques of Using Menus";
    
    	// Create the application window
    	WndClsEx.cbSize        = sizeof(WNDCLASSEX);
    	WndClsEx.style         = CS_HREDRAW | CS_VREDRAW;
    	WndClsEx.lpfnWndProc   = WndProcedure;
    	WndClsEx.cbClsExtra    = 0;
    	WndClsEx.cbWndExtra    = 0;
    	WndClsEx.hIcon         = LoadIcon(NULL, IDI_WARNING);
    	WndClsEx.hCursor       = LoadCursor(NULL, IDC_ARROW);
    	WndClsEx.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
    	WndClsEx.lpszMenuName  = MAKEINTRESOURCE(IDR_MAIN_MENU);
    	WndClsEx.lpszClassName = ClsName;
    	WndClsEx.hInstance     = hInstance;
    	WndClsEx.hIconSm       = LoadIcon(NULL, IDI_WARNING);
    
    	RegisterClassEx(&WndClsEx);
    
    	hWnd = CreateWindow(ClsName,
                            WndName,
    						WS_OVERLAPPEDWINDOW,
    						200,
    						160,
    						460,
    						320,
    						NULL,
    						NULL,
    						hInstance,
    						NULL);
    
    	if( !hWnd )
    		return 0;
    
    	ShowWindow(hWnd, SW_SHOWNORMAL);
    	UpdateWindow(hWnd);
    
    	while( GetMessage(&Msg, NULL, 0, 0) )
    	{
                 TranslateMessage(&Msg);
                 DispatchMessage(&Msg);
    	}
    
    	return 0;
    }
    
    LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg,
    			   WPARAM wParam, LPARAM lParam)
    {
    	// Handle to a menu. This will be used with the context-sensitive menu
    	HMENU hMenu;
    	// Handle to the system menu
    	HMENU hSysMenu;
    	// Handle to the context menu that will be created
    	HMENU hMenuTrackPopup;
    
        switch(Msg)
        {
    	case WM_CREATE:
    		// To modify the system menu, first get a handle to it
    		hSysMenu = GetSystemMenu(hWnd, FALSE);
    		// This is how to add a separator to a menu
    		InsertMenu(hSysMenu, 2, MF_SEPARATOR, 0, "-");
    		// This is how to add a menu item using a string
    		AppendMenu(hSysMenu, MF_STRING, 1, "Practical Techniques");
    		// This is how to add a menu item using a defined identifier
    		AppendMenu(hSysMenu, MF_STRING, IDM_HELP_ABOUT, "About...");
    		return 0;
    
    	case WM_COMMAND:
    		switch(LOWORD(wParam))
    		{
    		case IDM_LARGE:
    			MessageBox(hWnd, "Menu Item Selected = Large", "Message", MB_OK);
    			break;
    
    		case IDM_FILE_EXIT:
    			PostQuitMessage(WM_QUIT);
    			break;
    		}
    		return 0;
    
    	case WM_CONTEXTMENU:
    		// Get a handle to the popup menu using its resource
    		if( (hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_POPUP))) == NULL )
    			return 0; 
    
    		// Get a handle to the first shortcut menu
    		hMenuTrackPopup = GetSubMenu(hMenu, 0); 
    
    		// Display the popup menu when the user right-clicks
    		TrackPopupMenu(hMenuTrackPopup,
    			           TPM_LEFTALIGN | TPM_RIGHTBUTTON,
    					   LOWORD(lParam),
    					   HIWORD(lParam), 
    					   0,
    					   hWnd,
    					   NULL);
    		break;
    
        case WM_DESTROY:
            PostQuitMessage(WM_QUIT);
            break;
    
        default:
            return DefWindowProc(hWnd, Msg, wParam, lParam);
        }
    
        return 0;
    }
    
    // main.rc
    //
    #include "resource.h"
    
    /////////////////////////////////////////////////////////////////////////////
    //
    // Menu
    //
    
    IDR_MAIN_MENU MENU 
    BEGIN
        POPUP "&File"
        BEGIN
            MENUITEM "E&xit",                       IDM_FILE_EXIT
        END
        POPUP "&Help"
        BEGIN
            MENUITEM "&About...\tF1",               IDM_HELP_ABOUT
        END
    END
    
    IDR_POPUP MENU 
    BEGIN
        POPUP "_POPUP_"
        BEGIN
            MENUITEM "&Small",                      IDM_SMALL
            MENUITEM "&Medium",                     IDM_MEDIUM
            MENUITEM "&Large",                      IDM_LARGE
            MENUITEM SEPARATOR
            MENUITEM "&Jumbo",                      IDM_JUMBO
        END
    END
    
    /////////////////////////////////////////////////////////////////////////////
    //
    // String Table
    //
    
    STRINGTABLE 
    BEGIN
        IDM_FILE_EXIT           "Closes the application\nClose"
        IDM_SMALL               "Selects a small pizza"
        IDM_MEDIUM              "Selects a medium pizza"
        IDM_LARGE               "Makes up a large pizza"
        IDM_JUMBO               "Builds an extra-large pizza"
        IDM_HELP_ABOUT          "About this application"
    END
    
    STRINGTABLE 
    BEGIN
        IDS_APP_NAME            "MenuApplied"
    END
    

    Und das hier ist der Fehler:

    ------ Erstellen gestartet: Projekt: MeinMenu, Konfiguration: Debug Win32 ------
    Kompilieren...
    main.cpp
    Ressourcen werden kompiliert...
    Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
    Copyright (C) Microsoft Corporation.  All rights reserved.
    .\resource.h(9) : fatal error RC1004: unexpected end of file found
    Das Buildprotokoll wurde unter "file://c:\Dokumente und Einstellungen\patrick\Eigene Dateien\Visual Studio 2008\Projects\MeinMenu\MeinMenu\Debug\BuildLog.htm" gespeichert.
    MeinMenu - 1 Fehler, 0 Warnung(en)
    ========== Erstellen: 0 erfolgreich, Fehler bei 1, 0 aktuell, 0 übersprungen ==========
    

    Weiss jemand warum es diesen Fehler gibt?

    Gruss Patrick



  • MSDN Library for Visual Studio schrieb:

    Visual C++ Concepts: Building a C/C++ Program
    Resource Compiler Fatal Error RC1004

    Error Message
    unexpected end of file found

    This error can be caused by missing linefeed and carriage return characters on the last line of a text file

    Einfach gleich nach "40006" die Return Taste drücken, oder gorc.ex statt rc.exe benutzen.



  • Und was muss ich nun ändern, damit es keine Fehler mehr gibt?



  • This error can be caused by missing linefeed and carriage return characters on the last line of a text file



  • Jochen Kalmbach schrieb:

    This error can be caused by missing linefeed and carriage return characters on the last line of a text file

    Mit anderen Worten: Der Resourcen-Compiler findet einen Fehler in Deiner Datei resource.h. Mache mit dem Editor einfach einen Zeilenumbruch (Enter) am Dateiende. Und bitte verschone uns künftig mit ellenlangem Sourcecode, wenn das Problem ganz woanders liegt!


Anmelden zum Antworten