Solved

How to hide/unhide a menu item in win32 programming

Posted on 2002-05-23
3
1,315 Views
Last Modified: 2013-12-03
Is there is any windows API to hide and unhide a menu item at runtime.
Shantanu
0
Comment
Question by:Shantanu
3 Comments
 
LVL 12

Expert Comment

by:pjknibbs
Comment Utility
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().
0
 

Author Comment

by:Shantanu
Comment Utility
piknibbs, in VB we have visible property for menu bar which do the same but I want the paralle l in win32
0
 
LVL 1

Accepted Solution

by:
RolandAZ earned 50 total points
Comment Utility
Shantanu,

//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 |
    MIIM_ID | MIIM_STATE | MIIM_SUBMENU | MIIM_TYPE ;
  menuiteminfo.cch = 128;
  menuiteminfo.dwTypeData = sMenuText;
  menuiteminfo.fType = MFT_STRING;
 GetMenuItemInfo(hSubMenu, uItem,TRUE,&menuiteminfo);
 RemoveMenu(hSubMenu,uItem, MF_BYPOSITION);
//end -------

//////////////////////////////
//to unhide menuitem
//----------------------
  InsertMenuItem(hSubMenu,uItem,TRUE,&menuiteminfo);
  DrawMenuBar(m_hWnd);
//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...

Roland
 
 


 
 
     
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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 …
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now