Removing a menu item |
Post Reply |
Author | |
71SoCal
Newbie Joined: 15 April 2008 Location: United States Status: Offline Points: 6 |
Post Options
Thanks(0)
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:
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
|
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
Something lile:
CXTPControl* pControl = CXTPControl::FromUI(pCmdUI);
if (pControl) pControl->GetControls()->Remove(pControl);
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
71SoCal
Newbie Joined: 15 April 2008 Location: United States Status: Offline Points: 6 |
Post Options
Thanks(0)
|
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...
|
|
71SoCal
Newbie Joined: 15 April 2008 Location: United States Status: Offline Points: 6 |
Post Options
Thanks(0)
|
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
|
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
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 |
|
71SoCal
Newbie Joined: 15 April 2008 Location: United States Status: Offline Points: 6 |
Post Options
Thanks(0)
|
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 itemCXTPControls* pControls = pMenuBar->GetControls(); CXTPControl* pControl = pControls->GetAt(4); // Utilities Menu itemCXTPControls* pUtilCtrls = pControl->GetControls(); int nItemCount = pUtilCtrls->GetCount();CXTPControl* pUtilMenuItem = pUtilCtrls->GetAt(13); pControls->Remove(pUtilMenuItem); //IDM_VIEW_RECALL_NOTICESIt 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
|
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
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 |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |