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 » Problem with repainting caption of floating MenuBar Collapse All
Subject Author Date
Suhai Gyorgy Mar 21, 2007 - 8:41 AM

Dear Support,

In our application we have to dynamically change text of MenuBar, so we have a CExtMenuControlBar-derived class, which has the following _UpdateMenuBar method (simplified):

	virtual BOOL _UpdateMenuBar(BOOL bDoRecalcLayout = TRUE)
	{
		BOOL bRet = CExtMenuControlBar::_UpdateMenuBar(bDoRecalcLayout);
		for( int nPos = 0; nPos < GetButtonsCount(); nPos++ ) {
			UINT nCmdId = GetButton(nPos)->GetCmdID();
			CExtCmdItem *pCmdItem =
					g_CmdManager->CmdGetPtr(
						g_CmdManager->ProfileNameFromWnd(GetSafeHwnd()),
						nCmdId
						);
			ASSERT( pCmdItem != NULL );
			pCmdItem->m_sToolbarText = _T("My") + pCmdItem->m_sMenuText;
		}
		if( bDoRecalcLayout )
		{
			Invalidate();
			_RecalcLayoutImpl();
			UpdateWindow();
		}
		return bRet;
	}
The problem happens in an MDI application, which has one menubar for the mainframe and one for the doctype. We place the menubar in a floating position. When initially there is no document open, user can see the mainframe’s menu. When we open a document, the floating menu turns into the menu of the document-type (in the meanwhile, _UpdateMenuBar is called). The problem is, that the caption of the menubar is painted only to the length of the original menubar, but since the texts of the buttons got longer than it would have been originally, the remaining part of the caption is white. Picture

Technical Support Mar 21, 2007 - 11:20 AM

The following version of _UpdateMenuBar() method fixes the problem:

      class CMyMB : public CExtMenuControlBar
      {
            virtual BOOL _UpdateMenuBar(BOOL bDoRecalcLayout = TRUE)
            {
                  BOOL bRet = CExtMenuControlBar::_UpdateMenuBar( FALSE ); // CHANGED
                  for( int nPos = 0; nPos < GetButtonsCount(); nPos++ ) {
                        UINT nCmdId = GetButton(nPos)->GetCmdID();
                        CExtCmdItem *pCmdItem =
                                    g_CmdManager->CmdGetPtr(
                                          g_CmdManager->ProfileNameFromWnd(GetSafeHwnd()),
                                          nCmdId
                                          );
                        ASSERT( pCmdItem != NULL );
                        pCmdItem->m_sToolbarText = _T("My") + pCmdItem->m_sMenuText;
                  }
                  if( bDoRecalcLayout )
                  {
                        Invalidate();
                        _RecalcLayoutImpl();
                        UpdateWindow();
                        if( IsFloating() )                                 // ADDED
                              GetParentFrame()->SendMessage( WM_NCPAINT ); // ADDED
                  }
                  return bRet;
            }
      };