Sign in to follow this  

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

This topic is 3816 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
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

This topic is 3816 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this