Solved

How to hide/unhide a menu item in win32 programming

Posted on 2002-05-23
3
1,408 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
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 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