Windows programming problem
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.
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.
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
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
-Arek the Absolute"The full quartet is pirates, ninjas, zombies, and robots. Create a game which involves all four, and you risk being blinded by the sheer level of coolness involved." - Superpig
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?
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
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.
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.
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.
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)
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)
-----------------"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)
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:
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]
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 WinMainLRESULT 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]
-Ax
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...
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."
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."
-----------------------------"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."
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]
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]
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.
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."
-----------------------------
"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."
-----------------------------"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."
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?
As for the email I mention in my previous post can anyone 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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement