Print Page | Close Window

CXTPCommandBar::LoadMenu Causing crash

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=3650
Printed Date: 06 October 2024 at 5:25am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: CXTPCommandBar::LoadMenu Causing crash
Posted By: MarkIRS
Subject: CXTPCommandBar::LoadMenu Causing crash
Date 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 https://forum.codejock.com/forum_posts.asp?TID=3123&KW=LoadMenu - post about this here on the forums, does anyone know what the result of that was?







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


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



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


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



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


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



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