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.

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 CForm. 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 based 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

  1. Display the New or the New Project dialog box and specify that you want to use MFC AppWizard or MFC Application
  2. Set the Project Name to FormBased1

  3. Click OK
  4. Specify that you want to create a Single Document type of application
  5. In the last step, in the Base Class combo box, select CFormView
  6. Click Finish
  7. To display the form, in the Resource View, expand the Dialog folder and double-click IDD_FORMBASED1_FORM
  8. In the Properties window, notice that its Style is set to Child and its Border is set to None
  9. Press Ctrl + F5 to test the application.
  10. After viewing it, return to MSVC



Previous Copyright © 2003-2015, FunctionX Next