Solved

How to hide/unhide a menu item in win32 programming

Posted on 2002-05-23
3
1,621 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
[X]
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
3 Comments
 
LVL 12

Expert Comment

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

Author Comment

by:Shantanu
ID: 7031334
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
ID: 7031499
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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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 this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

623 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