Print Page | Close Window

Want to create all menus dynamically

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=3756
Printed Date: 12 May 2024 at 12:59pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Want to create all menus dynamically
Posted By: deepghosh
Subject: Want to create all menus dynamically
Date Posted: 10 March 2006 at 9:48am

I want to add a new menu element dynamically and add submenus to it.

I cannot use a resource. I am populating from a set of proprietary objects.

So..the approach I am taking (maybe wrong - trying to learn from dynamicpopup sample - which is not really my case).

Create a CXTPControlPopup derived and add it to command bar. (This part works).

Now I am confused...Which ones I have to override..CalcDynamicSize,OnSetPopup or what?

I can make my menu popup piece show up. But I cannot add children to it. This is simply because of lack of knowledge. I wish Dynamic Popup sample did not have the Undo bit on the main one already created then I could have just followed that example.

HELP!!




Replies:
Posted By: Oleg
Date Posted: 10 March 2006 at 10:11am

 

Just add new controls in this popup's commandbar:

pPopup->GetCommandBar()->GetControls()->Add(...);



-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: deepghosh
Date Posted: 10 March 2006 at 12:16pm

void CiListOfPopupMenus::AddMenu(CiMainFrame*pMain, CiPopupMenu* pIPopupMenu,LPCTSTR szTitle)
{
    CXTPMenuBar*pMenuBar = pMain->GetMenuBar();
    if (!pMenuBar)
 return;
    CXTPControls *pList = pMenuBar->GetControls();
    CXTPControl* pControlPopup = new CXTPControlPopup();
    CXTPControl* pControl = new CXTPControlButton();
    pList->Add(pControlPopup, 3, NULL,pList->GetCount()-1, TRUE);

    -- UPTO THIS ALL OK

    CXTPCommandBar *pBar = pControlPopup->GetCommandBar();

    BUT NOW I GET pBar AS NULL...WHY?
    pBar->GetControls()->Add(pControl, 3, NULL,-1, TRUE);
    //pControlPopup->GetCommandBar()->GetControls()->Ad d(pControl, 3, NULL,-1, TRUE);
    pControl->SetCaption("DSD");
    pControlPopup->SetCaption(szTitle);
    pControlPopup->SetFlags(xtpFlagManualUpdate);
    Push(pIPopupMenu);
}



Posted By: Oleg
Date Posted: 11 March 2006 at 12:47pm

Hello,

right... sorry.. by default it is NULL, just add

CXTPControlPopup* pControlPopup = new CXTPControlPopup();

pControlPopup->SetCommandBar(CXTPPopupBar::CreatePopupBar (pCommandBars);

or you can automatically convrert CMenu to CommandBar

CMenu* pMenu = ...

pControlPopup->SetCommandBar(pMenu);



-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: deepghosh
Date Posted: 12 March 2006 at 10:10pm

Sorry Still does not work.

    CXTPMenuBar*pMenuBar = pMain->GetMenuBar();
    if (!pMenuBar)
 return;
    CXTPControls *pList = pMenuBar->GetControls();
    CXTPControlPopup* pControlPopup = new CXTPControlPopup();
    pList->Add(pControlPopup, 3, NULL,pList->GetCount()-1, TRUE);
    pControlPopup->SetCommandBar(CXTPPopupBar::CreatePopupBar (pMain->GetCommandBars()));
    pControlPopup->SetCaption(szTitle);

    CXTPControl* pControl = new CXTPControlButton();
    CXTPPopupBar *pBar = (CXTPPopupBar*) pControlPopup->GetCommandBar();
    pBar->GetControls()->Add(pControl, 99, NULL,-1, TRUE);
    pControl->SetCaption("TEST");

I did not know what you meant by pCommandBars (Understood it needs that type of object, so I replaced by pMain->GetCommandBars()) ..Maybe thats the problem?

What I get is a disabled popup menu added with NO CHILDREN.

However I appreciate all your help. I think we possibly need a sample app for which all the menus (or at least one menu) is constructed dynamically.

I think I can usea CMenu object but do not intend to do so.



Posted By: deepghosh
Date Posted: 12 March 2006 at 10:11pm

Also I wanted to add this.

CXTPPopupBar was created with hWnd 0 , what means creation failed?



Posted By: deepghosh
Date Posted: 13 March 2006 at 12:42am

Also Tried This..Still it is disabled (Enabled Items here)

void CiListOfPopupMenus::AddMenu(CiMainFrame*pMain, CiPopupMenu* pIPopupMenu,LPCTSTR szTitle)
{
    CXTPMenuBar*pMenuBar = pMain->GetMenuBar();
    if (!pMenuBar)
 return;
    CXTPControls *pList = pMenuBar->GetControls();
    //popup creation
    CXTPPopupBar *pBar = (CXTPPopupBar*) CXTPPopupBar::CreatePopupBar (pMain->GetCommandBars());
    CXTPControlPopup * pControlPopup = CXTPControlPopup::CreateControlPopup(xtpControlPopup);
    pControlPopup->SetCommandBar(pBar);
    pControlPopup->SetCaption(szTitle);
    pList->Add(pControlPopup, 3, NULL,pList->GetCount()-1, TRUE);

 

    CXTPControl* pControl = new CXTPControlButton();
    pBar->GetControls()->Add(pControl, 99, NULL,-1, TRUE);
    pControl->SetCaption("TEST");
    pControl->SetEnabled(TRUE);
    pControlPopup->SetEnabled(TRUE);
    Push(pIPopupMenu);
}



Posted By: Oleg
Date Posted: 13 March 2006 at 5:53pm

You add pControlPopup with Id = 3 it means that you must use Update Handle to enable/disable it.

Just use (-1) if you want to enable it.



-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: deepghosh
Date Posted: 14 March 2006 at 5:01pm

Oleg

You are great. (Its fixed)

I think we all appreciate your persistent help.

Deep



Posted By: bambha
Date Posted: 19 July 2006 at 7:38pm
How can disable a menu item? I have File->New, File->Exit. How can disable Exit if my menu is created using
CXTPCommandBars* pCommandBars = GetCommandBars();
pCommandBars->SetMenu(_T("Menu Bar"), IDR_MENU);


-------------
Manik Bambha


Posted By: Oleg
Date Posted: 20 July 2006 at 8:51am
Hello,
Add update handlers. See how ON_UPDATE_COMMAND_UI work in any sample.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: bambha
Date Posted: 21 July 2006 at 12:05pm
Thanks Oleg. I am able to change the text and disable it. Do you know how to delete?

-------------
Manik Bambha


Posted By: Oleg
Date Posted: 21 July 2006 at 2:51pm

Hi,

See Notifications sample.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: bambha
Date Posted: 21 July 2006 at 4:08pm
Thanks Oleg. Its working for me now.
For people here is the code

CXTPCommandBar* pToolBar = (CXTPToolBar*)pCmdUI->m_pOther;

if (pToolBar)

{

CXTPControl* pControl = pToolBar->GetControls()->GetAt(pCmdUI->m_nIndex);

pControl->SetVisible(0);

pToolBar->DelayLayout();

}



-------------
Manik Bambha


Posted By: Oleg
Date Posted: 21 July 2006 at 5:05pm
Hi,
I'd replace it to:
 
CXTPControl* pControl = CXTPControl::FromUI(pCmdUI);
if (pControl)
{
     pControl->SetVisible(FALSE);
}
 
 
 
 
(SetVisible already have DelayLayout _if state is really changed_)
 


-------------
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