hi Leute ich wollte eigentlich nun mal ein Ressourcen-Menu erstellen und habe da zu auch schon eine Seite gefunden, aber unter Borland funktioniert das überhaupt nicht, und unter devc++ sieht man das Menü nicht. Hier der Code:
#include <windows.h>
#include "ressource.h"
LPCSTR MainClassName = "Ein Menü-Beispiel";
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMsg,
WPARAM wParam, LPARAM lParam);
HMENU hmenu;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
WNDCLASSEX wc;
MSG wmsg;
HWND hWnd;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(GetModuleHandle(NULL),
MAKEINTRESOURCE(ID_ICON));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
wc.lpszClassName = MainClassName;
wc.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL),
MAKEINTRESOURCE(ID_ICON),
IMAGE_ICON, 16, 16, 0);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Windows Registrations Fehler", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, MainClassName,
"Menü Beispiel",
WS_OVERLAPPEDWINDOW|WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT,
300,150,NULL,NULL,hInstance, NULL);
if(hWnd == NULL)
{
MessageBox(NULL, "Fehler beim Erstellen des Fensters!",
"Error!", MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hmenu= GetMenu(hWnd);
while(GetMessage(&wmsg,NULL,0,0))
{
TranslateMessage(&wmsg);
DispatchMessage(&wmsg);
}
return wmsg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMsg,
WPARAM wParam, LPARAM lParam)
{
char string[255];
switch (iMsg)
{
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_FILE_OPEN:
LoadString(GetModuleHandle(NULL),ID_STRING_OPEN,
string, sizeof(string));
MessageBox(hWnd,string,
"Öffnen",MB_ICONINFORMATION);
break;
case ID_FILE_SAVE:
LoadString(GetModuleHandle(NULL),ID_STRING_SAVE,
string,sizeof(string));
MessageBox(hWnd,string,
"Speichern",MB_ICONINFORMATION);
break;
case ID_OPTIONS_OPTIONS_OPTION1:
LoadString(GetModuleHandle(NULL),ID_STRING_OPTION1,
string,sizeof(string));
MessageBox(hWnd,string,
"Option 1",MB_ICONINFORMATION);
break;
case ID_OPTIONS_OPTIONS_OPTION2:
LoadString(GetModuleHandle(NULL),ID_STRING_OPTION2,
string,sizeof(string));
MessageBox(hWnd,string,"Option 2",
MB_ICONINFORMATION);
break;
case ID_ABOUT:
LoadString(GetModuleHandle(NULL),ID_STRING_ABOUT,
string,sizeof(string));
MessageBox(hWnd,string,"Über",MB_ICONINFORMATION);
break;
case ID_FILE_EXIT:
DestroyWindow(hWnd);
break;
}
break;
}
return DefWindowProc(hWnd,iMsg,wParam,lParam);
}
nun ressource.h:
#define ID_STRING_OPEN 1
#define ID_STRING_SAVE 2
#define ID_STRING_OPTION1 3
#define ID_STRING_OPTION2 4
#define ID_STRING_ABOUT 5
#define IDR_MENU1 101
#define ID_ICON 111
#define ID_FILE_OPEN 40001
#define ID_FILE_SAVE 40002
#define ID_FILE_EXIT 40003
#define ID_OPTIONS_OPTIONS_OPTION1 40004
#define ID_OPTIONS_OPTIONS_OPTION2 40005
#define ID_ABOUT 65535
und nun ressource.rc:
#include <windows.h>
#include "resource.h"
/////////////////////////////////////////////////////////////////
//
// Menü
//
IDR_MENU1 MENU
BEGIN
POPUP "Datei"
BEGIN
MENUITEM "Öffnen", ID_FILE_OPEN
MENUITEM "Speichern", ID_FILE_SAVE
MENUITEM "Ende", ID_FILE_EXIT
END
POPUP "Optionen"
BEGIN
POPUP "Optionen"
BEGIN
MENUITEM "Option&1", ID_OPTIONS_OPTIONS_OPTION1
MENUITEM "Option&2", ID_OPTIONS_OPTIONS_OPTION2
END
END
MENUITEM "Über", ID_ABOUT
END
/////////////////////////////////////////////////////////////////
//
//Icon
//
ID_ICON ICON "goofy.ico"
/////////////////////////////////////////////////////////////////
//
//Stringtabelle
//
STRINGTABLE
BEGIN
ID_STRING_OPEN, "Der Dialog Öffnen"
ID_STRING_SAVE, "Der Dialog Speichern"
ID_STRING_OPTION1, "Erste Option im Untermenü"
ID_STRING_OPTION2, "Zweite Option im Untermenü"
ID_STRING_ABOUT, "Ein Menü-Beispiel\nCoded by J.Wolf"
END
Könnt ihr mir vielleicht sagen , woran das liegt?
mfg alixander
#include <windows.h>
#include "ressource.h"
LPCSTR MainClassName = "Ein Menü-Beispiel";
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMsg,
WPARAM wParam, LPARAM lParam);
HMENU hmenu;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
WNDCLASSEX wc;
MSG wmsg;
HWND hWnd;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(GetModuleHandle(NULL),
MAKEINTRESOURCE(ID_ICON));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
wc.lpszClassName = MainClassName;
wc.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL),
MAKEINTRESOURCE(ID_ICON),
IMAGE_ICON, 16, 16, 0);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Windows Registrations Fehler", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, MainClassName,
"Menü Beispiel",
WS_OVERLAPPEDWINDOW|WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT,
300,150,NULL,NULL,hInstance, NULL);
if(hWnd == NULL)
{
MessageBox(NULL, "Fehler beim Erstellen des Fensters!",
"Error!", MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hmenu= GetMenu(hWnd);
while(GetMessage(&wmsg,NULL,0,0))
{
TranslateMessage(&wmsg);
DispatchMessage(&wmsg);
}
return wmsg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMsg,
WPARAM wParam, LPARAM lParam)
{
char string[255];
switch (iMsg)
{
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_FILE_OPEN:
LoadString(GetModuleHandle(NULL),ID_STRING_OPEN,
string, sizeof(string));
MessageBox(hWnd,string,
"Öffnen",MB_ICONINFORMATION);
break;
case ID_FILE_SAVE:
LoadString(GetModuleHandle(NULL),ID_STRING_SAVE,
string,sizeof(string));
MessageBox(hWnd,string,
"Speichern",MB_ICONINFORMATION);
break;
case ID_OPTIONS_OPTIONS_OPTION1:
LoadString(GetModuleHandle(NULL),ID_STRING_OPTION1,
string,sizeof(string));
MessageBox(hWnd,string,
"Option 1",MB_ICONINFORMATION);
break;
case ID_OPTIONS_OPTIONS_OPTION2:
LoadString(GetModuleHandle(NULL),ID_STRING_OPTION2,
string,sizeof(string));
MessageBox(hWnd,string,"Option 2",
MB_ICONINFORMATION);
break;
case ID_ABOUT:
LoadString(GetModuleHandle(NULL),ID_STRING_ABOUT,
string,sizeof(string));
MessageBox(hWnd,string,"Über",MB_ICONINFORMATION);
break;
case ID_FILE_EXIT:
DestroyWindow(hWnd);
break;
}
break;
}
return DefWindowProc(hWnd,iMsg,wParam,lParam);
}
nun ressource.h:
#define ID_STRING_OPEN 1
#define ID_STRING_SAVE 2
#define ID_STRING_OPTION1 3
#define ID_STRING_OPTION2 4
#define ID_STRING_ABOUT 5
#define IDR_MENU1 101
#define ID_ICON 111
#define ID_FILE_OPEN 40001
#define ID_FILE_SAVE 40002
#define ID_FILE_EXIT 40003
#define ID_OPTIONS_OPTIONS_OPTION1 40004
#define ID_OPTIONS_OPTIONS_OPTION2 40005
#define ID_ABOUT 65535
und nun ressource.rc:
#include <windows.h>
#include "resource.h"
/////////////////////////////////////////////////////////////////
//
// Menü
//
IDR_MENU1 MENU
BEGIN
POPUP "Datei"
BEGIN
MENUITEM "Öffnen", ID_FILE_OPEN
MENUITEM "Speichern", ID_FILE_SAVE
MENUITEM "Ende", ID_FILE_EXIT
END
POPUP "Optionen"
BEGIN
POPUP "Optionen"
BEGIN
MENUITEM "Option&1", ID_OPTIONS_OPTIONS_OPTION1
MENUITEM "Option&2", ID_OPTIONS_OPTIONS_OPTION2
END
END
MENUITEM "Über", ID_ABOUT
END
/////////////////////////////////////////////////////////////////
//
//Icon
//
ID_ICON ICON "goofy.ico"
/////////////////////////////////////////////////////////////////
//
//Stringtabelle
//
STRINGTABLE
BEGIN
ID_STRING_OPEN, "Der Dialog Öffnen"
ID_STRING_SAVE, "Der Dialog Speichern"
ID_STRING_OPTION1, "Erste Option im Untermenü"
ID_STRING_OPTION2, "Zweite Option im Untermenü"
ID_STRING_ABOUT, "Ein Menü-Beispiel\nCoded by J.Wolf"
END
Könnt ihr mir vielleicht sagen , woran das liegt?
mfg alixander