Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - CXTPCommandBar::LoadMenu Causing crash
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

CXTPCommandBar::LoadMenu Causing crash

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


Joined: 13 February 2006
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote MarkIRS Quote  Post ReplyReply Direct Link To This Post Topic: CXTPCommandBar::LoadMenu Causing crash
    Posted: 14 February 2006 at 8:49am

Hi Everyone,

I'm getting a crash in our program when we run CXTPCommandBar::LoadMenu.  The problem appears to be caused by the m_pControls, which is set to NULL at that time.

The LoadMenu function is being called because we are adding additional items (at runtime) to our CXTPPopupBar.  Does anyone know what the problem might be? 

I've also noticed that there was a similar post about this here on the forums, does anyone know what the result of that was?




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: 14 February 2006 at 11:16am

Hello,

We need sample application from you to see what you try to do.

Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
MarkIRS View Drop Down
Newbie
Newbie


Joined: 13 February 2006
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote MarkIRS Quote  Post ReplyReply Direct Link To This Post Posted: 14 February 2006 at 3:52pm

Hi Oleg,

Thanks for replying to my post, I've been trying to replicate this in a simple program or using one of your sample applications but I've been having a bit of a problem replicating it.

Basically what we are doing is using a LoadMenu() function on a CXTPPopupBar* pointer that was created as follows:

m_pLayoutsPopupBar =
CXTPPopupBar::CreatePopupBar(GetCommandBars());


We then dynamically re-populate m_pLayoutsPopupBar is the user has saved a new layout.  To repopulate m_pLayoutsPopupBar we create a temporary CMenu, and then call the following to load the new menu:


m_pLayoutsPopupBar->LoadMenu(&TempMenu,TRUE);


This works fine the first time through, but the next time through the m_pControls member variable is invalid and the LoadMenu function causes a crash.

I have been able to avoid the crash using the following code:


CXTPControls* pControls = m_pLayoutsPopupBar->GetControls();
    if ((pControls)
        &&(AfxIsValidAddress(pControls
            , sizeof(CXTPControls), FALSE)))


But that does not make my menu work.  What I'm having trouble understanding is how m_pControls, a private member variable, is getting corrupted?

I will keep trying to replicate it in a sample app, and if I am successful I will send you that.  Hopefully in the mean time the above explanation will give you some ideas as to what the problem maybe.

Also, we are using Visual Studio 6.0, MFC, and version 9.80 of your library.

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: 15 February 2006 at 7:56am

Hello,

It is very bad idea to store pointer m_pLayoutsPopupBar. - it will be corrupted if you Load previous state of commandbars or user made customization and delete some controls with this popup. (guess it is the reason that m_pControls is NULL)

 

Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
MarkIRS View Drop Down
Newbie
Newbie


Joined: 13 February 2006
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote MarkIRS Quote  Post ReplyReply Direct Link To This Post Posted: 15 February 2006 at 8:45am

Hi Oleg,

Thats interesting, so we shouldn't be storing m_pLayoutsPopupBar? 

How then should we be reloading the menu when we need to?  As explained above when the user wants to save a layout, we re-create the menu (with the new addition) and then load it into m_pLayoutsPopupBar.  If we don't keep a pointer to m_pLayoutsPopupBar, how do we load our new menu?

Also what do we do about freeing the memory used to create m_pLayoutsPopupBar?

Thanks for your help!

Back to Top
MarkIRS View Drop Down
Newbie
Newbie


Joined: 13 February 2006
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote MarkIRS Quote  Post ReplyReply Direct Link To This Post Posted: 17 February 2006 at 3:18pm
Does anyone have any ideas how to do this?  Basically I'm looking for information on how to repopulate a pupup menu at a given point while our program is running?

I've taken a look at the Dyamic Menu sample, but I cannot seem to get it working for a popup menu (CXTPPopupBar)?

Any help with this would be appreciated.
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: 20 February 2006 at 10:38am

Hello,

I guess you can catch

ON_XTP_INITCOMMANDSPOPUP()

void CMainFrame::OnInitCommandsPopup(CXTPPopupBar* pCommandBar)
{

if ThisIsMyPopup(pCommandBar )
{

   pCommandBar->LoadMenu(&TempMenu,TRUE);

}

}

it will update menu before user popup it.

 

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.266 seconds.