<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Fehler bei WinApi Menu]]></title><description><![CDATA[<p>Hallo</p>
<p>Ich wollte mir ein Fenster programmieren, dass ein Menu beinhaltet. Doch es gibt einen Fehler beim folgenden Code:</p>
<pre><code class="language-cpp">// 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 &lt;windows.h&gt;
#include &quot;resource.h&quot;

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 = &quot;MenuApplied&quot;;
	const char *WndName = &quot;Techniques of Using Menus&quot;;

	// 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(&amp;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(&amp;Msg, NULL, 0, 0) )
	{
             TranslateMessage(&amp;Msg);
             DispatchMessage(&amp;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, &quot;-&quot;);
		// This is how to add a menu item using a string
		AppendMenu(hSysMenu, MF_STRING, 1, &quot;Practical Techniques&quot;);
		// This is how to add a menu item using a defined identifier
		AppendMenu(hSysMenu, MF_STRING, IDM_HELP_ABOUT, &quot;About...&quot;);
		return 0;

	case WM_COMMAND:
		switch(LOWORD(wParam))
		{
		case IDM_LARGE:
			MessageBox(hWnd, &quot;Menu Item Selected = Large&quot;, &quot;Message&quot;, 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 &quot;resource.h&quot;

/////////////////////////////////////////////////////////////////////////////
//
// Menu
//

IDR_MAIN_MENU MENU 
BEGIN
    POPUP &quot;&amp;File&quot;
    BEGIN
        MENUITEM &quot;E&amp;xit&quot;,                       IDM_FILE_EXIT
    END
    POPUP &quot;&amp;Help&quot;
    BEGIN
        MENUITEM &quot;&amp;About...\tF1&quot;,               IDM_HELP_ABOUT
    END
END

IDR_POPUP MENU 
BEGIN
    POPUP &quot;_POPUP_&quot;
    BEGIN
        MENUITEM &quot;&amp;Small&quot;,                      IDM_SMALL
        MENUITEM &quot;&amp;Medium&quot;,                     IDM_MEDIUM
        MENUITEM &quot;&amp;Large&quot;,                      IDM_LARGE
        MENUITEM SEPARATOR
        MENUITEM &quot;&amp;Jumbo&quot;,                      IDM_JUMBO
    END
END

/////////////////////////////////////////////////////////////////////////////
//
// String Table
//

STRINGTABLE 
BEGIN
    IDM_FILE_EXIT           &quot;Closes the application\nClose&quot;
    IDM_SMALL               &quot;Selects a small pizza&quot;
    IDM_MEDIUM              &quot;Selects a medium pizza&quot;
    IDM_LARGE               &quot;Makes up a large pizza&quot;
    IDM_JUMBO               &quot;Builds an extra-large pizza&quot;
    IDM_HELP_ABOUT          &quot;About this application&quot;
END

STRINGTABLE 
BEGIN
    IDS_APP_NAME            &quot;MenuApplied&quot;
END
</code></pre>
<p>Und das hier ist der Fehler:</p>
<pre><code class="language-cpp">------ 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 &quot;file://c:\Dokumente und Einstellungen\patrick\Eigene Dateien\Visual Studio 2008\Projects\MeinMenu\MeinMenu\Debug\BuildLog.htm&quot; gespeichert.
MeinMenu - 1 Fehler, 0 Warnung(en)
========== Erstellen: 0 erfolgreich, Fehler bei 1, 0 aktuell, 0 übersprungen ==========
</code></pre>
<p>Weiss jemand warum es diesen Fehler gibt?</p>
<p>Gruss Patrick</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/243524/fehler-bei-winapi-menu</link><generator>RSS for Node</generator><lastBuildDate>Sat, 04 Apr 2026 04:47:27 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/243524.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 17 Jun 2009 19:47:34 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Fehler bei WinApi Menu on Wed, 17 Jun 2009 19:47:34 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Ich wollte mir ein Fenster programmieren, dass ein Menu beinhaltet. Doch es gibt einen Fehler beim folgenden Code:</p>
<pre><code class="language-cpp">// 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 &lt;windows.h&gt;
#include &quot;resource.h&quot;

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 = &quot;MenuApplied&quot;;
	const char *WndName = &quot;Techniques of Using Menus&quot;;

	// 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(&amp;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(&amp;Msg, NULL, 0, 0) )
	{
             TranslateMessage(&amp;Msg);
             DispatchMessage(&amp;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, &quot;-&quot;);
		// This is how to add a menu item using a string
		AppendMenu(hSysMenu, MF_STRING, 1, &quot;Practical Techniques&quot;);
		// This is how to add a menu item using a defined identifier
		AppendMenu(hSysMenu, MF_STRING, IDM_HELP_ABOUT, &quot;About...&quot;);
		return 0;

	case WM_COMMAND:
		switch(LOWORD(wParam))
		{
		case IDM_LARGE:
			MessageBox(hWnd, &quot;Menu Item Selected = Large&quot;, &quot;Message&quot;, 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 &quot;resource.h&quot;

/////////////////////////////////////////////////////////////////////////////
//
// Menu
//

IDR_MAIN_MENU MENU 
BEGIN
    POPUP &quot;&amp;File&quot;
    BEGIN
        MENUITEM &quot;E&amp;xit&quot;,                       IDM_FILE_EXIT
    END
    POPUP &quot;&amp;Help&quot;
    BEGIN
        MENUITEM &quot;&amp;About...\tF1&quot;,               IDM_HELP_ABOUT
    END
END

IDR_POPUP MENU 
BEGIN
    POPUP &quot;_POPUP_&quot;
    BEGIN
        MENUITEM &quot;&amp;Small&quot;,                      IDM_SMALL
        MENUITEM &quot;&amp;Medium&quot;,                     IDM_MEDIUM
        MENUITEM &quot;&amp;Large&quot;,                      IDM_LARGE
        MENUITEM SEPARATOR
        MENUITEM &quot;&amp;Jumbo&quot;,                      IDM_JUMBO
    END
END

/////////////////////////////////////////////////////////////////////////////
//
// String Table
//

STRINGTABLE 
BEGIN
    IDM_FILE_EXIT           &quot;Closes the application\nClose&quot;
    IDM_SMALL               &quot;Selects a small pizza&quot;
    IDM_MEDIUM              &quot;Selects a medium pizza&quot;
    IDM_LARGE               &quot;Makes up a large pizza&quot;
    IDM_JUMBO               &quot;Builds an extra-large pizza&quot;
    IDM_HELP_ABOUT          &quot;About this application&quot;
END

STRINGTABLE 
BEGIN
    IDS_APP_NAME            &quot;MenuApplied&quot;
END
</code></pre>
<p>Und das hier ist der Fehler:</p>
<pre><code class="language-cpp">------ 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 &quot;file://c:\Dokumente und Einstellungen\patrick\Eigene Dateien\Visual Studio 2008\Projects\MeinMenu\MeinMenu\Debug\BuildLog.htm&quot; gespeichert.
MeinMenu - 1 Fehler, 0 Warnung(en)
========== Erstellen: 0 erfolgreich, Fehler bei 1, 0 aktuell, 0 übersprungen ==========
</code></pre>
<p>Weiss jemand warum es diesen Fehler gibt?</p>
<p>Gruss Patrick</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1728459</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1728459</guid><dc:creator><![CDATA[Eglifisch1]]></dc:creator><pubDate>Wed, 17 Jun 2009 19:47:34 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei WinApi Menu on Wed, 17 Jun 2009 20:46:12 GMT]]></title><description><![CDATA[<p>MSDN Library for Visual Studio schrieb:</p>
<blockquote>
<p>Visual C++ Concepts: Building a C/C++ Program<br />
Resource Compiler Fatal Error RC1004</p>
<p>Error Message<br />
unexpected end of file found</p>
<p>This error can be caused by missing linefeed and carriage return characters on the last line of a text file</p>
</blockquote>
<p>Einfach gleich nach &quot;40006&quot; die Return Taste drücken, oder gorc.ex statt rc.exe benutzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1728465</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1728465</guid><dc:creator><![CDATA[sapero]]></dc:creator><pubDate>Wed, 17 Jun 2009 20:46:12 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei WinApi Menu on Wed, 17 Jun 2009 20:19:41 GMT]]></title><description><![CDATA[<p>Und was muss ich nun ändern, damit es keine Fehler mehr gibt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1728470</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1728470</guid><dc:creator><![CDATA[Eglifisch1]]></dc:creator><pubDate>Wed, 17 Jun 2009 20:19:41 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei WinApi Menu on Wed, 17 Jun 2009 20:24:33 GMT]]></title><description><![CDATA[<blockquote>
<p>This error can be caused by missing linefeed and carriage return characters on the last line of a text file</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1728471</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1728471</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Wed, 17 Jun 2009 20:24:33 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei WinApi Menu on Thu, 18 Jun 2009 10:34:46 GMT]]></title><description><![CDATA[<p>Jochen Kalmbach schrieb:</p>
<blockquote>
<blockquote>
<p>This error can be caused by missing linefeed and carriage return characters on the last line of a text file</p>
</blockquote>
</blockquote>
<p>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!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1728706</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1728706</guid><dc:creator><![CDATA[berniebutt]]></dc:creator><pubDate>Thu, 18 Jun 2009 10:34:46 GMT</pubDate></item></channel></rss>