Fix2lBar.exe Fixes Spacing Errors in MFC's CToolBar

ID: Q195081


The information in this article applies to:
  • Microsoft Visual C++, 32-bit Editions, version 6.0


SUMMARY

Fix2lBar.exe is a sample that show how to correct CToolBar's behavior. The original CToolBar, relying only on early releases of the common controls, does not behave intuitively whenever it contains two or more consecutive separators and it has vertical orientation. This behavior is even more striking when the toolbar has the new TBSTYLE_FLAT style.

This sample provides a CToolBar-derived class that takes advantage of the new common controls features, in particular, of the CCS_VERT style, now available for control bars. Building on the new features of the toolbar control, the new class overrides the necessary functions to provide the correct behavior. The class requires ComCtl32.DLL versions 4.72 or greater.


MORE INFORMATION

The following files are available for download from the Microsoft Download Center. Click the file names below to download the files:


Fix2lBar.exe

For more information about how to download files from the Microsoft Download Center, please visit the Download Center at the following Web address

http://www.microsoft.com/downloads/search.asp
and then click How to use the Microsoft Download Center.


   File Name          Size
   ---------------------------------------------------------

   FixToolBar.h,      The new CFixToolBar class that overrides
   FixToolBar.cpp     necessary methods in CtoolBar.
   FixTBar.dsp        The project file.
   FixTBar.h          The main header file for the application.
   FixTBar.cpp        The main application source file (CFixTBarApp).
   FixTBar.rc         Listing of all Windows resources used.
   res\FixTBar.ico    Icon file, which is used as the application's icon.
   res\FixTBar.rc2    Resources that are not edited by Visual C++ IDE.
   MainFrm.h,
   MainFrm.cpp        Contain the frame class CMainFrame.
   res\Toolbar.bmp    Used to create tiled images for the toolbar.
   FixTBarDoc.h,
   FixTBarDoc.cpp     The document CFixTBar class.
   FixTBarView.h
   FixTBarView.cpp    The view of the document CFixTBarView class.
   StdAfx.h
   StdAfx.cpp         Used to build a precompiled header (PCH) file.
   Resource.h         Defines new resource IDs. 
The sample contains an AppWizard-generated SDI application, and implements a CToolBar-derived class that implements the necessary fixes. The solution relies basically on adding the new style CCS_VERT to the toolbar when it must display more than just one row of buttons. In addition, the CalcSize() and WrapToolBar() functions must be overridden. However, because these two functions are not virtual, all CToolBar members that call these two functions need to be copied and pasted in the new class, up to and including the virtual functions CalcFixedLayout() and CalcDynamicLayout().

To illustrate the problem, the resource file has been edited to define the toolbar as:

   IDR_MAINFRAME TOOLBAR DISCARDABLE  16, 15
   BEGIN
       BUTTON      ID_FILE_NEW
       BUTTON      ID_FILE_OPEN
       BUTTON      ID_FILE_SAVE
           SEPARATOR
           SEPARATOR
       BUTTON      ID_EDIT_CUT
       BUTTON      ID_EDIT_COPY
       BUTTON      ID_EDIT_PASTE
           SEPARATOR
       BUTTON      ID_FILE_PRINT
           SEPARATOR
       BUTTON      ID_APP_ABOUT
   END 
You can experiment with both flat style toolbars and old style toolbars. To do this, comment in and out the corresponding toolbar creation code in CMainFrame::OnCreate().

NOTE: To use this fix on a Visual C++ 5.0 system, you need to add the two files, FixToolBar.h and FixToolBar.cpp, to a Visual C++ 5.0-generated project. Make sure you have the new common controls dll; add the corresponding new header (Commctrl.h and Commctrl.rh in DevStudio\VC\include directory) and lib files (Comctl32.lib in DevStudio\VC\lib) to your Visual C++ 5.0 installation.

Additional query words: kbDSupport

Keywords : kbfile kbMFC KbUIDesign kbVC600
Version : winnt:6.0
Platform : winnt
Issue type :


Last Reviewed: December 11, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.