Share via


Form Topics

You can add forms to any Visual C++ application that supports the MFC libraries, including a forms-based application (one whose view class is derived from CFormView). If you didn't initially create your application to support forms, Visual C++ will add this support for you when you insert a new form. In an SDI or MDI application, which implements the default , when the user chooses the New command (by default, on the File menu), Visual C++ prompts the user to choose from the available forms.

With an SDI application, when the user chooses the New command, the current instance of the form closes and the user can open another instance of that form or any other available form. In an MDI application, the current instance of the form continues to run when the user chooses the New command.

Note   You can insert a form into a dialog-based application (one whose dialog class is based on CDialog and one in which no view class is implemented). However, without the document/view architecture, Visual C++ does not automatically implement the File|New functionality. You must create a way for the user to view additional forms, such as by implementing a tabbed dialog box with various property pages.

When you insert a new form into your application, Visual C++ does the following:

  • Creates a class based on one of the form-style classes that you choose (CFormView, CRecordView, CDaoRecordView, or CDialog).

    For programs without a document/view architecture (this includes dialog-based applications and ATL programs with MFC support), the initial base class is always CDialog.

  • Creates a dialog resource with appropriate styles (or you can use an existing dialog resource that has not yet been associated with a class).

    If you choose an existing dialog resource, you may need to set these styles by using the Properties page for the dialog box. Styles for a dialog box must include:

    WS_CHILD=On

    WS_BORDER=Off

    WS_VISIBLE=Off

    **WS_CAPTION=**Off

For applications based on the document/view architecture, the New Form command also:

  • Creates a CDocument-based class with a name based on the first three letters of the form class (skipping the leading "C").

    You can choose, instead of having a new class created, to use any existing CDocument-based class in your project.

  • Generates a document template (derived from CDocument) with string, menu, and icon resources.

    You can also create a new class on which to base the template.

  • Adds a call to AddDocumentTemplate in your app's InitInstance code.

    Visual C++ adds this code for each new form you create, which adds the form to the list of available forms when the user chooses the New command. This code includes the form's associated resource ID, and the names of the associated document, view, and frame classes that together make up the new form object.

    Document templates serve as the connection between documents, frame windows, and views. For a single document, you can create many templates.

What do you want to do?

Insert a form into a project