Archived

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

penetrator

Adding menu to nehe code

Recommended Posts

Look at where he registers the window class, it specifies the menu to be used.

wc.lpszMenuName = MAKEINTRESOURCE(IDC_MENU);

Remember though, the menu takes up about 10 pixels or so, and covers up the top of the Open GL window. You will need to compensate for this or just leave it be. Perhaps a better solution would be to make the menu show up when the user hits a key and then when the user clicks on the window again, it hides it.

Share this post


Link to post
Share on other sites
here is a part of my CreateGLWindow function:

wc.lpszMenuName = (LPCSTR)IDC_MENU1;
wc.lpszClassName= "OpenGL"; // Set The Class Name

as you can see now i have a menu name. If i run the following instruction

LoadString(hInstance, IDC_MENU1, "OpenGL", 100);

i get an access violation !




www.web-discovery.net

Share this post


Link to post
Share on other sites
Use LoadMenu() instead:

HMENU LoadMenu(
HINSTANCE hInstance, // handle of application instance
LPCTSTR lpMenuName // menu name string or menu-resource identifier
);

Create the window and then call LoadMenu() and the SetMenu():

BOOL SetMenu(
HWND hWnd, // handle of window
HMENU hMenu // handle of menu
);

Whne you''re done, call DestroyMenu():

BOOL DestroyMenu(

HMENU hMenu // handle to menu to destroy
);

and SetMenu(hWnd, NULL); to unbind any bound menus from the window.

Crispy

Share this post


Link to post
Share on other sites
i already load windows.h header, so setmenu and loadmenu are already there. In the InitGL function i have these:

LoadMenu(hInstance,"IDC_PROVA2");
SetMenu(hWnd,LoadMenu(hInstance, MAKEINTRESOURCE(IDC_MENU)) );

IDC_MENU has been defined in the resource.rc file, so i have a simple menu. When i run the app, i get the File header but no sub-menus.



www.web-discovery.net

Share this post


Link to post
Share on other sites
Why are you loading two different menus? The reason I gave you the function prototypes was to spare you the time of looking them up - of course they have been declared and defined internally by WinAPI.

Are you storing the menu name/ID as a string or DWORD (a numeric constant) in the resource file. That is - does the name have quotes around it or not? If it does, you don''t need to call MAKEINTRESOURCE(). Additionally, set the WindowClass.lpszMenuName member to NULL when you create the window.

And finally - what do you mean by "submenus"? A submenu is an expanding list of menuitems that can be activated by moving the mouse cursor or caret over a menu item that traditionally has an arrow next to it: such as View->Toolbars in Internet Explorer.

Crispy

Share this post


Link to post
Share on other sites
The problem is that i have the menu correctly displayed, but when i click on it, i dont get the submenus defined with a AppendMenu statement. Also, when i click on the minimize or maximize or close box of the window, nothing happens. Why C++ has to be this damn difficult !



www.web-discovery.net

Share this post


Link to post
Share on other sites
It seems to me you''re using AppendMenu() incorrectly - remember - you have to reference the parent menu in order for some other menu to become a submenu. Here''s an example:


  
MENUITEMINFO MenuItem;

MenuItem.cbSize = sizeof(MENUITEMINFO);
MenuItem.fMask = MIIM_TYPE | MIIM_SUBMENU | MIIM_CHECKMARKS;
MenuItem.fType = MFT_STRING;
MenuItem.fState = MFS_ENABLED;
MenuItem.wID = NULL;
MenuItem.hbmpChecked = NULL;
MenuItem.hbmpUnchecked = NULL;
MenuItem.dwItemData = NULL;
MenuItem.dwItemData = NULL;
MenuItem.hSubMenu = ThisItemsSubMenu; //a 2nd level submenu that expands from this item; this item belongs to a 1st level submenu

MenuItem.cch = SomeString;
MenuItem.dwTypeData = (char *)malloc(SomeString.length());
strcpy(MenuItem.dwTypeData, SomeString.c_str());

InsertMenuItem(SubMenu, GetMenuItemCount(Menu), MF_BYPOSITION, &MenuItem); //let''s recap: "Menu" is the root menu, "SubMenu" is the menu

//into which you''re inserting (the 1st level submenu in this

//case) and "MenuItem" is the item that you''re instering that will

//be the root item for a 2nd level submenu



It doesn''t use AppendMenu(), but the idea is the same.

Crispy

Share this post


Link to post
Share on other sites