Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How to hide/unhide a menu item in win32 programming

Posted on 2002-05-23
Medium Priority
Last Modified: 2013-12-03
Is there is any windows API to hide and unhide a menu item at runtime.
Question by:Shantanu
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 12

Expert Comment

ID: 7031329
If you have a HMENU handle to the menu, you can call EnableMenuItem() to disable or grey out menu options. As far as I know you can't actually completely hide menu options without removing them from the menu--this can also be done at run time, but is a more complex process than EnableMenuItem().

Author Comment

ID: 7031334
piknibbs, in VB we have visible property for menu bar which do the same but I want the paralle l in win32

Accepted Solution

RolandAZ earned 150 total points
ID: 7031499

//needed variables
 MENUITEMINFO menuiteminfo;
 UINT uItem = 0; //position of menu item to hide
 HMENU hMenuX;
 HMENU hSubMenu;
 int cchsize = 128; //
 ZCHAR sMenuText[256];
 int iSubMenu = 5;
//to hide menuitem in menubar, submenu 5, menuitem 0
  hMenuX = GetMenu(m_hWnd); //hWnd HWND of window
  hSubMenu = GetSubMenu(hMenuX,iSubMenu);
  menuiteminfo.cbSize = sizeof(menuiteminfo);
   //set mask at your discretion
  menuiteminfo.fMask = MIIM_CHECKMARKS | MIIM_DATA |
  menuiteminfo.cch = 128;
  menuiteminfo.dwTypeData = sMenuText;
  menuiteminfo.fType = MFT_STRING;
 GetMenuItemInfo(hSubMenu, uItem,TRUE,&menuiteminfo);
 RemoveMenu(hSubMenu,uItem, MF_BYPOSITION);
//end -------

//to unhide menuitem
//end ----------------

Key APIs are : GetMenu, GetSubMenu, GetMenuItemInfo,RemoveMenu,InsertMenuItem

Make sure to set menuiteminfo parameters fMask, cbSize,
cch,dwTypeData,and fType. Else you'll get an error.

Copy and paste into your routines and it should work fine.
Hope that gets you started...



Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question