Programming Microsoft Visual C++
The CFormView class is a useful view class that has many of the characteristics of a modeless dialog window. Like a class derived from CDialog, a derived CFormView class is associated with a dialog resource that defines the frame characteristics and enumerates the controls. The CFormView class supports the same dialog data exchange and validation (DDX and DDV) functions that you saw in the CDialog examples in Chapter 6.
If AppWizard generates a Form View dialog, the properties are set correctly, but if you use the dialog editor to make a dialog for a form view, you must specify the following items in the Dialog Properties dialog:
Style = Child
Border = None
Visible = unchecked
A CFormView object receives notification messages directly from its controls, and it receives command messages from the application framework. This application framework command-processing ability clearly separates CFormView from CDialog, and it makes controlling the view from the frame's main menu or toolbar easy.
The CFormView class is derived from CView (actually, from CScrollView) and not from CDialog. You can't, therefore, assume that CDialog member functions are supported. CFormView does not have virtual OnInitDialog, OnOK, and OnCancel functions. CFormView member functions do not call UpdateData and the DDX functions. You have to call UpdateData yourself at the appropriate times, usually in response to control notification messages or command messages.
Even though the CFormView class is not derived from the CDialog class, it is built around the Microsoft Windows dialog. For this reason, you can use many of the CDialog class member functions such as GotoDlgCtrl and NextDlgCtrl. All you have to do is cast your CFormView pointer to a CDialog pointer. The following statement, extracted from a member function of a class derived from CFormView, sets the focus to a specified control. GetDlgItem is a CWnd function and is thus inherited by the derived CFormView class.
((CDialog*) this)->GotoDlgCtrl(GetDlgItem(IDC_NAME));
AppWizard gives you the option of using CFormView as the base class for your view. When you select CFormView, AppWizard generates an empty dialog with the correct style properties set. The next step is to use ClassWizard to add control notification message handlers, command message handlers, and update command UI handlers. (The example steps starting after Figure 16-2 show you what to do.) You can also define data members and validation criteria.
Категории