Thursday, March 8, 2007

MFC Architecture





The MFC Architecture is sub-divided into the above three.

So in SDI we will get only one window at a time and in MDI we get one or more window at a time.

A window here is called document.

The document-view application architecture in MFC includes

  1. An application object,------------------------------------------
  2. A frame window,------------------------------------------------

MainFrm.h and MainFrm.cpp

  1. A document object (or several), and--------------------------

Diagram.h, Diagram.cpp DiagramDoc.h, and DiagramDoc.cpp

  1. One or more view objects for each document.--------------

DiagramView.h and DiagramView.cpp.

1) An application object

The Application Object is derived from the Application Class CWinApp. CWinApp is derived from CWinThread, which represents the main thread of execution for your application, which might have one or more threads.

This is solely responsible for initialization, running, and termination of an application for the Windows operating system.

If your application creates separate threads of execution — for example, to perform calculations in the background — you'll use classes derived from CWinThread. CWinApp itself is derived from CWinThread and represents the primary thread of execution (or the main process) in your application. You can also use MFC in secondary threads.

2) A frame window

Views are displayed inside "document frame windows." In an SDI application, the document frame window is also the "main frame window" for the application. In an MDI application, document windows are child windows displayed inside a main frame window. Your derived main frame-window class specifies the styles and other characteristics of the frame windows that contain your views. If you need to customize frame windows, derive from CFrameWnd to customize the document frame window for SDI applications. Derive from CMDIFrameWnd to customize the main frame window for MDI applications. Also derive a class from CMDIChildWnd to customize each distinct kind of MDI document frame windows that your application supports.

3) A document object

Your document class (derived from CDocument) specifies your application's data. If you want OLE functionality in your application, derive your document class from COleDocument or one of its derived classes, depending on the type of functionality you need.

4) View objects

Your view class (derived from CView) is the user's "window on the data." The view class controls how the user sees your document's data and interacts with it. In some cases, you may want a document to have multiple views of the data.

If you need scrolling, derive from CScrollView. If your view has a user interface that is laid out in a dialog-template resource, derive from CFormView. For simple text data, use or derive from CEditView. For a form-based data-access application, such as a data-entry program, derive from CRecordView (for ODBC). Also available are classes CTreeView, CListView, and CRichEditView.

The document template or templates

A document template orchestrates the creation of documents, views, and frame windows. A particular document-template class, derived from class CDocTemplate, creates and manages all open documents of one type. Applications that support more than one type of document have multiple document templates. Use class CSingleDocTemplate for SDI applications, or use class CMultiDocTemplate for MDI applications.

The document object and the view objects are connected with a document template.

Frame Windows

When an application runs under Microsoft Windows, the user interacts with documents displayed in frame windows. A document frame window has two major components: the frame and the contents that it frames. A document frame window can be a single document interface (SDI) frame window or a multiple document interface (MDI) child window. Windows manages most of the user's interaction with the frame window: moving and resizing the window, closing it, and minimizing and maximizing it. You manage the contents inside the frame.

The Full Picture

The white space in the middle is called client area. And all the other parts the border; menu, toolbar etc are termed as non-client area.

Ø The Frame Window is the non-client area.

Ø The view object is the client area and contains the displays the user needs

Ø The document object stores the data the user needs. That is what the view object makes use of.

Ø The Application Object is needed to launch this application. (Derived from Thread Class).

Ø And a Document template is needed to communicate between view and document objects

Ø A thread is used to open many instances of an application.

No comments:

Post a Comment