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 General Discussion » How to delete all the Menu Collapse All
Subject Author Date
ven rag Dec 29, 2005 - 4:21 AM

I want to delete all the Menus in the Menu Bar.


for eg I have Menu IDR_MDIDOCTYPE,Which is loaded in the MDI frame when I Open a new document .I want to delete all the Menu ie from root menu to the submenu in IDR_MDIDOCTYPE .


and then


I want to insert my own menu in the IDR_MDIDOCTYPE.I should able to insert root,submenu and POPUP menu in the submenu.


for eg


///////////////////////////////////////////


FILE(root)


New(submenu under root FILE)


Open(submenu under root FILE)


Shape(submenu under root FILE)------->Circle(submenu under Shape)


EXIT                                                    Square(submenu under Shape)


                                                           Rect(submenu under Shape)


//////////////////////////////////////////////


How do it ....


Thank u

Technical Support Dec 30, 2005 - 8:03 AM

The solution is also based on overriding the _UpdateMenuBar() virtual method in the CExtMenuControlBar-derived class, which we described in our previous answers to your questions.

ven rag Dec 31, 2005 - 2:30 AM

I have overrided  _UpdateMenuBar() virtual method in the CExtMenuControlBar-derived class.


I mentioned the line of the error in  the  red font.


I am getting an Assertion error. I think due to this Assertion error I could not load the new menu bar.


please sample code for inserting the my menu in the new menu bar.


BOOL CMyMenuBar::_UpdateMenuBar( BOOL bDoRecalcLayout // = TRUE
      )
{
    SetButtons(); // remove all buttons
  // remove all previously allocated command identifiers 
  // for menu buttons
    VERIFY(
     g_CmdManager->CmdRemoveByMask(
       g_CmdManager->ProfileNameFromWnd( GetSafeHwnd() ),
       (DWORD)CExtCmdItem::STATE_MENUBAR_TMP ));
-->"Iam getting the Assertion Error in the line".


   CMenu * pMenu = _GetMenu();
   if( pMenu->GetSafeHmenu() != NULL )
   {
     bool bRevertRTL = OnQueryRevertRTL();
     UINT nMenuItemCount = pMenu->GetMenuItemCount();
     for( UINT nMenuItemIndex = 0; nMenuItemIndex < nMenuItemCount; nMenuItemIndex++ )
    {
   UINT nInsertButtonLocation =
      bRevertRTL
      ? 0
      : nMenuItemIndex
      ;
      MENUITEMINFO mii;
      ::memset( &mii, 0, sizeof(MENUITEMINFO) );
      mii.cbSize = sizeof(MENUITEMINFO);
      mii.fMask =
             MIIM_CHECKMARKS
             |MIIM_DATA
             |MIIM_ID
             |MIIM_STATE
             |MIIM_SUBMENU
             |MIIM_TYPE
             ; 
             mii.cch = __MAX_UI_ITEM_TEXT;
             CExtSafeString sText;
             mii.dwTypeData =
                        sText.GetBuffer( __MAX_UI_ITEM_TEXT );
             ASSERT( mii.dwTypeData != NULL );
             if( mii.dwTypeData == NULL )
             {
                ASSERT( FALSE );
                return FALSE;  
             } 


      if( ! pMenu->GetMenuItemInfo(
         nMenuItemIndex,
                       &mii,
                       TRUE  
        )
                     )
             {
                 sText.ReleaseBuffer();
                 ASSERT( FALSE );
                 return false;
             }
              sText.ReleaseBuffer();
              BOOL bAppendMdiWindowsMenu = FALSE;
              UINT nCmdID = 0;
              CExtCmdItem * pCmdItem = NULL;
              if( mii.hSubMenu == NULL )
             {
                 nCmdID = mii.wID;
                 if( nCmdID == ID_SEPARATOR )
                  {  
                    if( ! InsertButton(
                               nInsertButtonLocation,
                               nCmdID,
                               FALSE 
                               )
                             )
                          {
    ASSERT( FALSE );
                                return FALSE; 
      } 
   continue;
                   } // if( nCmdID == ID_SEPARATOR )  
                   ASSERT( CExtCmdManager::IsCommand(nCmdID) );  
                  pCmdItem =
                  g_CmdManager->CmdGetPtr(
                  g_CmdManager->ProfileNameFromWnd( GetSafeHwnd() ),
                  nCmdID
     );
                  ASSERT( pCmdItem != NULL );
                 } // if( mii.hSubMenu == NULL )
                 else
                  {    
                       pCmdItem =     
                       g_CmdManager->CmdAllocPtr(
                       g_CmdManager->ProfileNameFromWnd( GetSafeHwnd() )
                        );
                        if( pCmdItem == NULL )
                        {
                          ASSERT( FALSE );
                          return FALSE;
                        }// if( pCmdItem == NULL )
                          nCmdID = pCmdItem->m_nCmdID;
                          ASSERT( CExtCmdManager::IsCommand(nCmdID) );
                          pCmdItem->StateSetMenubarTemp(); 
                          pCmdItem->StateSetBasic();
                          if( _IsMdiApp() && (! m_sMdiWindowPopupName.IsEmpty() ) )
                          {
                             CExtSafeString _sText(sText);
                             _sText.TrimLeft(); 
                             _sText.TrimRight();
                             while( _sText.Replace(_T("&"),_T("")) > 0 )
                             {
                                 _sText.TrimLeft(); 
                                 _sText.TrimRight();
                             }// while( _sText.Replace(_T("&"),_T("")) > 0 )
                            if( _sText == m_sMdiWindowPopupName )
                             bAppendMdiWindowsMenu = TRUE;
                        } // if( _IsMdiApp() && (! m_sMdiWindowPopupName.IsEmpty() ) )
                     } // else from if( mii.hSubMenu == NULL )
                   ASSERT( pCmdItem != NULL );
                   if( pCmdItem->m_sToolbarText.IsEmpty() )
                       pCmdItem->m_sToolbarText = sText;  
                    if( pCmdItem->m_sMenuText.IsEmpty() )     
                     pCmdItem->m_sMenuText = sText;
                     if( ! InsertButton(
                        nInsertButtonLocation,
                        nCmdID,
                        FALSE
                        )
                      ) 
                 {
                    ASSERT( FALSE );
                    return FALSE;
                 }
                   if( mii.hSubMenu != NULL )
                   {
                        ASSERT( ::IsMenu(mii.hSubMenu) );
                        SetButtonMenu(
                        nInsertButtonLocation,
                        mii.hSubMenu,
                        FALSE,
                        FALSE,
                        FALSE
                    );
                   } // if( mii.hSubMenu != NULL )
                 if( bAppendMdiWindowsMenu )
                {
                   VERIFY(
                       MarkButtonAsMdiWindowsMenu(
                        nInsertButtonLocation,
                       TRUE
                       )
                       );
                 } // if( bAppendMdiWindowsMenu )
       } // for( UINT nMenuItemIndex = 0; nMenuItemIndex < nMenuItemCount; nMenuItemIndex++ )
        ASSERT( m_pRightBtn == NULL );
        m_pRightBtn = OnCreateBarRightBtn();
        if( m_pRightBtn != NULL )
        {         
          ASSERT_VALID( m_pRightBtn );
          ASSERT_KINDOF( CExtBarContentExpandButton, m_pRightBtn );
          m_buttons.Add( m_pRightBtn );
        }// if( m_pRightBtn != NULL )
     } // if( pMenu->GetSafeHmenu() != NULL )


/////////////////////////////////////////////////////
//
// TO DO:
// insert custom menu bar’s buttons here
//
/////////////////////////////////////////////////////
if( _IsMdiApp() )
{
  if( !IsOleIpObjActive() )
    if( _InstallMdiDocButtons( FALSE ) )
            bDoRecalcLayout = TRUE;
    VERIFY( _SyncActiveMdiChild() );
}


if( bDoRecalcLayout )
{
 Invalidate();
 _RecalcLayoutImpl();
 UpdateWindow();


 


///////////////////"I want to know what the below code does"///////////////
if( m_pDockSite != NULL )
{
   //CFrameWnd * pFrame = GetParentFrame();
   //ASSERT_VALID( pFrame );
   //if( pFrame->IsKindOf(RUNTIME_CLASS(CExtMiniDockFrameWnd)) )
  // pFrame->SetWindowPos(
   //NULL, 0, 0, 0, 0,
  // SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE
  // |SWP_NOZORDER|SWP_NOOWNERZORDER
  // |SWP_FRAMECHANGED
  // );
 } // if( m_pDockSite != NULL )
 } // if( bDoRecalcLayout )
  return TRUE;
}


 

Technical Support Dec 31, 2005 - 8:43 AM

The CExtCmdManager::CmdRemoveByMask() returns false and causes an assertion message in the debug version of the VERIFY() macro because you forgot to initialize the command profile during your application startup. The CMainFrame::OnCreate() method in your project should invoke the g_CmdManager->ProfileSetup( . . . ) or g_CmdManager->ProfileWndAdd( . . . ) code like in any of our sample applications. Please fix this. Just take a look at the CMainFrame::OnCreate() method of one of our simplest applications like SDI, MDI, SDIDOCVIEW or MDIDOCVIEW for details.

The source code at the end of the _UpdateMenuBar() method that you also marked with red is needed to update the size of the menu bar’s floating mini frame window window according to the re-created menu bar’s buttons. This code is invoked only when the menu bar is floating. So, please do not comment it.


ven rag Jan 2, 2006 - 10:55 PM

As u have told I have already intialized in OnCreate function of CMainFrame()


/////////////////////////////////////////////////////


int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
   CWinApp * pApp = ::AfxGetApp();
 ASSERT( pApp != NULL );
 ASSERT( pApp->m_pszRegistryKey != NULL );
 ASSERT( pApp->m_pszRegistryKey[0] != _T(’\0’) );
 ASSERT( pApp->m_pszProfileName != NULL );
 ASSERT( pApp->m_pszProfileName[0] != _T(’\0’) );
 if( CMDIFrameWnd::OnCreate(lpCreateStruct) == -1 )
 {
  ASSERT( FALSE );
  return -1;
 }
 VERIFY(
  g_CmdManager->ProfileWndAdd(
   pApp->m_pszProfileName,
   GetSafeHwnd()
   )
  );
///////////////////////////////////////////////////////////////////////


When I debugged the function _UpdateMenuBar().


Note:Iam calling the _UpdateMenuBar in the OnCreate() function of the child frame.


<--- indicates debugger


/////////////////////////////////////
      BOOL CMyMenuBar::_UpdateMenuBar( BOOL bDoRecalcLayout // = TRUE
      )
{
    SetButtons(); // remove all buttons
  // remove all previously allocated command identifiers 
  // for menu buttons
    VERIFY(
     g_CmdManager->CmdRemoveByMask(
       g_CmdManager->ProfileNameFromWnd( GetSafeHwnd() ),<---
       (DWORD)CExtCmdItem::STATE_MENUBAR_TMP ));


----->from GetSafeHwnd() the code jumps to the below function on debugging.


_AFXWIN_INLINE HWND CWnd::GetSafeHwnd() const
 { return this == NULL ? NULL : m_hWnd; }-->here the function is returning the NULL value instead of m_hWnd


I am getting the hWnd=0x00000000(NULL).I think due to the empty handle only iam getting this error.


----->from CExtCmdItem::STATE_MENUBAR_TMP the function jumps to


__EXT_MFC_SAFE_LPCTSTR CExtCmdManager::ProfileNameFromWnd(
 HWND hWnd
 )
{
 ASSERT( hWnd != NULL );
<---- from here the debugging jumps to AfxAssertFailedLine() function.


So Iam getting the error in the PeekMessage of the AfxAssertFailedLine() function.


What i should do to get the handle .


BOOL AFXAPI AfxAssertFailedLine(LPCSTR lpszFileName, int nLine)
{
#ifndef _AFX_NO_DEBUG_CRT
 // we remove WM_QUIT because if it is in the queue then the message box
 // won’t display


 MSG msg;
 BOOL bQuit = PeekMessage(&msg, NULL, WM_QUIT, WM_QUIT, PM_REMOVE);//I have got the error in this line.
 BOOL bResult = _CrtDbgReport(_CRT_ASSERT, lpszFileName, nLine, NULL, NULL);
 if (bQuit)
  PostQuitMessage(msg.wParam);
 return bResult;


How to solve this problem?

Technical Support Jan 3, 2006 - 4:55 AM

If the CWnd::GetSafeHwnd() method returns NULL instead of a valid HWND handle, then the window is not created yet, nor subclassed or it is already destroyed. We guess you forgot to invoke the CExtMenuControlBar::Create() method for your menu bar window. The CMainFrame::OnCreate() method is responsible for the menu bar creation and should contain the code lines like below next to the place where toolbars are created:

    if( ! m_wndMenuBar.Create(
            NULL, // _T("Menu Bar"),
            this,
            ID_VIEW_MENUBAR
            )
        )
    {
        TRACE0("Failed to create menubar\n");
        return -1;
    }



ven rag Jan 3, 2006 - 6:48 AM

For eg: "MDI_DynamicBars" program  in the ProfUIS Samples programs.When no document is open the program loads "IDR_MAINFRAME"  Menu from the resource.But if a new document is opened then the program loads "IDR_MDIDOCTYPE" Menu from the resource.What I won’t to do is that When I open a new document, my Dynamic Bar should Loaded (ie) When I open a New document "IDR_MDIDOCTYPE" should not be loaded.To solve this what I did was I called the overridden _UpdateMenuBar() function from the CChildFrame OnCreate() function like this


int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
 if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
  return -1;


 CMyMenuBar mymenu;
 mymenu._UpdateMenuBar(); 
 // TODO: Add your specialize  creation code here
 return 0;
}
When I call the _UpdaMenuBar() function ,As I told before I could not get the CWnd::GetSafeHwnd() method returns NULL instead of a valid HWND handle.As u have told me that I have not called then CExtMenuControlBar::Create() function.That true.But I don’t know where to call this function.can u use the same sample program that i have used (ie)"MDI_DynamicBars" program from PROFUIS Sample programs AND add the Dynamic Menu when i open the new Document .That is When I press ctrl+N the New Dynamic Menu Bar and The Dynamic Menus should be added .


Thank u .


 


 


 


 


 

Technical Support Jan 4, 2006 - 11:41 AM

You can use only one menu line in your MDI application. You should not even code complex things like you try to do. Just remove the IDR_MDIDOCTTYPE menu from your project and replace IDR_MDIDOCTTYPE with IDR_MAINFRAME in the source code.

ven rag Jan 5, 2006 - 6:21 AM

But I have did this correctly in mfc.I think two ways we can load the Menu.1.U can add the Dynamic MenuBar and Menu instead of IDR_MDIDOCTTYPE from the resource 2.We can remove items in  IDR_MDIDOCTTYPE at runtime and insert our Dynamic poup menu in the IDR_MDIDOCTTYPE MenuBar.


"Please give me the Sample for creating a Dynamic Menu and Inserting a Dynamic Menu in IDR_MDIDOCTTYPE  at runtime in ProfUIS with MFC "


Thank u.

Technical Support Jan 5, 2006 - 10:58 AM

Let us put this in a different way to help you more efficiently. Please create a new project and add all the important UI parts you need in your real application. After that, please send this project to us and let us know what’s wrong.