Print Page | Close Window

Removing a menu item

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=10245
Printed Date: 28 April 2024 at 2:17am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Removing a menu item
Posted By: 71SoCal
Subject: Removing a menu item
Date Posted: 15 April 2008 at 6:51pm
I've loaded a skin for my application, and added the following code to wrap my MainFrame menu:
 

if (!InitCommandBars())

return -1;

CXTPCommandBars* pCommandBars = GetCommandBars();

CXTPMenuBar* pMenuBar = pCommandBars->SetMenu(_T("Menu Bar"), IDR_MAINFRAME);

pMenuBar->SetShowGripper(false);

The problem is that legacy code is trying to remove a menu item, and it's crashing the app:

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

The m_pMenu object is NULL.  Should I replace this call with a CodeJock call?  And if so, what call is it...I can't find a RemoveMenu function on any of the objects.
 
Thanks for any help...
 
Mike



Replies:
Posted By: Oleg
Date Posted: 16 April 2008 at 6:18am
Something lile:
 
CXTPControl* pControl = CXTPControl::FromUI(pCmdUI);
if (pControl) pControl->GetControls()->Remove(pControl);


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: 71SoCal
Date Posted: 16 April 2008 at 5:19pm
Thanks for the response. 
 
I added that code to my OnUpdateUI handler and it compiled and I was able to step past it.  I'm still crashing though, and I'm hoping that you might have an idea why.
 
As soon as I hit F5 (run), I end up crashing in this xtpcommandbar.cpp file code shown below (the red highlighted code is the actual crash line):

void CXTPCommandBar::CCommandBarCmdUI::Enable(BOOL bOn){

m_bEnableChanged = TRUE;

ASSERT(m_pControl != NULL);

if (!m_pControl)

return;

if (m_pControl->GetAction())

{

m_pControl->SetEnabled(bOn ? -1 : FALSE);

}

else

{

m_pControl->SetEnabled(bOn);

if (!bOn && !m_bCheckedChanged) m_pControl->SetChecked(FALSE);

}

}

Before I step over that line of code, m_pControl has a value, but the data members inside don't seem to have valid data.

Any ideas would be appreciated.  Thanks again...
-Mike


Posted By: 71SoCal
Date Posted: 16 April 2008 at 5:24pm
I just realized that the m_pControl should be deleted at this point??? 
 
So now I'm wondering why the framework is calling the Enable() on that object...assuming is should be gone.  Is there something else that needs to be done to get the object set to NULL?
 
Thanks,
Mike


Posted By: Oleg
Date Posted: 17 April 2008 at 1:16am
Right. Actually do you really need to delete it in Updatehandler? Maybe you can Hide/show it instead?
 
pControl->SetVisible(TRUE/FALSE);
 
 
 
also to prevent this problem add pCmdUI>Enable(FALSE);  before you delete control.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: 71SoCal
Date Posted: 17 April 2008 at 1:47pm
Thanks Oleg,
 
Yes, I agree that this code shouldn't be removing an item in its Update handler.  Someone coded it that way long ago, so I moved it elsewhere.
 
The problem still exists though, that I can't delete that menu item.  I don't understand how CodeJock organizes the objects.  I've got the hierarchy chart.
 
On my mainframe menu, I want to remove the 14th item down on the 5th menu...I hope I explained that correctly.
 
Here's how I would expect it to be coded:
 

CXTPCommandBars* pCommandBars = GetCommandBars();

CXTPMenuBar* pMenuBar = pCommandBars->SetMenu(_T("Menu Bar"), IDR_MAINFRAME);

pMenuBar->SetFlags(xtpFlagAddMDISysPopup);

pMenuBar->SetShowGripper(false);

if (!GetAcesConfig()->GetSafetyRecallNoticesEnabledFlag())

{

// Remove the safety recall notice menu item

CXTPControls* pControls = pMenuBar->GetControls();

CXTPControl* pControl = pControls->GetAt(4); // Utilities Menu item

CXTPControls* pUtilCtrls = pControl->GetControls();

int nItemCount = pUtilCtrls->GetCount();

CXTPControl* pUtilMenuItem = pUtilCtrls->GetAt(13);

pControls->Remove(pUtilMenuItem); //IDM_VIEW_RECALL_NOTICES

It crashes because the second Remove() call is out of index...it is referring to the top-level menu.  How do I get to that secondary item to remove it?

I actually have this entered as a tech support request, so I apologize for the redundancy. If you answer there, I'll post back here for everyone else.
 
Thanks,
Mike


Posted By: Oleg
Date Posted: 17 April 2008 at 2:19pm
try 

CXTPControls* pControls = pMenuBar->GetControls();

CXTPControl* pControl = pControls->GetAt(4); // Utilities Menu item

CXTPControls* pUtilCtrls = pControl->GetCommandBar()->GetControls(); // POpup Controls

int nItemCount = pUtilCtrls->GetCount();

CXTPControl* pUtilMenuItem = pUtilCtrls->GetAt(13);

pUtilCtrls->Remove(pUtilMenuItem);



-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS



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