Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 2: Introduction to MFC


2.2.1 Introduction..............................................................................................


The basic functionality of a window is defined in a class called CWnd. An object created
from CWnd must have a parent. In other words, it must be a secondary window, which is
a window called from another, existing, window.

The CWnd class gives birth to a class called CFrameWnd. This class actually describes
a window or defines what a window looks like. The description of a window includes
items such as its name, size, location, etc. To create a window using the CFrameWnd
class, you must create a class derived from the CFrameWnd class.

Figure 21: Window Illustration....................................................................................................


As in real world, a Microsoft Windows window can
be identified on the monitor screen because it has a
frame. To create such a window, you can use the
CFrameWnd class. CFrameWnd provides various
alternatives to create a window. For example, it is
equipped with a method called Create(). The Create()
method uses a set of arguments that define a complete
window.

The syntax of the CFrameWnd::Create() method is
as follows:

BOOL Create(
LPCTSTR lpszClassName,
LPCTSTR lpszWindowName,
DWORD dwStyle = S_OVERLAPPEDWINDOW,
const RECT& rect = rectDefault,
CWnd* pParentWnd = NULL,
LPCTSTR lpszMenuName = NULL,
DWORD dwExStyle = 0,
CCreateContext* pContext = NULL );

As you can see, only two arguments are necessary to
create a window, the others, though valuable, are
optional.

As you should have learned from C++, every class in a program has a name. The name
lets the compiler know the kind of object to create. The name of a class follows the
conventions used for C++ names. That is, it must be a null-terminated string. Many
classes used in Win32 and MFC applications are already known to the Visual C++
compiler. If the compiler knows the class you are trying to use, you can specify the
lpszClassName as NULL. In this case, the compiler would use the characteristic of the
CFrameWnd object as the class' name. Therefore, the Create() member function can be
implemented as follows:

Create(NULL);

Every object in a computer has a name. In the same way, a window must have a name.
The name of a window is specified as the lpszWindowName argument of the Create()
method. In computer applications, the name of a window is the one that displays on the
top section of the window. This is the name used to identify a window or an application.
For example, if a window displays Basic Windows Application, then the object is called
the "Basic Windows Application Window". Here is an example:

Create(NULL, "Basic Windows Application");
Free download pdf