Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » CExtMenuControlBar question Collapse All
Subject Author Date
tera tera Oct 21, 2010 - 2:26 AM

Hello.


I want to add a menu dynamically.

Even if, after LoadFrame, I add a menu

It is not displayed.

Please teach a method to add dynamically.


    CMainFrame* pFrame = new CMainFrame;  m_pMainWnd = pFrame;  if( ! pFrame->LoadFrame(    IDR_MAINFRAME, //   IDR_NXBKTYPE,    WS_OVERLAPPEDWINDOW|FWS_ADDTOTITLE,    NULL,    NULL    )   )   return FALSE;  // window placement persistence : : :

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) {  if( CExtNCW < CFrameWnd > :: OnCreate( lpCreateStruct ) == -1 )   return -1;

 // メニューバーの作成  if( ! m_wndMenuBar.Create(    NULL,    this,    ID_VIEW_MENUBAR    )   )  {   TRACE0("Failed to create menubar\n");   return -1;  }

    m_wndMenuBar.InitMenuMCB();

: : :

void CNxbkMenuControlBar::InitMenuMCB() {

 CMenu popupMenu;  BOOL bCreate;

 bCreate = popupMenu.CreatePopupMenu ();

 // メインメニュー  bCreate = popupMenu.AppendMenu ( MF_STRING, 123 , "aaa" );  bCreate = popupMenu.AppendMenu ( MFT_SEPARATOR  );  bCreate = popupMenu.AppendMenu ( MF_STRING, 444 , "bbbb" );  bCreate = popupMenu.AppendMenu ( MFT_SEPARATOR  );

 CMenu* pMenu = GetMenu();  bCreate = pMenu->AppendMenu ( MF_POPUP, ( UINT ) popupMenu.Detach() , "AddMenu" );

}

 

Technical Support Oct 23, 2010 - 9:50 AM

Thank you for the test project. The approach you are using in your app works only in the SDI environment. The MDI environment changes menus on-the-fly. Your code is almost OK. You only forgot to re-build menu bar buttons from the changed menu:

void CNxbkMenuControlBar::InitMenuMCB()
{
CMenu popupMenu;
            BOOL bCreate;
            bCreate = popupMenu.CreatePopupMenu ();
            bCreate = popupMenu.AppendMenu ( MF_STRING, 123 , "aaa" );
            bCreate = popupMenu.AppendMenu ( MFT_SEPARATOR  );
            bCreate = popupMenu.AppendMenu ( MF_STRING, 444 , "bbbb" );
            bCreate = popupMenu.AppendMenu ( MFT_SEPARATOR  );
CMenu* pMenu = GetMenu();
            bCreate = pMenu->AppendMenu ( MF_POPUP, ( UINT ) popupMenu.Detach() , "_POPUP_" );
            UpdateMenuBar( FALSE ); // THIS LINE IS IMPORTANT
}

Technical Support Oct 21, 2010 - 9:48 AM

Could you send the complete source code for CMainFrame and CNxbkMenuControlBar classes to the support mail box at this web site?

tera tera Oct 21, 2010 - 11:12 PM