Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - Want to create all menus dynamically
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Want to create all menus dynamically

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

Joined: 10 March 2006
Location: United States
Status: Offline
Points: 14
Post Options Post Options   Thanks (0) Thanks(0)   Quote deepghosh Quote  Post ReplyReply Direct Link To This Post Topic: Want to create all menus dynamically
    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!!

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: 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
Back to Top
deepghosh View Drop Down
Groupie
Groupie
Avatar

Joined: 10 March 2006
Location: United States
Status: Offline
Points: 14
Post Options Post Options   Thanks (0) Thanks(0)   Quote deepghosh Quote  Post ReplyReply Direct Link To This Post 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);
}

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: 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
Back to Top
deepghosh View Drop Down
Groupie
Groupie
Avatar

Joined: 10 March 2006
Location: United States
Status: Offline
Points: 14
Post Options Post Options   Thanks (0) Thanks(0)   Quote deepghosh Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
deepghosh View Drop Down
Groupie
Groupie
Avatar

Joined: 10 March 2006
Location: United States
Status: Offline
Points: 14
Post Options Post Options   Thanks (0) Thanks(0)   Quote deepghosh Quote  Post ReplyReply Direct Link To This Post Posted: 12 March 2006 at 10:11pm

Also I wanted to add this.

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

Back to Top
deepghosh View Drop Down
Groupie
Groupie
Avatar

Joined: 10 March 2006
Location: United States
Status: Offline
Points: 14
Post Options Post Options   Thanks (0) Thanks(0)   Quote deepghosh Quote  Post ReplyReply Direct Link To This Post 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);
}

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: 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
Back to Top
deepghosh View Drop Down
Groupie
Groupie
Avatar

Joined: 10 March 2006
Location: United States
Status: Offline
Points: 14
Post Options Post Options   Thanks (0) Thanks(0)   Quote deepghosh Quote  Post ReplyReply Direct Link To This Post Posted: 14 March 2006 at 5:01pm

Oleg

You are great. (Its fixed)

I think we all appreciate your persistent help.

Deep

Back to Top
bambha View Drop Down
Newbie
Newbie


Joined: 19 June 2006
Location: United States
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote bambha Quote  Post ReplyReply Direct Link To This Post 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
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 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
Back to Top
bambha View Drop Down
Newbie
Newbie


Joined: 19 June 2006
Location: United States
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote bambha Quote  Post ReplyReply Direct Link To This Post 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
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: 21 July 2006 at 2:51pm

Hi,

See Notifications sample.
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
bambha View Drop Down
Newbie
Newbie


Joined: 19 June 2006
Location: United States
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote bambha Quote  Post ReplyReply Direct Link To This Post 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
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: 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
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.186 seconds.