Note Microsoft Visual C++ 2005 supports both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model.
The following section lists the steps required to support creating a single document interface (SDI) or multiple document interface (MDI) application based on a CFormView, sizing the initial frame window around the form, changing the style of the frame, and closing an MDI document using a button in the form.
- Use the AppWizard to generate an SDI or MDI application. This inserts a dialog box template with the correct styles set for your project's resource file.
Visual Studio 6.0:
At step 6 of the AppWizard, select the view class. In the Base class combo box, select CFormView to specify CFormView as the base class.
Visual Studio .NET or Visual Studio 2005:
In step 1 of the AppWizard, select Generated Classes. In the Base class combo box, select CFormView to specify CFormView as the base class.
- Override the OnUpdate() member function and call UpdateData() as documented in the CFormView documentation to update the member variables with the current document data and to perform dialog data exchange (DDX).
NOTE: UpdateData is not virtual and calling the base class ensures that the derived class DoDataExchange is called through standard polymorphism. The CFormView documentation states to call, not override UpdateData.
- If you would like to set the initial size of the form view, override the OnInitialUpdate() function. The text below provides additional information about this step, which is slightly different in an SDI or MDI application.
Changing the Size of an SDI Main Frame Around a CFormViewTo change the size of the main frame of an SDI application (that uses CFormView as its view class) to be the appropriate size for the form you designed in App Studio, override the OnInitialUpdate() function in your class derived from CFormView, as follows:
ResizeParentToFit(); // default argument is TRUE
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT &cs)
cs.style &= ~WS_THICKFRAME;
Changing the Size of an MDI Child Frame Around a CFormViewThe process of changing the size of an MDI child frame is similar to changing the size of a main frame for an SDI application, as explained above. However, the RecalcLayout() call is not required.
To change the size of an MDI child frame around a form view, override the OnInitialUpdate() function in your class derived from CFormView as follows:
ResizeParentToFit(); // Default argument is TRUE.
To change the style of the MDI child frame (for example, to remove the WS_THICKFRAME style so the user cannot change the size of the window), derive an MDI child window class and override the PreCreateWindow function as demonstrated in the SDI example above.
Closing an MDI Form with a ButtonTo create a button on a form that closes the document add a message handler for the BN_CLICKED message to the CFormView class. Make sure that the buttons in CFormView do not have the default IDOK or IDCANCEL identifiers. If they do, then incorrect entries in the message map and incorrect functions for the buttons will be created.
Once the message handler is in place, you can simulate the Close command on the File menu with the following code:
ID do Artigo: 98598 - Última Revisão: 04/01/2006 - Revisão: 1