Print Page | Close Window

How to dynamically remove menu items?

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=153
Printed Date: 27 November 2024 at 1:11am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: How to dynamically remove menu items?
Posted By: daniel001
Subject: How to dynamically remove menu items?
Date 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!

 




Replies:
Posted By: kstowell
Date 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



Posted By: dearvivekkumar
Date 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


Posted By: free_user
Date 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



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net