LRESULT CALLBACK MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId)
{
case IDM_QUIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
I don''t know what I''m doing wrong. It compiles fine and runs fine. But Quit in the File menu just won''t work.
Can anyone help me?
DAMN IT! Can't get the "menu" to work... please help
Ok. I have tried to get a menu in a normal window to work.
But I just can''t. I''m using VC++6.0.
I have made the menu in the rescources. I have med a res.h file
that got all the menu commands in it. The res.h file is included.
And I use this code to get the "Quit"(IDM_QUIT) to work.
But it doesn''t.
"To some its a six-pack, to me it's a support group."
August 24, 2000 02:36 PM
I assume that the menu is actually visible. You''re just having trouble handling commands. I don''t see anything obviously wrong with your code so perhaps you''re setting the menu id in your .rc file wrong.
I would run the code in a debugger and put a breakpoint on "switch (wmId)", then select your menu item and see what id comes out of the WM_COMMAND message. Alternatively you can use a window spying program (spyxx that comes with VC is really good) to see the messages going to the window.
-Mike
I would run the code in a debugger and put a breakpoint on "switch (wmId)", then select your menu item and see what id comes out of the WM_COMMAND message. Alternatively you can use a window spying program (spyxx that comes with VC is really good) to see the messages going to the window.
-Mike
i can think of 3 things:
A) you might just want to use switch(LOWORD(wParam))
i would thank what you have would work but you never know with this crazy API
B) your items are misnamed in your menue in your resource file
C) when creating your window, you didnt fill the lpszMenuName item of the WNDCLASS you used to to make your window with the proper name of your menue. (MAKEINTRESOURCE(MENU_ID))
A) you might just want to use switch(LOWORD(wParam))
i would thank what you have would work but you never know with this crazy API
B) your items are misnamed in your menue in your resource file
C) when creating your window, you didnt fill the lpszMenuName item of the WNDCLASS you used to to make your window with the proper name of your menue. (MAKEINTRESOURCE(MENU_ID))
Doesn''t MSVC automaticly create a "resource.h" file?
Maybe I have on older version, but I once tried to rename this file, but I couldn''t...
- Have you tried including "resource.h"?
- Did you give that menu item the IDM_QUIT identifier in your resource editor?
Maybe I have on older version, but I once tried to rename this file, but I couldn''t...
- Have you tried including "resource.h"?
- Did you give that menu item the IDM_QUIT identifier in your resource editor?
I don''t think you need to return a value after you handled a WM_COMMAND. Look at the lines after you handled the IDM_QUIT. I think that there shouldn''t be a return DefWindowProc call when you handle the default value. maybe you should comment that out and see if your program works.
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
How come you have return 0? You should return all unused messafges back to windows. Something like this:
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam){ switch (iMsg) { case WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, iMsg, wParam, lParam) ;}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement