KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q315603: HOW TO: Create a Class Derived from CControlBar and Its SubClass

Article: Q315603
Product(s): Microsoft C Compiler
Version(s): 6.0
Operating System(s): 
Keyword(s): kbDSupport kbAudDeveloper kbHOWTOmaster
Last Modified: 23-MAY-2002

-------------------------------------------------------------------------------
The information in this article applies to:

- Microsoft Visual C++ Standard Edition, version 6.0 
- Microsoft Visual C++, 32-bit Enterprise Edition, version 6.0 
-------------------------------------------------------------------------------

IN THIS TASK

- SUMMARY

   - Requirements
- Generating a Class That Is Based on CWnd
- Modifying the Class Source

SUMMARY
=======

In Microsoft Visual C++ 6.0, ClassWizard does not list CControlBar or any of its
subclasses (CDialogBar, COleResizeBar, CStatusBar, CToolBar, and CReBar) in the
"Base class" drop-down list box. This article shows you how to create a class
derived from CControlBar and from its subclasses by using ClassWizard.

Requirements
------------

- You must know Visual C++ 6.0 and the MFC framework classes.

Generating a Class That Is Based on CWnd
----------------------------------------

To create a class derived from CControlBar, select "generic CWnd" as the base
class, and then modify the files that are generated by ClassWizard.

For example, suppose you want to create a class called CMyBar that is derived
from CReBar in an existing project. The following instructions assume that you
have started Visual C++ 6.0 and that you have an MFC-based project open.

1. Click New Class on the Insert menu.

2. Type the class name "CMyBar" (without the quotation marks) in the Name field
  of the dialog box.

3. Click "generic CWnd" in the "Base class" field of the dialog box.

4. Click OK.

5. If the Workspace window is not visible, click Workspace on the View menu.

6. At the bottom of the Workspace window, click the FileView tab.

7. In the Workspace window, expand the Source Files folder and the Header Files
  folder. Make sure that the files named MyBar.cpp and MyBar.h have been
  generated.

Modifying the Class Source
--------------------------

You must modify the code that is generated for the derived class because
ClassWizard has created a class derived from CWnd and not from CReBar. You must
change the second parameter of the BEGIN_MESSAGE_MAP macro that is added to the
implementation of the class from CWnd to CReBar. This parameter specifies the
immediate base class of the derived class.

1. Edit the file MyBar.cpp, and then change the message map declaration as
  follows:

  BEGIN_MESSAGE_MAP(CMyBar, CReBar)

2. Edit MyBar.h. Change the derived class definition so that it specifies CReBar
  as the base class, as follows:

  class CMyBar : public CReBar

Additional query words:

======================================================================
Keywords          : kbDSupport kbAudDeveloper kbHOWTOmaster 
Technology        : kbVCsearch kbAudDeveloper kbVC600 kbVC32bitSearch
Version           : :6.0
Issue type        : kbhowto

=============================================================================

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1986-2002.