-
Menu not showing
Hi everybody,
I started with Visual C++ and stumbled upon a small problem.
I began with the tutorial which can be found here: Link.
This all works well. I'm getting my application with the text in the middle. Perfect.
Now I want a menu with an option to close the application. I created a menu with the resource editor in Visual C++. After that I got a header file and a script file.
The header file contains:
Code:
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by recource.rc
//
#define IDR_MENU1 101
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
And the most important parts in the script are:
Code:
#include "resource.h"
IDR_MENU1 MENU DISCARDABLE
BEGIN
MENUITEM "&File", 65535
END
I know, this doesn't close the application, but I wanted to see if the menu would show up at all.
I was under the assumption that I can make the menu visible by simple stating:
Code:
windowClass.lpszMenuName = MAKEINTRESOURCE("IDR_MENU1");
But..... This isn't the case.
What am I doing wrong here?
Any help is much appreciated.
-
Don't use quotes around the menu identifier.
Code:
windowClass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
If you haven't already, "resource.h" needs to be included in the .c or .cpp file as well as the resource file.
-
You can designate your menu resource with a numeric identifier or a string but not both.
Since your menu resource is identified with a number (101) then use that with MAKEINTRESOURCE, ie remove the quotes:
Code:
windowClass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
If your menu was identified with a string then you wouldn't need to use the MAKEINTRESOURCE macro at all, you would just use the string identifier.
edit: beaten by 'tmouse.
-
Code:
case WM_CREATE:
{
HMENU hMenu, hSubMenu;
HICON hIcon, hIconSm;
hMenu = CreateMenu();
hSubMenu = CreatePopupMenu();
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File");
SetMenu(hwnd, hMenu);
}
break;
Something like that.
-
@Ideswa
Your method works. Thanks.
Using quotes or not, I can't get the menu to work by using the other method. Ah well, as long as it works now....
Thnx
-
fixed it
Hi, fixed the menu... I didn't add the file to my project (silly mistake to make)... Figured it was included automatically... Guess not...
Thnx for the replies!