LoadMenu error.

Started by
1 comment, last by The Nerd 16 years, 9 months ago
I was reading the Game Programing Genesis article, and it was great, but I am having trouble leading a menu: my code:

wincl.hIcon = LoadIcon(hThisInstance, "ICON_MAIN");
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = LoadMenu(hThisInstance, MAKEINTRESOURCE(MAIN_MENU));              
wincl.cbClsExtra = 0;                      
wincl.cbWndExtra = 0;
resource file:

MAIN_MENU MENU DISCARDABLE
{
    POPUP "&File"
    {
        MENUITEM "&New",        MENUID_NEW
        MENUITEM "&Open...",    MENUID_OPEN
        MENUITEM "&Save",       MENUID_SAVE
        MENUITEM "Save &As...", MENUID_SAVEAS
        MENUITEM "E&xit",       MENUID_EXIT
    }
    POPUP "&Help"
    {
        MENUITEM "&Contents",   MENUID_CONTENTS
        MENUITEM "&Index...",   MENUID_INDEX
        MENUITEM "&About",      MENUID_ABOUT
    }
}
resource.h :

#define MAIN_MENU		9

#define MENUID_NEW		0
#define MENUID_OPEN		1
#define MENUID_SAVE		2
#define MENUID_SAVEAS	3
#define MENUID_EXIT		4
#define MENUID_CONTENTS	5
#define MENUID_INDEX	6
#define MENUID_ABOUT	7
there error I get is: "cannot convert `HMENU__*' to `const CHAR*' in assignment" it is on this line:

wincl.lpszMenuName = LoadMenu(hThisInstance, MAKEINTRESOURCE(MAIN_MENU));  
thanks in advance (obviously this isnt full source, if you need anything else let me know)
Advertisement
The lpsz part of lpszMenuName means that the parameter is a string (Long Pointer String Zero terminated). You dont want an HMENU, you just want a string representing the menu name:

wincl.lpszMenuName = MAKEINTRESOURCE(MAIN_MENU);
Thanks a lot, it compiles fine, and after figuring out how to add .rc files to your project in Dev-C++ it works fine :D I also figured out that the gcc MinGW compiler requires you to use BEGIN/END instead of {} in .rc files. Thanks again man ;)

This topic is closed to new replies.

Advertisement