Public Group

Archived

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

Windows programming problem

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

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 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 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 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 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 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 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]

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 on other sites

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 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 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?

1. 1
2. 2
Rutin
20
3. 3
khawk
16
4. 4
A4L
14
5. 5

• 11
• 16
• 26
• 10
• 11
• Forum Statistics

• Total Topics
633755
• Total Posts
3013706
×