Chapter 12: Dialog-Based Windows Visual C++ and MFC Fundamentals
13.1 Forms.............................................................................................................
13.1.1..Introduction..........................................................................................
Like a dialog box, a form is the primary object used to host Windows controls to allow
user interaction with the computer. Like a dialog box, a form does not mean anything
except for the controls it is hosting. This means that a form by itself does not present any
significant functionality but it can be equipped with characteristics that make it a valuable
alternative to other view types.
When using a form, the user typically interacts with the controls it is hosting. These
controls can be positioned anywhere on the form. If there are too many controls or the
controls are positioned so the occupied area is larger than the form can display at one
time, the form would be equipped with scroll bars.
A form is created using the CFormView class which is derived indirectly from CView
through CScrollView.
13.1.2..Form Creation......................................................................................
There are three main ways you can provide a form to an application.
The easiest way to create a form is by using the AppWizard. To do this, when creating
the application, set the Base Class to CFormView. A document/view application would
be created with its view based on the CFormView class. The wizard would have created
a Child window with no borders and no title bar (over all, you should not attempt to
change the properties of this window). Also, if you create an application that supports
databases, AppWizard would create a form that can be used on that database.
If you have already created an application, for example based on CView, you can either
add a form view to the application, change the application's base view class into form
view, or replace its view class with a form view. If you add a form view to the
application, the user would be prompted to select one of both documents when the
applications comes up.
The last option you have, which you should hardly do is to work from scratch in creating
a form view-based application. The reason you should not spend time doing this is the
amount of work involved that would not necessarily improve your application.
Practical Learning: Creating a Form-Based Application
- Display the New or the New Project dialog box and specify that you want to use
MFC AppWizard or MFC Application - Set the Project Name to FormBased1