Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Fredric

Having a bit of trouble with Menus in VC++

This topic is 6941 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Advertisement
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!

Share this post


Link to post
Share on other sites
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 -

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!