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 » 16x16 and 32x32 toolbars Collapse All
Subject Author Date
Timothy Anderson May 6, 2008 - 10:07 PM

 


I have two toolbars, one uses a 16x16 toolbar bitmap, the other uses a 32x32 bitmap. They are created like this:


 // This is the main small toolbar

 if (!m_wndToolBar[0].Create(NULL, this, IDR_MAINFRAME1))

 {

        TRACE0("Failed to create small toolbar psf\n");

        return false;

 }

 m_wndToolBar[0].LoadToolBar(IDR_MAINFRAME1);

 m_wndToolBar[0].EnableDocking(CBRS_ALIGN_ANY);


 // This is the main large toolbar

 if (!m_wndToolBar[1].Create(NULL, this, IDR_MAINFRAME1_LARGE))

 {

        TRACE0("Failed to create large toolbar psf\n");

        return false;

 }

 m_wndToolBar[1].LoadToolBar(IDR_MAINFRAME1_LARGE);

 m_wndToolBar[1].EnableDocking(CBRS_ALIGN_ANY);


And I simply switch back and forth by doing a show window. Regardless of what toolbar is supposed to be displayed, the large bitmap is the one that is used. How do I do this? I want multiple toolbars, all at either 16x16 or 32x32. I assumed having two identical toolbars with the different bitmaps and toggling back and forth between them would work as expected.


May I add that this text editor you are using for this website is terrible.

Technical Support May 7, 2008 - 3:04 PM

You should use two commands instead one particular command in a toolbar in your project. I.e. you should have ID_FILE_OPEN in the menu and in a 16x16 toolbar resource and a new ID_FILE_OPEN_BIG command in a 32x32 resource. The command manager should be updated from both toolbars. The OnFileNew() and OnUpdateFileNew() methods are currently connected to the ID_FILE_OPEN command only in the message map(s) in your project. You should also connect these handler methods to the ID_FILE_OPEN_BIG command by adding some appropriate message map entries. You can re-initialize toolbar by using CExtToolControlBar::LoadToolBar() or CExtToolControlBar::SetButtons() methods.

Timothy Anderson May 7, 2008 - 3:06 PM

Thanks for the pointers! I like the "reload the bitmap" approach, it seems a little easier.

Technical Support May 7, 2008 - 1:15 PM

There are several approaches with regard to how to implement the support for icons of different sizes. Creating two toolbars instead one is not effective. You can simply re-load icons into the command manager:

UINT nToolBarResourceID = . . . // ID of small or big toolbar resource in your project.
CExtToolControlBar * pToolBar = . . .
      ASSERT_VALID( pToolBar );
LPCTSTR strCommandProfileName = g_CmdManager->ProfileNameFromWnd( pToolBar->GetSafeHwnd() );
      ASSERT( strCommandProfileName != NULL );
      //
      // First, we will remove icons for toolbar commands in the command manager
      //
CExtCmdIcon iconEmpty;
INT nButtonIndex, nButtonCount = pToolBar->GetButtonsCount();
      for( nButtonIndex = 0; nButtonIndex < nButtonCount; nButtonIndex )
      {
            CExtBarButton * pTBB = pToolBar->GetButton(nButtonIndex );
            ASSERT_VALID( pTBB );
            if( pTBB->IsSeparator() || pTBB->IsKindOf( RUNTIME_CLASS(CExtBarContentExpandButton) ) )
                  continue;
            UINT nCmdID = pTBB->GetCmdID();
            CExtCmdItem * pCmdItem = g_CmdManager->CmdGetPtr( strCommandProfileName, nCmdID );
            if( pCmdItem == NULL )
                  continue;
            g_CmdManager->CmdSetIcon( strCommandProfileName, nCmdID, iconEmpty );
      }
      //
      // Second, we will update the command manager from toolbar resource
      //
      g_CmdManager->UpdateFromToolBar( strCommandProfileName, nToolBarResourceID );
      //
      // Third, we will recomputed layout of toolbar’s parent frame window
      //
      pToolBar->GetParentFrame()->RecalcLayout();
The code above (can be a global function or static method) will reload icons for all the toolbar commands from a known toolbar resource.

Please note, the newly loaded icons will be used both in toolbars and menus. If you need different size icons in toolbars and menus, then you should use different command identifiers in toolbars and menus. I.e. each command should have two identifiers and you should bind one command handler method for two identifiers.

As for the text editor, it is a well-know editor FCKEditor (http://www.fckeditor.net/).


Timothy Anderson May 7, 2008 - 4:07 PM

Don’t forget the "nButtonIndex++" in the for loop there. Otherwise it works perfectly! Woo Hoo!

Technical Support May 8, 2008 - 3:01 AM

We meant two for loops in the CExtControlBar::InternalFriendlyFrameWnd::SetOuterDockState() method where the i variable is used in all 3 parts of the for statement - not the nButtonIndex variable. Here is the latest code of this method:

void CExtControlBar::InternalFriendlyFrameWnd::SetOuterDockState(
      const CDockState & state,
      const CExtControlBar::OuterPropsArr_t & arrOuterProps,
      bool bSerializeFixedBarsState,
      bool bSerializeResizableBarsState
      )
{
      // first pass through barinfo’s sets the m_pBar member correctly
      // creating floating frames if necessary
//CMapPtrToWord _mapCFV;
int i = 0;
      for( i = 0; i < state.m_arrBarInfo.GetSize(); i++ )
      {
            CControlBarInfo * pInfo = (CControlBarInfo *)
                  state.m_arrBarInfo[i];
            ASSERT( pInfo != NULL );
            CControlBar * pExistingBar = GetControlBar( pInfo->m_nBarID );
            if( pExistingBar != NULL )
            {

//
//CControlBar * pOld = pInfo->m_pBar;
//pInfo->m_pBar = pExistingBar;
//__DEBUG_trace_bar_info( _T("-LOAD-"), pInfo, 4 );
//pInfo->m_pBar = pOld;
//

                  if(         (! pExistingBar->IsKindOf(RUNTIME_CLASS(CExtControlBar)) )
                        ||    ( ((CExtControlBar*)pExistingBar)->IsFixedMode() )
                        ||    ( ((CExtControlBar*)pExistingBar)->IsFixedDockStyle() )
                        )
                  {
                        if( ! bSerializeFixedBarsState )
                              continue;
                  }
                  else
                  {
                        if( ! bSerializeResizableBarsState )
                              continue;
                  }
            }
            if( pInfo->m_bFloating )
            {
                  // need to create floating frame to match
                  CMiniDockFrameWnd * pDockFrame =
                        CreateFloatingFrame(
                              pInfo->m_bHorz ?
                                    CBRS_ALIGN_TOP : CBRS_ALIGN_LEFT
                              );
                  ASSERT( pDockFrame != NULL) ;
                  CRect rcWnd( pInfo->m_pointPos, CSize(10, 10) );
                  pDockFrame->CalcWindowRect( &rcWnd );
                  pDockFrame->SetWindowPos(
                        NULL,
                        rcWnd.left, rcWnd.top, 0, 0,
                        SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE
                        );
                  CDockBar * pDockBar = (CDockBar *)
                        pDockFrame->GetDlgItem( AFX_IDW_DOCKBAR_FLOAT );
                  ASSERT( pDockBar != NULL );
                  ASSERT_KINDOF( CDockBar, pDockBar );
                  pInfo->m_pBar = pDockBar;
//                if( pInfo->m_bVisible )
//                      _mapCFV.SetAt( pDockFrame, 0 );
            } // if( pInfo->m_bFloating )
            else // regular dock bar or toolbar
            {
                  pInfo->m_pBar =
                        pExistingBar; // GetControlBar( pInfo->m_nBarID );
                  if( pInfo->m_pBar == NULL )
                        continue;
            } // else from if( pInfo->m_bFloating )
            pInfo->m_pBar->m_nMRUWidth = pInfo->m_nMRUWidth;
      } // for( i = 0; i < state.m_arrBarInfo.GetSize(); i++ )

      // update new outer props
      for( i = 0; i < arrOuterProps.GetSize(); i++ )
      {
            OuterItemData_t _oid = arrOuterProps[i];
            CControlBar * pBarTmp = GetControlBar( _oid.m_nBarID );
            if( pBarTmp == NULL )
                  continue;
            CExtControlBar * pExtBar = DYNAMIC_DOWNCAST( CExtControlBar, pBarTmp );
            if( pExtBar == NULL )
                  continue;
            if(         ( pExtBar->IsFixedMode() )
                  ||    ( pExtBar->IsFixedDockStyle() )
                  )
            {
                  if( ! bSerializeFixedBarsState )
                        continue;
            }
            else
            {
                  if( ! bSerializeResizableBarsState )
                        continue;
            }
            pExtBar->m_ptFloatHelper = _oid.m_ptFloatHelper;
            pExtBar->m_sizeDockedH = _oid.m_sizeDockedH;
            pExtBar->m_sizeDockedV = _oid.m_sizeDockedV;
            pExtBar->m_sizeFloated = _oid.m_sizeFloated;
            pExtBar->_AffixmentSetOuter( &_oid.m_AffixmentData );
      } // for( i = 0; i < arrOuterProps.GetSize(); i++ )

      // the second pass will actually dock all of the control bars and
      // set everything correctly
      for( i = 0; i < state.m_arrBarInfo.GetSize(); i++ )
      {
            CControlBarInfo * pInfo = (CControlBarInfo *)
                  state.m_arrBarInfo[i];
            ASSERT( pInfo != NULL );
            if( pInfo->m_pBar == NULL )
                  continue;
            if(         (! pInfo->m_pBar->IsKindOf(RUNTIME_CLASS(CExtControlBar)) )
                  ||    ( ((CExtControlBar*)pInfo->m_pBar)->IsFixedMode() )
                  ||    ( ((CExtControlBar*)pInfo->m_pBar)->IsFixedDockStyle() )
                  )
            {
                  if( ! bSerializeFixedBarsState )
                        continue;
            }
            else
            {
                  if( ! bSerializeResizableBarsState )
                        continue;
            }
            if(         pInfo->m_pBar->m_pDockContext != NULL
                  &&    pInfo->m_pBar->IsKindOf(RUNTIME_CLASS(CExtControlBar))
                  )
                  ((CExtControlBar*)(pInfo->m_pBar))->m_ptFloatHelper
                        = pInfo->m_ptMRUFloatPos;
            pInfo->m_pBar->SetBarInfo( pInfo, this );
      } // for( i = 0; i < state.m_arrBarInfo.GetSize(); i++ )

      // the third pass will move independent floating bars
      // into valid positions
      for( i = 0; i < arrOuterProps.GetSize(); i++ )
      {
            OuterItemData_t _oid = arrOuterProps[i];
            CControlBar * pBarTmp = GetControlBar( _oid.m_nBarID );
            if( pBarTmp == NULL )
                  continue;
            CExtControlBar * pExtBar = DYNAMIC_DOWNCAST( CExtControlBar, pBarTmp );
            if( pExtBar == NULL )
                  continue;
            if(         ( pExtBar->IsFixedMode() )
                  ||    ( pExtBar->IsFixedDockStyle() )
                  )
            {
                  if( ! bSerializeFixedBarsState )
                        continue;
            }
            else
            {
                  if( ! bSerializeResizableBarsState )
                        continue;
            }
            if( ! _oid.m_bFloating )
                  continue;
            CSize _sizeFloating = _oid.m_sizeFloated;
            CRect rcFrameInitial( _oid.m_ptFloatHelper, _sizeFloating /*_oid.m_sizeFloated*/ );
            CExtMiniDockFrameWnd * pMiniFrame =
                  DYNAMIC_DOWNCAST(
                        CExtMiniDockFrameWnd,
                        pExtBar->GetParentFrame()
                        );
            if( pMiniFrame != NULL )
            {
                  CRect rcClientFrame, rcWndFrame;
                  pMiniFrame->GetClientRect( &rcClientFrame );
                  pMiniFrame->GetWindowRect( &rcWndFrame );
                  _sizeFloating += rcWndFrame.Size() - rcClientFrame.Size();
                  rcFrameInitial.right += rcWndFrame.Width() - rcClientFrame.Width();
                  rcFrameInitial.bottom += rcWndFrame.Height() - rcClientFrame.Height();
            }
            CRect rcFrameNew =
                  CExtPaintManager::stat_AlignWndRectToMonitor(
                        rcFrameInitial
                        );
//          CExtMiniDockFrameWnd * pMiniFrame =
//                DYNAMIC_DOWNCAST(
//                      CExtMiniDockFrameWnd,
//                      pExtBar->GetParentFrame()
//                      );
            if( pMiniFrame != NULL )
            {
                  ASSERT_VALID( pMiniFrame );
                  CRect rcFrameReal;
                  pMiniFrame->GetWindowRect( rcFrameReal );
                  
                  //if( rcFrameReal == rcFrameNew )
                  if( rcFrameReal.TopLeft() == rcFrameNew.TopLeft() )
                        continue;
                  pExtBar->OnNcAreaButtonsReinitialize();
                  if( ! pExtBar->IsFixedMode() )
                        pMiniFrame->ModifyStyle( FWS_SNAPTOBARS, 0 );
                  //((InternalFriendlyFrameWnd *)pMiniFrame)->m_bInRecalcLayout = TRUE;
                  pMiniFrame->MoveWindow( &rcFrameNew, FALSE );
                  //((InternalFriendlyFrameWnd *)pMiniFrame)->m_bInRecalcLayout = FALSE;
                  pMiniFrame->DelayRecalcLayout();
                  //WORD tmp;
                  //if(       _mapCFV.Lookup( pMiniFrame, tmp )
                  //    &&    ( pMiniFrame->GetStyle()&WS_VISIBLE ) == 0
                  //    &&    ( ! pExtBar->IsFixedMode() )
                  //    )
                  if( _oid.m_bVisible )
                  {
                        pExtBar->DelayShow( TRUE );
                        CSize _size = rcFrameNew.Size();
                        pExtBar->SetInitDesiredSizeFloating( _size );
                        pExtBar->m_pDockContext->m_sizeLast = _size;

                        pMiniFrame->ShowWindow( SW_SHOWNOACTIVATE );
//                      ((InternalFriendlyFrameWnd *)pMiniFrame)->m_bInRecalcLayout = TRUE;
                        pMiniFrame->MoveWindow( &rcFrameNew, FALSE );
//                      ((InternalFriendlyFrameWnd *)pMiniFrame)->m_bInRecalcLayout = FALSE;
                        pMiniFrame->RecalcLayout();
                        CRect rcClientFrame, rcWndFrame;
                        pMiniFrame->GetClientRect( &rcClientFrame );
                        pMiniFrame->GetWindowRect( &rcWndFrame );
                        CRect rcClientBar, rcWndBar;
                        pExtBar->GetClientRect( &rcClientBar );
                        pExtBar->GetWindowRect( &rcWndBar );
                        CSize _sizeBar =
                              _sizeFloating // _oid.m_sizeFloated
                                    - rcClientFrame.Size()
                                    + rcWndFrame.Size()
                                    - rcClientBar.Size()
                                    + rcWndBar.Size()
                                    ;
                        pExtBar->OnRepositionSingleChild(
                              _sizeBar.cx,
                              _sizeBar.cy,
                              true
                              );
                  }
            } // if( pMiniFrame != NULL )
            else
                  pExtBar->FloatControlBar( rcFrameNew.TopLeft() );
      } // for( i = 0; i < arrOuterProps.GetSize(); i++ )

      // last pass shows all the floating windows that were previously shown
      for( i = 0; i < state.m_arrBarInfo.GetSize(); i++ )
      {
            CControlBarInfo * pInfo = (CControlBarInfo *)
                  state.m_arrBarInfo[i];
            ASSERT( pInfo != NULL );
            if( pInfo->m_pBar == NULL )
                  continue;
            if(         (! pInfo->m_pBar->IsKindOf(RUNTIME_CLASS(CExtControlBar)) )
                  ||    ( ((CExtControlBar*)pInfo->m_pBar)->IsFixedMode() )
                  ||    ( ((CExtControlBar*)pInfo->m_pBar)->IsFixedDockStyle() )
                  )
            {
                  if( ! bSerializeFixedBarsState )
                        continue;
            }
            else
            {
                  if( ! bSerializeResizableBarsState )
                        continue;
            }
            if( ! pInfo->m_bFloating )
                  continue;
            CFrameWnd * pFrameWnd =
                  pInfo->m_pBar->GetParentFrame();
            CDockBar * pDockBar = (CDockBar *) pInfo->m_pBar;
            ASSERT_KINDOF( CDockBar, pDockBar );
            if( pDockBar->GetDockedVisibleCount() > 0 )
            {
                  pFrameWnd->RecalcLayout();
                  pFrameWnd->ShowWindow( SW_SHOWNA );
                  for( INT nBar = 1; nBar < pDockBar->m_arrBars.GetSize(); nBar ++ )
                  {
                        ASSERT( pDockBar->m_arrBars[0] == NULL );
                        CControlBar * pBar = (CControlBar *)
                              pDockBar->m_arrBars[nBar];
                        if( pBar == NULL )
                              continue;
                        if( __PLACEHODLER_BAR_PTR(pBar) )
                              continue;
                        CExtControlBar * pExtBar =
                              DYNAMIC_DOWNCAST(
                                    CExtControlBar,
                                    pBar
                                    );
                        if( pExtBar == NULL
                              || pExtBar->IsFixedMode()
                              )
                              continue;
                        pExtBar->_RecalcNcArea();
                  }
            } // if( pDockBar->GetDockedVisibleCount() > 0 )
      } // for( i = 0; i < state.m_arrBarInfo.GetSize(); i++ )
}


Timothy Anderson May 9, 2008 - 1:02 PM

...and this has exactly what to do with reloading icons into the command manager?


I’m having a problem with serialization using the first method above. After the icons are loaded up correctly, the toolbars seem to be "disabled" when I go to fire the application up again. So it’s updating the icons correctly (the first code chunk) but either the serialization on close is not working correctly with this updated toolbar, or the serialization on startup is not working correctly.


If I just leave the toolbars alone everything serializes correctly, but when I change them from one toolbar resource to the next they magically disappear on the next startup of the application.

Timothy Anderson May 9, 2008 - 2:39 PM

Oops! I found it. I had accidently coded in an assumption the toolbar ID changed to the resource ID when switching between the two. So I always use the small toolbar resource ID to identify the toolbar then just slam the larger icons into it as needed.


Woo Hoo! Multi-sized toolbars!

Timothy Anderson May 7, 2008 - 12:59 PM

It also wants to use the 32x32 icons in all the menus.


I want: always use 16x16 icons everywhere. Optionally display either a 16x16 or a 32x32 sized icon based toolbar. I can’t believe no one does multiple sized toolbars.