Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 2 Variables and Identifiers Visual C++ and MFC Fundamentals


Figure 22: A Window Frame with Title Bar..............................................................................


In all of your windows, you should specify a window name. If you omit it, the users of
your window would have difficulty identifying it. Here is an example of such a window:

Figure 23: A Window Frame with no Caption..........................................................................


2.2.2 Reference to the Main Window............................................................


After creating a window, to let the application use it, you can use a pointer to the class
used to create the window. In this case, that would be (a pointer to) CFrameWnd. To use
the frame window, assign its pointer to the CWinThread::m_pMainWnd member
variable. This is done in the InitInstance() implementation of your application.

At any time, to get a pointer to m_pMainWnd anywhere in your program, you can call
the AfxGetMainWnd() function. Its syntax is:

CWnd* AfxGetMainWnd();

This function simply returns a pointer to CWnd. Because all MFC’s window objects are
based on the CWnd class, this function can give you access to the main class used for the
application.

Practical Learning: Creating a Simple Window



  1. To create a frame for the window, in the file, type the following:

Free download pdf