Hiding a menu item in MFC - visual-c++

How can I hide a menu item under certain conditions in MFC?
I'm not interested in just graying it out.

Add an Update Handler for your menu item (using ON_UPDATE_COMMAND_UI).
This line should appear in your message map:
ON_UPDATE_COMMAND_UI(ID_MYMENUITEM, OnUpdateMyMenuItem)
In the handler, use this code:
void CMainFrame::OnUpdateMyMenuItem(CCmdUI *pCmdUI)
{
if (pCmdUI->m_pMenu!=NULL)
pCmdUI->m_pMenu->DeleteMenu(pCmdUI->m_nID, MF_BYCOMMAND);
}

Or if you are removing a single menu item use CMenu::RemoveMenu

Related

ODOO 12 menuitem not appears

Good day to all.
I am trying to add menu item to module Events with my custom module.
Also, in my module i add some models, so i pretty sure that module installed successfully.
In xml file i use this line to add menuitem
<menuitem name="City Catalog" id="menu_event_city_catalog" parent="event.menu_event_mail_schedulers"/>
Menu item is created(i can find it on menu items menu), and parent is setted correct, but there is no changes in UI.
When i try to add menu item thru UI - it appears.
I try this line with sequence and action attribute setted, but no effect.
Whould be grateful for any help, and sorry for my bad english.
try to add menu action
<menuitem name="City Catalog" id="menu_event_city_catalog" parent="event.menu_event_mail_schedulers" action="your menu action"/>
You must need to define action in menu to get reflation of your custom define menuitem.
In odoo 12 you have to mention an action for a menuitem. Else it will not shown.
If it is a custom model, Please add security.

JavaFX : How to retrieve the Menu's subMenu ContextMenu instance

I am trying to get the Menu's submenu ContextMenu instance. Is there a way to get that? I actually want to add some event filters on the submenu ContextMenu.
I tried getting the ContextMenu as below.
Menu menu = new Menu("Menu");
menu.getItems().addAll(...); // Will be added dynamically
menu.setOnShown(e->{
ContextMenu contextMenu = menu.getItems().get(0).getParentPopup();
contextMenu.addEventFilter(..., ...);
});
How can I ensure that I set the event filter only once to the context menu?
Please note that the menu can be an item in MenuBar or as an item in Menu itself.
You mentioned that menu can be a MenuBar or Menu. So it depends on how deeply the menus are nested and whether getItems().get(0) could also return a MenuItem.
So the following code might be a solution to your first question:
menu.getItems().get(0).getParentMenu().getParentMenu().getParentPopup();
// or
menu.getItems().get(0).getParentMenu().getParentPopup();
// or...
Related to your second question: You have to memorise which EventHandlers have already been added, for example in a collection. Or use one of the so called convenience methods which you are already using with menu.setOnShown.

How to force CMFCPropertyGridCtrl to refresh after adding an item?

I add an item to the CMFCPropertyGridCtrl, but the new item does not show up only if i click the CMFCPropertyGridCtrl.
Now i have a indirect solution to show up the new item by calling ExpandAll(), but i don't want to expand those i have collapsed.
Is there a way to show up the new item gracefully ?
After CMFCPropertyGridProperty.AddSubItem() call, new item will show up by the following two calls:
YourGridCtrl.AdjustLayout();
YourGridCtrl.RedrawWindow();
Hope it helps !

Creating a navigation menu item in Orchard

I have written an Orchard Module and would like an item to appear in a Navigation list when the module is Enabled. Ideally, I would like to be able to remove the item when the Module is disabled.
Where should I hook into to for when the module is enabled and disabled?
How do I programmatically add a menu item to an already existing Navigation?
You can implement the IMenuProvider interface for this. An example implementation might look something like this:
namespace Orchard.Bar {
public class SuperMenuProvider : IMenuProvider {
private readonly IOrchardServices _orchardServices;
public SuperMenuProvider(IOrchardServices orchardServices) {
_orchardServices = orchardServices;
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
public void GetMenu(IContent menu, NavigationBuilder builder) {
string position = "10";
builder.Add(T("Foo"), position, item => item.Url("http://foo.com").AddClass("someClass"));
builder.Add(T("Bar"), position + ".1", item => item.Action("Index", "Foo", new { area = "Orchard.Bar" }));
if (_orchardServices.Authorizer.Authorize(Orchard.Security.StandardPermissions.AccessAdminPanel)) {
builder.Add(T("Secure FooBar"), position + ".2", item => item.Action("Index", "Secure", new { area = "Orchard.Bar" }));
}
}
}
}
This will appear on all menus on the front end. You may want to put in the name of the menu you are targeting if you know for sure that is what it is called (default in Orchard is "Main Menu", people don't generally change it to be honest). This could be a little brittle, so you may want it customizable, either with a site setting or you could create a part that you attach to the menu content type that lets the admin specify whether to show your menu items on the said menu.
An alternative approach would be to hook into the modules enable event using IFeatureEventHandler and using the content manager to create menu items with urls and adding them to a specified Menu. I don't really recommend this approach; you lose control of the menu items (e.g. to update a url), they can be removed from the menu accidentally, you have to know the name of the Menu you are adding them to, you are more limited (cant do permissions checks etc.).
I assume you are talking about showing up on the front end. If you talking about the admin menu then check out pretty much any module for a file generally called AdminMenu.cs, plenty of examples :)
The question doesn't specify what the module does so I guess we're to assume that it creates a content type. In that case you have (at least) two options:
In the Content Type's Content Definition go to Add Parts and add the Menu part. This will allow you to add a content item to a menu from the item's content editor.
From the Navigation menu choose the appropriate Menu and select add a Content Menu Item. Note that the content type must be set as "listable" in Content Definition in order for the items to be listed as a choice.
Disabling the module should remove the item from the navigation in either case.

TestComplete Menu Item

I am new to TestComplete. I have a question and it may be something impossible or too simple. I have a toolbar containg File, Edit, View, etc. I want to get one item (eg. Edit) to mapped objects. I can get the whole toolbar only. I want to simulate a click event on Edit. How can I do this?
As a rule, TestComplete does not work with menu items as with separate objects. It works with a menu object or even only with a menu's parent object and you can specify which item to select by passing the caption of this item to the corresponding method of a menu object. For example:
objMenu.Click("Edit|Paste");
// or
parent.MainMenu("Edit|Paste");
Please find more details on how TestComplete interacts with menus in the Working With Menus help topic.

Resources