Print Page | Close Window

Getting CMenu from CXTPControlPopup I get error

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=22419
Printed Date: 01 October 2024 at 8:33pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Getting CMenu from CXTPControlPopup I get error
Posted By: sdancer75
Subject: Getting CMenu from CXTPControlPopup I get error
Date Posted: 23 September 2014 at 8:31am
Hi,

I want to change (insert or delete item) the popup menu of a CXTPControlPopup dynamically. I use the following code below, but everytime I am trying to get access to the popup menu I assertion error. Any Ideas ?

m_pPopupHistory = (CXTPControlPopup*)pGroup0->Add(xtpControlButtonPopup, ID_POPUP_HISTORY); 
pPopupBar = CXTPPopupBar::CreatePopupBar(GetCommandBars());
m_pPopupHistory->SetCommandBar(pPopupBar);
m_PopupHistoryMenu.LoadMenu(IDR_MENU_HISTORY);
pPopupBar->LoadMenu(m_PopupHistoryMenu.GetSubMenu(0));
pPopupBar->InternalRelease();

........................................................... 
//somewhere in my code
CXTPPopupBar *pChildBar = (CXTPPopupBar*)m_pPopupHistory->GetCommandBar();
CMenu *mm = pChildBar->GetMenu();  // <-- At this point I get assertion error
mm->AppendMenu(MF_STRING, 1, "Text 1");
pChildBar->InternalRelease();


-------------
Just me!



Replies:
Posted By: olebed
Date Posted: 23 September 2014 at 12:49pm
Hi,

Can you please provide a small sample application so that we could debug this issue? 

Make sure that pChildBar is not NULL and also really belongs to CXTPPopupBar class.

Thank you.
Regards,
   Oleksandr Lebed


Posted By: sdancer75
Date Posted: 24 September 2014 at 3:49am
Thanks for the reply.

I can verify that pChildBar is not null. I attach the original sample "Ribbon Controls" where I added my offended custom code at line number 524 inside the MainFrm.cpp.

Thanks


uploads/4319/RibbonControls.zip" rel="nofollow - uploads/4319/RibbonControls.zip


-------------
Just me!


Posted By: olebed
Date Posted: 24 September 2014 at 5:35am
CXTPPopupBar *pChildBar = (CXTPPopupBar*)pCustomPopup->GetCommandBar(); 
CMenu *mm = pChildBar->GetMenu(); // <-- At this point I get assertion error

but pChildBar->m_hWnd is NULL that is why assertion fired
CMenu* CWnd::GetMenu() const
{
ASSERT(::IsWindow(m_hWnd));
return CMenu::FromHandle(::GetMenu(m_hWnd));
}

pPopupBar->LoadMenu(mmenu.GetSubMenu(0)) converts menu items to command bar controls. That is why you can't get CMenu which was loaded.
But you can use
pChildBar->GetControls()->Add();
pChildBar->GetControls()->InsertAt();
pChildBar->GetControls()->AddMenuItem();
pChildBar->GetControls()->AddClone();

pChildBar->GetControls()->MoveBefore();

Fro example:
CXTPPopupBar *pChildBar = (CXTPPopupBar*)pCustomPopup->GetCommandBar(); 
CXTPControl* pMenuItem = pChildBar->GetControls()->Add(xtpControlButton, ID_DYNAMIC_POPUP2 + 1);
pMenuItem->SetCaption(_T("Text 1"));



Posted By: sdancer75
Date Posted: 24 September 2014 at 6:01am
Originally posted by olebed olebed wrote:

CXTPPopupBar *pChildBar = (CXTPPopupBar*)pCustomPopup->GetCommandBar(); 
CMenu *mm = pChildBar->GetMenu(); // <-- At this point I get assertion error

but pChildBar->m_hWnd is NULL that is why assertion fired
CMenu* CWnd::GetMenu() const
{
ASSERT(::IsWindow(m_hWnd));
return CMenu::FromHandle(::GetMenu(m_hWnd));
}

pPopupBar->LoadMenu(mmenu.GetSubMenu(0)) converts menu items to command bar controls. That is why you can't get CMenu which was loaded.
But you can use
pChildBar->GetControls()->Add();
pChildBar->GetControls()->InsertAt();
pChildBar->GetControls()->AddMenuItem();
pChildBar->GetControls()->AddClone();

pChildBar->GetControls()->MoveBefore();

Fro example:
CXTPPopupBar *pChildBar = (CXTPPopupBar*)pCustomPopup->GetCommandBar(); 
CXTPControl* pMenuItem = pChildBar->GetControls()->Add(xtpControlButton, ID_DYNAMIC_POPUP2 + 1);
pMenuItem->SetCaption(_T("Text 1"));


Hi,

Thank you for your quick response. I was suspicious with the LoadMenu() thing.

In fact, I thought that the pPopupBar->LoadMenu(xxx) may have suppressed the CMenu structure in some way since the way you showed me to solve the problem, was already tested and verified that it works just fine.....

I should check the source code before I ask... but you help was precious and saved my time !

Best Regards,


-------------
Just me!



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