Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - How to get Submenu?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

How to get Submenu?

 Post Reply Post Reply
Author
Message
kent_t View Drop Down
Groupie
Groupie


Joined: 15 July 2008
Status: Offline
Points: 13
Post Options Post Options   Thanks (0) Thanks(0)   Quote kent_t Quote  Post ReplyReply Direct Link To This Post Topic: How to get Submenu?
    Posted: 06 November 2008 at 5:55pm
CJ Version: 12.0.0, MSVC++ 2005, MFC

I want to * programmatically * change a Submenu from within a standard MFC MAIN menu with a check mark. There should be a CheckMenuItem(...) call somewhere, right?

I've looked through all the CommandBar samples. No joy. (Maybe I missed something.)

I have this in CMainFrame::OnCreate(...);
...

    CXTPCommandBars* pCommandBars = GetCommandBars();
    mpMainMenuBar = pCommandBars->SetMenu(_T("Menu Bar"), IDR_MAINFRAME);
    mpMainMenuBar->SetFlags(xtpFlagAddMDISysPopup);


I can call mpMainMenuBar from other class's and it provides me the same behavior as below.

In another class I call:

        CMainFrame* pMF = (CMainFrame*)AfxGetMainWnd();
        CXTPCommandBars* pCB = pMF->GetCommandBars();
        CXTPMenuBar* pMB = pCB->GetMenuBar();

        // id is always "1", wrong id
        int id = pMB->GetBarID();

       // none of the returned pointers are usefull
       CXTPControl* pc = pCB->FindControl( xtpControlPopup, ID_VIEW_PROPON, TRUE, FALSE );
      CXTPMenuBarMDIMenus* pmdi = pMB->GetMDIMenus();
      CXTPMenuBarMDIMenuInfo* pinfo = pmdi->Lookup( ID_VIEW_PROPON );
      // GetMenu always returns NULL
      CMenu* pcm = pMB->GetMenu();


Sadness.

This is how you would do it in normal MFC. From MS example.

CMenu* menu_bar = AfxGetMainWnd()->GetMenu();
CMenu* file_menu = menu_bar->GetSubMenu(0);


Any help to achieve this would be appreciated.

Thank you.
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: 07 November 2008 at 5:12am
Hi,
try
 
CXTPMenuBar* pMB = pCB->GetMenuBar();
pMB->GetControl(0)->GetCommandBar();
 
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
kent_t View Drop Down
Groupie
Groupie


Joined: 15 July 2008
Status: Offline
Points: 13
Post Options Post Options   Thanks (0) Thanks(0)   Quote kent_t Quote  Post ReplyReply Direct Link To This Post Posted: 10 November 2008 at 2:56pm
I now have the code below. The cnt return value reflects the correct number of items in the associated menus. I believe I have the correct menu "controls." They are MenuItems, aren't they. The id's obtained from the CXTPControl.GetID() calls are correct. The controls have the resource.h ID's that they should.

Note: mpMainMenuBar is set in the OnCreate function above.

The SetCheck call does NOTHING. Zero. I am losing faith rapidly.

   
    CMainFrame* pMF = (CMainFrame*)AfxGetMainWnd();

    CXTPCommandBar* pBar = pMF->mpMainMenuBar->GetControl(2)->GetCommandBar();
    int cnt = pBar->GetControlCount();
    CXTPCommandBar* pSMenu = pBar->GetControl(4)->GetCommandBar();
    cnt = pSMenu->GetControlCount();

    CXTPControl* p0 = pSMenu->GetControl(0);
    p0->SetChecked( FALSE );
    int id0 = p0->GetID();

    CXTPControl* p1 = pSMenu->GetControl(1);
    p1->SetChecked( TRUE );
    int id1 = p1->GetID();

Please Advise.

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: 07 January 2009 at 1:33pm
Hello,
 
Guess you check wrong controls.
 
I very recommend use standard MFC Update handlers - as advantage you don't need afraid that your user remove/move/delete or copy this control in Customization dialog.
 
Add
 
ON_UPDATE_COMMAND_UI(ID_P0_ID, OnUpdateP0)
 
and
void CMainFrame::OnUpdateP0(CCmdUI* pCmdUI)
{
 pCmdUI->SetCheck(m_bP0IsChecked);
}
 
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.172 seconds.