Having a bit of trouble with Menus in VC++
I''ve come to the point where I''m learning to build and use menus in my windows applications. It displays in my book to include all your menu information in a header. I did that, and it''s below:
// MENU.H
// the header file for MenuWindow
MyMenu MENU
{
POPUP "&File"
{
MENUITEM "&Open", IDM_OPEN
MENUITEM "&Close", IDM_CLOSE
MENUITEM "E&xit", IDM_EXIT
}
POPUP "&Options"
{
MENUITEM "&Colors", IDM_COLORS
POPUP "&Priority"
{
MENUITEM "&Low", IDM_LOW
MENUITEM "&High", IDM_HIGH
}
MENUITEM "&Fonts", IDM_FONT
MENUITEM "&Resolution", IDM_RESOLUTION
}
MENUITEM "&Help", IDM_HELP
}
#define IDM_OPEN 100
#define IDM_CLOSE 101
#define IDM_EXIT 102
#define IDM_COLORS 103
#define IDM_LOW 104
#define IDM_HIGH 105
#define IDM_FONT 106
#define IDM_RESOLUTION 107
#define IDM_HELP 108
Is this made correctly? Anyhow...
When I have an #include "Menu.h" in my windows skeleton, it generates 3 errors... none of the errors point to anything in the WinProc that act upon the messages from the menu nor the class definition where I mention MyMenu as a menu name, rather they all point the 5th line (the line where I have #include "Mymenu.h"). What could be wrong? For clarity, here are the compile-time errors:
d:\programming\projects\windows 2000 programming from the ground up studies\chapter 4- menus\window menu\menu.h(5) : error C2146: syntax error : missing '';'' before identifier ''MENU''
d:\programming\projects\windows 2000 programming from the ground up studies\chapter 4- menus\window menu\menu.h(5) : error C2501: ''MyMenu'' : missing storage-class or type specifiers
d:\programming\projects\windows 2000 programming from the ground up studies\chapter 4- menus\window menu\menu.h(5) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
Window Menu.exe - 3 error(s), 0 warning(s)
Sorry for having such a long post, but can anyone help me with my menu troubles?
GO LEAFS GO!
3D Math- The type of mathematics that'll put hair on your chest!
I''m pretty sure with MSVC++ that you have to write BEGIN and END instead of { and }.
altair
altair734@yahoo.com
biggins.mit.edu/altair734
altair
altair734@yahoo.com
biggins.mit.edu/altair734
altairaltair734@yahoo.comwww.geocities.com/altair734
Not from what it shows in the book.
GO LEAFS GO!
GO LEAFS GO!
3D Math- The type of mathematics that'll put hair on your chest!
Okay, I was looking in my Windows 2000 Programming book, and it showed how to make menu''s using the { and }.
However, I checked out making menus in Andre''s Dummies book and it does indeed using BEGIN and END...
However, my real problem lies within actually linking the menu to the cpp! I don''t understand that whole .rc, .res and resources stuff.. Basically, I want to learn (from you guys) to add menu''s to my application..
GO LEAFS GO!
However, I checked out making menus in Andre''s Dummies book and it does indeed using BEGIN and END...
However, my real problem lies within actually linking the menu to the cpp! I don''t understand that whole .rc, .res and resources stuff.. Basically, I want to learn (from you guys) to add menu''s to my application..
GO LEAFS GO!
3D Math- The type of mathematics that'll put hair on your chest!
Well you you can use both BEGIN/END or {}, the rc-compiler doesn´t care, but you are doing something very wrong:
MyMenu MENU
{
...
}
should be in a rc-file (*.rc), so the it gets compiled by the resource-compiler instead of the normal compiler, so you have to do something like this in a rc-file:
// resource.rc
#include "resource.h"
//////////////////////////////////////
// Menu goes here:
MyMenu MENU
{
...
}
In the resource.h you write:
// Resource.h
#define IDM_OPEN 100
#define IDM_CLOSE 101
#define IDM_EXIT 102
#define IDM_COLORS 103
#define IDM_LOW 104
#define IDM_HIGH 105
#define IDM_FONT 106
#define IDM_RESOLUTION 107
#define IDM_HELP 108
Please notice if you are using VC++, you can do this much more easy if you find the menu-item "Insert resource" and then design the menu visually.
- Hope this will work -
MyMenu MENU
{
...
}
should be in a rc-file (*.rc), so the it gets compiled by the resource-compiler instead of the normal compiler, so you have to do something like this in a rc-file:
// resource.rc
#include "resource.h"
//////////////////////////////////////
// Menu goes here:
MyMenu MENU
{
...
}
In the resource.h you write:
// Resource.h
#define IDM_OPEN 100
#define IDM_CLOSE 101
#define IDM_EXIT 102
#define IDM_COLORS 103
#define IDM_LOW 104
#define IDM_HIGH 105
#define IDM_FONT 106
#define IDM_RESOLUTION 107
#define IDM_HELP 108
Please notice if you are using VC++, you can do this much more easy if you find the menu-item "Insert resource" and then design the menu visually.
- Hope this will work -
<<>> The Big ? <<>>
GROWL!! This isn''t working...
Okay, here is where I stand...
The windows skeleton includes the following:
- windows.h
- resource.h
I built the menu, I have VC++ 6.0, using the ResourceFiles->Insert->Menu...
For some reason, I found resource.h in the directory of the program, and it defined all the parts of the menu. I moved the resource.h (the one I just talked about) into the Header Files folder. It compiles with no errors, but sadly, when I execute the program only the window is present- no menu...
GO LEAFS GO!
Okay, here is where I stand...
The windows skeleton includes the following:
- windows.h
- resource.h
I built the menu, I have VC++ 6.0, using the ResourceFiles->Insert->Menu...
For some reason, I found resource.h in the directory of the program, and it defined all the parts of the menu. I moved the resource.h (the one I just talked about) into the Header Files folder. It compiles with no errors, but sadly, when I execute the program only the window is present- no menu...
GO LEAFS GO!
3D Math- The type of mathematics that'll put hair on your chest!
April 23, 2000 06:04 PM
Well did you remember to include the menu-handle in the call to CreateWindow??
The code should look something like this:
// In WinMain()
HMENU hMenu = LoadMenu(hInstance, TEXT("MyMenu"));
CreateWindow(
TEXT("ClassName"), // Your class name
TEXT("MyWindow"), // Window title
WS_OVERLAPPEDWINDOW, // style
0, 0, 800, 600, // pos and window size
NULL, // Parent window
hMenu, // IMPORTANT!!! the menu-handle
hInstance, // The instance handle
NULL); // Own params.
// Hope you can use this.
The code should look something like this:
// In WinMain()
HMENU hMenu = LoadMenu(hInstance, TEXT("MyMenu"));
CreateWindow(
TEXT("ClassName"), // Your class name
TEXT("MyWindow"), // Window title
WS_OVERLAPPEDWINDOW, // style
0, 0, 800, 600, // pos and window size
NULL, // Parent window
hMenu, // IMPORTANT!!! the menu-handle
hInstance, // The instance handle
NULL); // Own params.
// Hope you can use this.
Yes and no. In the CreateWindow, the parameter that needs the window name I have put in, but I don''t need hMenu() call. I have two books that show the complete code to putting ina menu, end neither one of them show the HMENU call...
Why would I be having trouble using windows menus if I have two books? They don''t say how to use the headers and *.rc files, so I''m shit out of a luck on that part. They only show how to actually BUILD a menu.
GO LEAFS GO!
Why would I be having trouble using windows menus if I have two books? They don''t say how to use the headers and *.rc files, so I''m shit out of a luck on that part. They only show how to actually BUILD a menu.
GO LEAFS GO!
3D Math- The type of mathematics that'll put hair on your chest!
April 23, 2000 06:38 PM
There are lots of ways to load a menu, and this was just one example. You could also:
// In WinMain
WNDCLASS wc;
// And fill in the members
wc.lpszMenuName = TEXT("MyMenu");
Or in you main window (here called WndProc):
// In WndProc
switch (message)
{
case WM_CREATE:
{
HMENU hMenu = LoadMenu(g_hInstance, TEXT("MyMenu"));
SetMenu(hWnd, hMenu);
}
}
What books are you using?
They must be rather bad, because my books does tell,
how to load a menu.
// In WinMain
WNDCLASS wc;
// And fill in the members
wc.lpszMenuName = TEXT("MyMenu");
Or in you main window (here called WndProc):
// In WndProc
switch (message)
{
case WM_CREATE:
{
HMENU hMenu = LoadMenu(g_hInstance, TEXT("MyMenu"));
SetMenu(hWnd, hMenu);
}
}
What books are you using?
They must be rather bad, because my books does tell,
how to load a menu.
Wheeee!! I got it working!!
My problem was that when I created the menu.rc, I didn't have the: #include "MyMenu.h". I guess that was the problem, and since I was using vC++ 6.0 to compile all this, I made the menu using it's wizard, and wasn't able to modify the code (you probably can, but I don't know how!). So what I did was, I typed up the the MyMenu.rc in Borland Turbo C++ 4.5, included the "MyMenu.h", and added it into the project. It compiled without any errors or warnings, and I got it working! Yay!
I didn't need to do the Load Menu, but what I did need to do was, in the class definition put the Menu's name in the appropriate place.
Gee, I guess TC++ 4.5 came in REAL handy!
Thanks to all who helped me! I am grateful!
GO LEAFS GO!
Edit: Oh yah, I forgot to mention... when I clicked the different MenuItems and clicked the Ok Button (I was using MB_OK...), the entire application shut down. I took a look at the WinProc, and saw that whenever I chose a MenuItem, the messagebox would show up like a good little boy, but it would break away from the switch statement. Anyow.. to make the long story short, I moved WM_DESTROY above the switch(LOWORD(wParam) and was able to make it so that the application would still be running after a menuitem was executed! I'm feeling quite powerful!
Edited by - Fredric on 4/23/00 9:49:08 PM
My problem was that when I created the menu.rc, I didn't have the: #include "MyMenu.h". I guess that was the problem, and since I was using vC++ 6.0 to compile all this, I made the menu using it's wizard, and wasn't able to modify the code (you probably can, but I don't know how!). So what I did was, I typed up the the MyMenu.rc in Borland Turbo C++ 4.5, included the "MyMenu.h", and added it into the project. It compiled without any errors or warnings, and I got it working! Yay!
I didn't need to do the Load Menu, but what I did need to do was, in the class definition put the Menu's name in the appropriate place.
Gee, I guess TC++ 4.5 came in REAL handy!
Thanks to all who helped me! I am grateful!
GO LEAFS GO!
Edit: Oh yah, I forgot to mention... when I clicked the different MenuItems and clicked the Ok Button (I was using MB_OK...), the entire application shut down. I took a look at the WinProc, and saw that whenever I chose a MenuItem, the messagebox would show up like a good little boy, but it would break away from the switch statement. Anyow.. to make the long story short, I moved WM_DESTROY above the switch(LOWORD(wParam) and was able to make it so that the application would still be running after a menuitem was executed! I'm feeling quite powerful!
Edited by - Fredric on 4/23/00 9:49:08 PM
3D Math- The type of mathematics that'll put hair on your chest!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement