Jump to content
  • Advertisement
Sign in to follow this  
hkBattousai

[Win32/C++] I have trouble creating menu bar

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

	HMENU hMenu = CreateMenu();
	InsertMenu(hMenu, 0, MF_BYPOSITION | MF_STRING, 100, TEXT("File"));
	InsertMenu(hMenu, 1, MF_BYPOSITION | MF_STRING, 101, TEXT("Edit"));
	InsertMenu(hMenu, 2, MF_BYPOSITION | MF_STRING, 102, TEXT("View"));
	SetMenu(hWnd, hMenu);
	DrawMenuBar(hWnd); //hWnd is the handle of the main window



This code work nice and its output appears like this : But I want to use InsertMenuItem() function instead of InsertMenu() because InsertMenuItem() supports more features. The code I wrote is below :
	HMENU hMenu = CreateMenu();
	MENUITEMINFO mii;
	memset(&mii, 0, sizeof(MENUITEMINFO));

	mii.cbSize	= (UINT)		sizeof(MENUITEMINFO);
	mii.fMask	= (UINT)		MIIM_FTYPE | MIIM_STATE | MIIM_STRING;
	mii.fType	= (UINT)		MIIM_STRING;
	mii.fState	= (UINT)		MFS_DEFAULT | MFS_ENABLED;
	mii.dwTypeData	= (LPTSTR)		TEXT("File");
	mii.cch		= (UINT)		4;
	InsertMenuItem(hMenu, 0, TRUE, (LPCMENUITEMINFO) &mii);

	mii.cbSize	= (UINT)		sizeof(MENUITEMINFO);
	mii.fMask	= (UINT)		MIIM_FTYPE | MIIM_STATE | MIIM_STRING;
	mii.fType	= (UINT)		MIIM_STRING;
	mii.fState	= (UINT)		MFS_ENABLED;
	mii.dwTypeData	= (LPTSTR)		TEXT("Edit");
	mii.cch		= (UINT)		4;
	InsertMenuItem(hMenu, 1, TRUE, (LPCMENUITEMINFO) &mii);

	mii.cbSize	= (UINT)		sizeof(MENUITEMINFO);
	mii.fMask	= (UINT)		MIIM_FTYPE | MIIM_STATE | MIIM_STRING;
	mii.fType	= (UINT)		MIIM_STRING;
	mii.fState	= (UINT)		MFS_ENABLED;
	mii.dwTypeData	= (LPTSTR)		TEXT("View");
	mii.cch		= (UINT)		4;
	InsertMenuItem(hMenu, 2, TRUE, (LPCMENUITEMINFO) &mii);
	
	SetMenu(hWnd, hMenu);
	DrawMenuBar(hWnd);



This time output becomes like this : Why do the menu item names are listed vertically in the second code? How should I modify the second code so that its output becomes like the first one's?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Originally published by MSDN
MIIM_TYPE
Retrieves or sets the fType and dwTypeData members. Windows 98/Me, Windows 2000/XP: MIIM_TYPE is replaced by MIIM_BITMAP, MIIM_FTYPE, and MIIM_STRING.


	mii.fMask = MIIM_STRING | MIIM_STATE | MIIM_STRING;
mii.fType = MIIM_STRING;


I replaced MIIM_TYPE by MIIM_STRING, and now it works great.

Now I will try to add pull down menus to this menu bar.
I'll ask here if I happen to get confused again.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!