Microsoft KB Archive/230201

{|
 * width="100%"|

HOWTO: Dynamically Change Position of Menu Items on Top-Level Menu Bar

 * }

Q230201

-

The information in this article applies to:


 * Microsoft Win32 Software Development Kit (SDK), on platform(s):
 * Microsoft Windows 98
 * Microsoft Windows 95
 * Microsoft Windows NT Server version 4.0
 * Microsoft Windows NT Workstation version 4.0
 * the operating system: Microsoft Windows 2000

-

SUMMARY
This article describes how menu item positions on the top-level menu bar can be changed at run time. If the top-level menu items have sub menus they will also be moved with the top-level menu.

MORE INFORMATION
Steps to change the position of menu item:


 * 1) Get the handle to the menu.
 * 2) Create and initialize a MENUITEMINFO structure.
 * 3) Copy the menu item info from the item to be changed into the new MENUITEMINFO structure.
 * 4) Insert the new item so that it precedes the position specified.
 * 5) Remove the original item.
 * 6) Redraw the menu bar.

 HMENU hMenu; TCHAR szBuffer[40]; TCHAR buf[50]; MENUITEMINFO MInfo; int OrigPosition, NewPosition ;

hMenu           = GetMenu(hWnd); MInfo.cbSize    = sizeof(MENUITEMINFO); OrigPosition    = 2; NewPosition     = 4;

MInfo.fMask     = MIIM_DATA | MIIM_ID |MIIM_SUBMENU |MIIM_TYPE; MInfo.fType     = MFT_STRING; MInfo.fState    = MFS_DEFAULT; MInfo.dwTypeData = szBuffer; MInfo.cch       = 40; //sizeof(Buffer);

if(GetMenuItemInfo(hMenu, OrigPosition, TRUE, &MInfo)) {  if(InsertMenuItem(hMenu, NewPosition, TRUE, &MInfo))  // Insert between 3 and 4 {     RemoveMenu(hMenu, OrigPosition, MF_BYPOSITION); DrawMenuBar(hWnd); }  } Additional query words:

Keywords : kbMenu kbOSWinNT400 kbOSWin2000 kbSDKWin32 kbGrpDSUser kbOSWin95 kbOSWin98

Issue type : kbhowto

Technology : kbWin32SDKSearch kbAudDeveloper kbSDKSearch kbWin32sSearch