Jump to content
  • Advertisement
Sign in to follow this  
Fixxer

Need help with making menu

This topic is 4875 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

Advertisement
i have the menu built and added into my windows and now im trying to make it do certain things when people click on the items. here are my errors:



--------------------Configuration: icons - Win32 Debug--------------------
Compiling...
source.cpp
C:\Documents and Settings\Owner\Desktop\Comp Prog\C++\Windows
Programming\Chapter Three\icons\source.cpp(77) : error C2065: '_MENU_EXIT' : undeclared identifier

C:\Documents and Settings\Owner\Desktop\Comp Prog\C++\Windows Programming\Chapter Three\icons\source.cpp(77) :
error C2051: case expression
not constant

C:\Documents and Settings\Owner\Desktop\Comp Prog\C++\Windows Programming\Chapter Three\icons\source.cpp(81)
: warning C4060: switch statement contains no 'case' or 'default' labels
Error executing cl.exe.

icons.exe - 2 error(s), 1 warning(s)

Share this post


Link to post
Share on other sites
my resource file:




#include "MENU.H"

_ICON ICON t3dx.ico
_CURSOR CURSOR blue.cur
_MUSIC WAVE loop.wav

_MENU MENU DISCARDABLE
{
POPUP "File"
{
MENUITEM "&New", _MENU_NEW
MENUITEM "&Open", _MENU_OPEN
MENUITEM "&Close", _MENU_CLOSE
MENUITEM "&Save",_MENU_SAVE
MENUITEM "E&xit",_MENU_EXIT
}
POPUP "Help"
{
MENUITEM "&Help",_MENU_HELP
MENUITEM "&About",_MENU_ABOUT
}
}

Share this post


Link to post
Share on other sites
the winproc function:


// WINPROC ///////////////////////////////////////////////////////////
LRESULT CALLBACK WindowProc(HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam)
{

PAINTSTRUCT ps;
HDC hdc;

// check for message type
switch(msg)
{
// WM_CREATE //////////////////////////////////////////////////////
case WM_CREATE:
{
// do initialization stuff here

PlaySound("_MUSIC", hinstance_app, SND_RESOURCE | SND_ASYNC | SND_LOOP);

return(0);
} break;
// WM_COMMAND ///////////////////////////////////////////////////
case WM_COMMAND:
{
switch (LOWORD(wparam))
{
case _MENU_EXIT:
{
PostQuitMessage(0);
}break;
}
}break;
// WM_PAINT /////////////////////////////////////////////////////
case WM_PAINT:
{
hdc = BeginPaint(hwnd,&ps);

// you would do all your painting here
EndPaint(hwnd,&ps);

return(0);
} break;
// WM_DESTORY ////////////////////////////////////////////////////
case WM_DESTROY:
{

PlaySound(NULL, hinstance_app, SND_PURGE);

// kill the application, this sends a WM_QUIT message
PostQuitMessage(0);

return(0);
} break;

default:break;

}

// process any messages that we didn't take care of
return (DefWindowProc(hwnd, msg, wparam, lparam));

} // ENDWINPROC ///////////////////////////////////////////////////////


Share this post


Link to post
Share on other sites
you never put braces at the start of case commands!
sorry. I had to say it in that way. you use case statments like this:

switch(msg)
{
case WM_WHATEVER: //no brace!
do_something();
break; //breaks inbetween to seperate the cases

case WM_SOMETHINGELSE:
do_something_else();
break;
}


Share this post


Link to post
Share on other sites
like this?


// WINPROC ///////////////////////////////////////////////////////////
LRESULT CALLBACK WindowProc(HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam)
{

PAINTSTRUCT ps;
HDC hdc;

// check for message type
switch(msg)
{
// WM_CREATE ///////////////////////////////////////////////////////
case WM_CREATE:
// do initialization stuff here
PlaySound("_MUSIC", hinstance_app, SND_RESOURCE | SND_ASYNC | SND_LOOP);
return(0);
break;
// WM_COMMAND /////////////////////////////////////////////////////////
case WM_COMMAND:
switch (LOWORD(wparam))
{
case _MENU_EXIT:
PostQuitMessage(0);
break;
}
break;
// WM_PAINT ///////////////////////////////////////////////////////////
case WM_PAINT:
hdc = BeginPaint(hwnd,&ps);
// you would do all your painting here
EndPaint(hwnd,&ps);
return(0);
break;
// WM_DESTORY /////////////////////////////////////////////////////////
case WM_DESTROY:
PlaySound(NULL, hinstance_app, SND_PURGE);
// kill the application, this sends a WM_QUIT message
PostQuitMessage(0);
return(0);
break;

default:break;
}

// process any messages that we didn't take care of
return (DefWindowProc(hwnd, msg, wparam, lparam));

}
// ENDWINPROC /////////////////////////////////////////////////////////



errors are almost the same:


--------------------Configuration: icons - Win32 Debug--------------------
Compiling...
source.cpp
C:\Documents and Settings\Owner\Desktop\Comp Prog\C++\Windows Programming\Chapter Three\icons\source.cpp(73) : error C2065: '_MENU_EXIT' : undeclared identifier
C:\Documents and Settings\Owner\Desktop\Comp Prog\C++\Windows Programming\Chapter Three\icons\source.cpp(73) : error C2051: case expression not constant
C:\Documents and Settings\Owner\Desktop\Comp Prog\C++\Windows Programming\Chapter Three\icons\source.cpp(76) : warning C4060: switch statement contains no 'case' or 'default' labels
Error executing cl.exe.

icons.exe - 2 error(s), 1 warning(s)

Share this post


Link to post
Share on other sites
Quote:
Original post by Fixxer
// WM_COMMAND /////////////////////////////////////////////////////////
case WM_COMMAND:
switch (LOWORD(wparam))
{
case _MENU_EXIT:
PostQuitMessage(0);
break;
}
break;


It looks like the line above with "case _MENU_EXIT:" can't resolve _MENU_EXIT. Did you include the file holding its definition?

Share this post


Link to post
Share on other sites
yes but it is not on this computer i am on my brothers now, for some reason my damn computer keeps timing out when ever i try to access this site.

Share this post


Link to post
Share on other sites
first of all, where have you declared _MENU_EXIT? Make it MENU_EXIT, because the compiler reserves names beggining with an underscore then an uppercase. Make sure MENU_EXIT is declared. It also has to be const, so make it const int MENU_EXIT. [edit] beaten to it. And dont use a switch-case for only one possible output, use an if.

Share this post


Link to post
Share on other sites
here i got the file


/*====================================================================
*
* "Tricks of the windows game programming gurus"
*
* Nathan Krygier 6/17/05
* Chapter 3 Example Two "MENU.H"
*
*///==================================================================

//File Menu
#ifndef _MENU_NEW
#define _MENU_NEW 1000
#endif

#ifndef _MENU_OPEN
#define _MENU_OPEN 1001
#endif

#ifndef _MENU_CLOSE
#define _MENU_CLOSE 1002
#endif

#ifndef _MENU_SAVE
#define _MENU_SAVE 1003
#endif

#ifndef _MENU_EXIT
#define _MENU_EXIT 1004
#endif

// Help menu
#ifndef _MENU_HELP
#define _MENU_HELP 2000
#endif

#ifndef _MENU_ABOUT
#define _MENU_ABOUT 2001
#endif

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!