Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
SSW_8_11.doc
Скачиваний:
2
Добавлен:
01.05.2025
Размер:
5 Мб
Скачать
☆

8. The concept of Document view

8.1 Introduction to document conception

On standard, earlier considered way to MFC, there are really created two basic objects – the object of application and the object of window. In such programs the dates and the scheme of their representation are closely linked. Often of all, the data field is described inside the window creation class, also there are noticed how they must be displayed. This way isn’t always desirable, because in many cases the different representation of the same dates is required. For example, often it’s required to display dates and after to print them on printer. The main point, that dates in Windows programs are conceptually separated from the kind of their representation. But in architecture of application creation both the ideas are mixed.

The other way is defined in architecture of documents creation. The dates are separated from its representation (i.e. document or view). The dates are encapsulated to the class of document creation. The class of view also permits to control the data input from the user.

In the programs of such architectures the object of document is originated from CDocument, the object of View – from CView. To speak the truth, there are also created the classes of main window and application (with decreased role, as CView overlays CFrameWnd).

The Document is a data block to work with the program. The applications can be build on the base of interface with SDI (single document interface) and MDI (multi-document interface). Microsoft urgently recommends to use SDI.

The View corresponds to the view of document and contains the physical representation of dates. That displaying is ambiguous (example – the different formats of representation of time). Also, on printing there is other view region.

It is said, that the Document is “clear” dates, the View is specific kind of their representation.

The control of documents storing

The MFC-classes permits to automate the documents storing in the files on disk. That process is called serialization. CDocument class supports standard operations such as creating a document, loading it, and saving it. The framework manipulates documents using the interface defined by CDocument.

8.2 The dynamic creation of objects

In programs to work with documents all the objects are dynamic. So, they are originated in the process of program execution, they are loaded and re-originated. This process is provided by special macro commands:

DECLARE_DYNCREATE( class_name )

IMPLEMENT_DYNCREATE( class_name, base_class_name )

Parameters

class_name   The actual name of the class (not enclosed in quotation marks).

base_class_name   The actual name of the base class (not enclosed in quotation marks).

Use the DECLARE_DYNCREATE macro to enable objects of CObject-derived classes to be created dynamically at run time. The framework uses this ability to create new objects dynamically, for example, when it reads an object from disk during serialization. Document, view, and frame classes should support dynamic creation because the framework needs to create them dynamically.

Use the IMPLEMENT_DYNCREATE macro with the DECLARE_DYNCREATE macro to enable objects of CObject-derived classes to be created dynamically at run time. The framework uses this ability to create new objects dynamically, for example, when it reads an object from disk during serialization. Add the IMPLEMENT_DYNCREATE macro in the class implementation file. For more information, see CObject Class Topics in Visual C++ Programmer's Guide.

If you use the DECLARE_DYNCREATE and IMPLEMENT_DYNCREATE macros, you can then use the RUNTIME_CLASS macro and the CObject::IsKindOf member function to determine the class of your objects at run time.

If DECLARE_DYNCREATE is included in the class declaration, then IMPLEMENT_DYNCREATE must be included in the class implementation.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]