Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1
Chapter 2: Introduction to MFC Visual C++ and MFC Fundamentals


  1. In the list of files, click Main.h and click Open

  2. In the FileView tab of the Workspace, if necessary, expand the Header Files node.
    Double-click Main.h to display it in the Source Code Editor


1.3.4 Adding Classes........................................................................................


To add a class to your project, you have various options. You can separately create a
header file then create a source file. You can also import an existing header file and a
source file from any valid path.

Microsoft Visual C++ makes it easy to create a C++ class. When doing this, a header and
a source files are prepared. A (default) constructor and a destructor are added. You can
delete or completely change the supplied constructor and/or the destructor. Also, Visual
C++ includes the name of the header file in the source file so you would not have
forgotten to do this.

Most classes in Visual C++ have their names starting with the letter C. Although this is
only a suggestion, and any valid class name would work fine, to keep some harmony, in
this book, we will follow this convention.

To create a new class and add it to your project:
?? On the main menu, you can click Insert -> New Class ...

?? In the ClassView tab of the Workspace, you can right-click the name of the
project and click New Class...
Any of these actions would open the New Class dialog box. From here, you can specify
the type of class you want to create and click Open. You will then be asked to provide a
name for the class.

Practical Learning: Creating a Class



  1. To create a new class, in the ClassView tab, right-click Exercise2 and click New
    Class...

  2. In the New Class dialog box, in the Name edit box, type CPart


Note
In this book, we will
not follow the
famous “hungarian”
naming convention
because nobody
seems to be able to
follow or keep up
with it, not even
programmers from
Microsoft.

Free download pdf