Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - Removing a menu item
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Removing a menu item

 Post Reply Post Reply
Author
Message
71SoCal View Drop Down
Newbie
Newbie


Joined: 15 April 2008
Location: United States
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote 71SoCal Quote  Post ReplyReply Direct Link To This Post Topic: Removing a menu item
    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
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
71SoCal View Drop Down
Newbie
Newbie


Joined: 15 April 2008
Location: United States
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote 71SoCal Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
71SoCal View Drop Down
Newbie
Newbie


Joined: 15 April 2008
Location: United States
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote 71SoCal Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
71SoCal View Drop Down
Newbie
Newbie


Joined: 15 April 2008
Location: United States
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote 71SoCal Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
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.172 seconds.