Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - Getting CMenu from CXTPControlPopup  I get error
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Getting CMenu from CXTPControlPopup I get error

 Post Reply Post Reply
Author
Message
sdancer75 View Drop Down
Groupie
Groupie
Avatar

Joined: 08 July 2008
Location: Greece
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote sdancer75 Quote  Post ReplyReply Direct Link To This Post Topic: Getting CMenu from CXTPControlPopup I get error
    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!
Back to Top
olebed View Drop Down
Admin Group
Admin Group


Joined: 01 July 2014
Location: Ukraine
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote olebed Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
sdancer75 View Drop Down
Groupie
Groupie
Avatar

Joined: 08 July 2008
Location: Greece
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote sdancer75 Quote  Post ReplyReply Direct Link To This Post 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


Just me!
Back to Top
olebed View Drop Down
Admin Group
Admin Group


Joined: 01 July 2014
Location: Ukraine
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote olebed Quote  Post ReplyReply Direct Link To This Post 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"));

Back to Top
sdancer75 View Drop Down
Groupie
Groupie
Avatar

Joined: 08 July 2008
Location: Greece
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote sdancer75 Quote  Post ReplyReply Direct Link To This Post 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!
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.125 seconds.