Archived

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

Mage_gr

Windows programming problem

Recommended Posts

Hi all.I have a problem in Windows programming which I can not solve.I am reading the Tricks of the Windows programming and I am in the chapter where it says how to make a menu work.So as usual I load the menu and it works.When I try to make it to interact with the user and add modify the WM_COMMAND it becomes like this: case WM_COMMAND: { switch(LOWORD(wparam)) { case ID_FILE_WHAT: { MessageBox(hwnd,"WHAT","What?!What do u want?",MB_OK|MB_ICONEXCLAMATION); }break; case ID_FILE_OPEN : { PlaySound(MAKEINTRESOURCE(SOUND_HAWK),hinstance_app,SND_RESOURCE|SND_ASYNC); }break; case ID_FILE_ETC : { PostQuitMessage(0); }break; default:break; } }break; So when I run the program it copiles correctly but load the window without a menu!?!!?What is my mistake? When you see a roller coaster, get on it,put your hands in the air,and ride it to the very end.Life doesn''t remember you unless you kick,scream,and claw your way to the top.There is nothing in the world that is impossible.If you believe that you can do it, you will.

Share this post


Link to post
Share on other sites
Haven''t tested it, but that''s not the way I arrange the commands. I follow this format. It works, but it may or may not be what''s causing you your problems.

case WM_COMMAND:{
switch(LOWORD(wparam)){
case ID_FILE_WHAT:{
MessageBox(hwnd,"WHAT","What?!What do u want?",MB_OK | MB_ICONEXCLAMATION);
return 0;
}
case ID_FILE_OPEN:{
// whatever...
return 0;
}
.... etc.

If it''s not that, the problem may be somewhere else. Good luck!

-Arek the Absolute

Share this post


Link to post
Share on other sites
quote:
Original post by Mage_gr
So when I run the program it copiles correctly but load the window without a menu!?!!?What is my mistake?



That sounds like a problem with the menu loading code, not the code that responds to a menu selection event which you have shown here. I don''t have that book, so I have no idea how it loads the menu. Does the program run as a framed window or fullscreen? Does it use system provided menus or does it roll its own?

Share this post


Link to post
Share on other sites
It runs as a framed window.I followd exactly what it says n the book but still nothing.HELP!

When you see a roller coaster, get on it,put your hands in the air,and ride it to the very end.Life doesn''t remember you unless you kick,scream,and claw your way to the top.There is nothing in the world that is impossible.If you believe that you can do it, you will.

Share this post


Link to post
Share on other sites
It''s got to be with the loading code, or maybe the menu itself.

Post some code?

-----------------
"Who the hell wants to hear actors talk?" - H. M. Warner
"Everything that can be invented has been invented." - Charles H. Duell
"I think there is a world market for maybe five computers." - Thomas Watson, Chairman of IBM (1943)

Share this post


Link to post
Share on other sites
Well, like they're all saying, I seriously doubt that your message handling part of the code, which you posted (that handles the actions taken after an item your menu is clicked, because a message was sent and the handler handled it via your FILE_? handling procedures). First you have to "attach" your menu, which we'll assume you have in a resource (.rc) file. Consider this:

   

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow)
{
MSG msg;
...
WNDCLASS wc;
...
wc.lpszClassName = "WndClass";
wc.lpszMenuName = MAKEINTRESOURCE(IDMAINMENU); /*Chances are this is what you're missing. IDMAINMENU refers to what you're using as the identifier in your resource file and what you've defined in the header file you're using with your resource file (i.e. #define IDMAINMENU 101) */
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hIcon = LoadIcon(hInst,MAKEINTRESOURCE(IDAPPLICON));
if (!RegisterClass(&wc))
return 0;
...
return msg.wParam;
}//End WinMain

LRESULT CALLBACK MainWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch (msg) {
...
case WM_COMMAND:{
switch(LOWORD(wparam)){
case ID_FILE_WHAT:
MessageBox(hwnd,"WHAT","What?!What do u want?",MB_OK | MB_ICONEXCLAMATION);
break;
case ID_FILE_...:
MessageBox(hwnd,"...","...",...);
break;
...
}
break; //switch


default :
return( FALSE );

//End WM_COMMAND

}
}//End MainWndProc


//So on and so forth...



Anyway, what you're looking to do is actually put you menu in via "wc.lpszMenuName = MAKEINTRESOURCE(IDMAINMENU);" in your window class (if you see "wc.lpszMenuName = NULL;", take your best guess as to why your menu isn't showing up...). Nonetheless, there may be other things wrong with your code.

Later,
--Ax

[edited by - Ax on July 29, 2002 12:46:57 AM]

Share this post


Link to post
Share on other sites
Open you .rc file using notepad and make sure that the name of your menu is the same name in your program. Also, I just looked at your source code, try adding this to your code...

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam)

HINSTANCE hInstance;
.
.
.
switch(message)
{
case WM_CREATE:
hInstance = ((LPCREATESTRUCT) lParam)->hInstance;
LoadMenu = (hInstance, MAKEINTRESOURCE(IDAPPLICON));


take a look at www.winprog.org, that should help.


-----------------------------
"There are ones that say they can and there are those who actually do."

"...u can not learn programming in a class, you have to learn it on your own."

Share this post


Link to post
Share on other sites
Hey guys I will post the whole code so that you will see it.But it says that there are too many characters and I can not post it.Still I haven't found my mistake.Only one strange thing.While in the book it edits the rc file and creates the menu via sorce code in the 6.0 version it is created easier.So if you understand when I made the menu it worked.I ran the program and I had a window with a menu and I was happy.Now that I tried to add soemthing so that the menu could do something when I ran the program there is no menu.I know I must have tired you but please help.




P.S.:Can I email my program to someone so that he can see it and find my mistake?

When you see a roller coaster, get on it,put your hands in the air,and ride it to the very end.Life doesn't remember you unless you kick,scream,and claw your way to the top.There is nothing in the world that is impossible.If you believe that you can do it, you will.

[edited by - Mage_gr on July 30, 2002 6:57:12 PM]

Share this post


Link to post
Share on other sites
I have that book, "Tricks..." what page are u looking at?


-----------------------------
"There are ones that say they can and there are those who actually do."

"...u can not learn programming in a class, you have to learn it on your own."

Share this post


Link to post
Share on other sites
The chapter creating a menu in page 116 and the chapter loading a menu in page 119 works fine it compiles and runs correctly.But in page 122 starts the chapter which troubles me responding to menu event messages.HELP!!!

As for the email I mention in my previous post can anyone help?

Share this post


Link to post
Share on other sites
I just went down to the dungeon to fetch my "Tricks.." book. I can see why u are baffled. Its Win32 programming is rather obscured. For some help on menus:
www.winprog.org and www.gametutorials.com
I could try to explain but I would hate to mislead u since I not sure what u are asking.
Although, I recommend the book Charles Petzold''s Windows Programming book or you may run into other problems in the future on your win32 programming.



-----------------------------
"There are ones that say they can and there are those who actually do."

"...u can not learn programming in a class, you have to learn it on your own."

Share this post


Link to post
Share on other sites
Thanks for the help but I want to follow the book because it is as you know for game programming.In the cd I took with the book is an identical program but I can not understand the difference.Hey guys any help?Somehow I can give you the whole program to examine?


P.S.:I discovered something.When I clicked in the resources they do not open and it tells me that there is an error
error RC2144 : PRIMARY LANGUAGE ID not a number.......what the heck is this?


And then it says error RC2135: file not found :1

"What the heck is this is not among the errors"

[edited by - Mage_gr on July 31, 2002 6:11:33 PM]

Share this post


Link to post
Share on other sites