Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - How to dynamically remove menu items?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

How to dynamically remove menu items?

 Post Reply Post Reply
Author
Message
daniel001 View Drop Down
Newbie
Newbie


Joined: 04 August 2003
Location: Netherlands
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote daniel001 Quote  Post ReplyReply Direct Link To This Post Topic: How to dynamically remove menu items?
    Posted: 08 September 2003 at 4:37pm

How can you dynamically remove menu items from your main menu in the XTreme Toolkit Pro?

I use to do something like this:

void CMainFrame::OnUpdateMenuItem(CCmdUI* pCmdUI)
{

pCmdUI->m_pMenu->RemoveMenu(pCmdUI->m_nID, MF_BYCOMMAND)

}

But now using the CommandBars it crashes because m_pMenu = NULL

Help!

 

Back to Top
kstowell View Drop Down
Admin Group
Admin Group


Joined: 25 January 2003
Location: MIchigan, USA
Status: Offline
Points: 496
Post Options Post Options   Thanks (0) Thanks(0)   Quote kstowell Quote  Post ReplyReply Direct Link To This Post Posted: 01 November 2003 at 2:39pm

Hello,

You can do this (modify menu items dynamically) by handling the WM_XTP_INITCOMMANDSPOPUP message, for example:
 
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
      //{{AFX_MSG_MAP(CMainFrame)
      ON_WM_CREATE()
      //}}AFX_MSG_MAP
      ON_XTP_INITCOMMANDSPOPUP()
      ON_XTP_CREATECONTROL()
END_MESSAGE_MAP()
 
void CMainFrame::OnInitCommandsPopup(CXTPCommandBar* pCommandBar)
{
    // get the list of commands for the popup.
    CXTPControls* pCommandList = pCommandBar->GetControls();
 
    // Remove "New" menu item from the File menu.
    CXTPControl* pCommandNew = pCommandList->FindControl(
        xtpControlButton, ID_FILE_NEW, TRUE, FALSE);
    if (pCommandNew)
    {
        pCommandList->Remove(pCommandNew);
    }
 
    // Rename menu item "Save" to "Save Document".
    CXTPControl* pCommandSave = pCommandList->FindControl(
        xtpControlButton, ID_FILE_SAVE, TRUE, FALSE);
    if (pCommandSave)
    {
        pCommandSave->SetCaption("&Save Document");
    }
 
    // Rename menu item "Print..." to "Print Document...".
    CXTPControl* pCommandPrint = pCommandList->FindControl(
        xtpControlButton, ID_FILE_PRINT, TRUE, FALSE);
    if (pCommandPrint)
    {
        pCommandPrint->SetCaption("&Print Document...");
    }
}

Cheers,
Codejock Support

Back to Top
dearvivekkumar View Drop Down
Newbie
Newbie


Joined: 13 June 2012
Location: New Delhi
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote dearvivekkumar Quote  Post ReplyReply Direct Link To This Post Posted: 01 October 2012 at 6:12am
How remove some menuitem if its happen to be of Popup menu like
File     Edit     Test     Help
                     M1
                     M2    >  S1
                     m3        S2
                                  S3

I want to remove "M2" here
Back to Top
free_user View Drop Down
Groupie
Groupie
Avatar

Joined: 08 March 2006
Status: Offline
Points: 24
Post Options Post Options   Thanks (0) Thanks(0)   Quote free_user Quote  Post ReplyReply Direct Link To This Post Posted: 17 January 2013 at 6:38am

hi

i think you can invisible action of "M2" when you want ro remove it.

Xtreme SuitePro (ActiveX) version 15.1.3
C# 2010
Xp Sp3
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.203 seconds.