Click here to Skip to main content
15,881,757 members
Articles / Desktop Programming / ATL
Article

Create a Universal Document Template which supports Dynamic Frame Window Layout

Rate me:
Please Sign up or sign in to vote.
3.00/5 (8 votes)
14 Dec 20024 min read 49.2K   668   24   2
Introduce a programming technology to design a very complex, rich document type.

Sample Image - VisualFrameWork1.png

Introduction

The most important characteristic of MFC class library is the mechanism of implementing Document-View architecture. When you create an application that is based on document by the MFC Document-View mechanism, you may face the following questions:

  • The Document type support by an MFC application is limited by the collection of document template. Generally, one MFC application can only support finite document templates.
  • One MFC application usually includes finite "MFC View" classes.
  • For the reason of it has only finite "MFC View" classes, one MFC program can only support limited types of windows layout, and implementing a frame window layout usually needs to write very complex C++ code.
  • User usually cannot add or extend a new View class that is supported by the application, and the user or developer cannot add new frame window layout other than application inner support after this application is compiled.
  • It is difficult for the user to extend codes.
  • It is very difficult to share "MFC View" for the different applications.

ObjManager is a MFC library which is used to implement a universal document template in order to overcome the restriction of lack of document template. In general, one document template can have only one document class, one child frame window and some views, it is very difficult to implement multiple document layouts for one document template using C++ code. Commonly, to implement different document layouts, you must override frame window's OnCreateClient class member function and you have to write hard C++ code. It is a good idea to abstract document layout from document structure and to implement a 'Design Model' for a document model. A typical document layout commonly consists of some splitters, some views, and some tab like windows. It is possible to implement a design mechanism for a document layout with a visual manner (no C++ coding), and it is possible to implement multiple document layouts for a special document type and save corresponding layout information data into corresponding document, and can restore it when the user opens it. For detail technology information, please reference ObjManager library (it includes complete source code).

How to create a MFC framework application which contains a universal document type and supports multiple document layouts?

The sample project includes all source code, please download it and compile it.

How to use MFC CView Dynamically in VisualFrameWork?

Please reference the implementation of class CAtlForm and class TestFormView.

How to create a DLL library which contains MFC Views and can be used in a shared manner in MFC Application like "VisualFrameWork"?

Please reference the Sample project MfcViewLib.

How to use the source code?

  1. You must compile the lib objmanager.lib.
  2. Set correct include path in VS.NET environment in order to compile other projects correctly.
  3. Compile the project VisualFrameWork and link with objmanager.lib.
  4. Compile the project MfcViewLib.
  5. Compile the project VbComLib.
  6. Compile the project VCSharpComLib.
  7. Compile the project prjVBDoc in folder VBDoc.
  8. Compile the project PrjCnn in folder CNN.
  9. Run the project VisualFrameWork.
  10. Open documents "Demo1", "Demo2" and "Demo3" in folder DemoDoc.

How to insert Component (MFC View, ActiveX Ctrl, ActiveX Document and .NET Component)?

In designer, please input object ID into ComWndID: if you want to create ActiveX Ctrl, ActiveX Document or .NET Control, please input correct corresponding object Class ID. For example, if you want to create VB ListView control (offered by Visual Basic 6), you need to input "mscomctllib.listviewctrl". If you want to create MFC View existing in a DLL like mfcviewlib.dll, you input its "library name" + "." + "Class Name", for example, if you want to create the view CShareFormview1, your input is "mfcviewlib.cshareformview1". If you want to create a view in host application, you just input the C++ class name as object ID. After you input object ID, click button Create COM Window.

Sample Image - VisualFrameWork2.png

(Design Interface: create a view in library MfcViewLib.dll)

Sample Image - VisualFrameWork3.png

(create a view named "TestFormView" in host application)

How to make inserted components interact with each other?

You can control these components out of the application. You can use any programming language to deal with the interaction of these components. You only have to reference the objects the application needs to anther project; and connect it to the application. For example, I have a VB project named PrjVBDoc.UD. And I have a MFC view named CShareFormview3. For the rules above, insert these two objects to the application. The important part of the interaction is filling an object name after filling the COMWinID. That is the interface of interaction, and the object name must be unified with the interface name (I will introduce later).

Sample Image - VisualFrameWork3.png

After inserting these two objects, you can open a VB Active DLL project. Reference "PrjVBDoc", "VisualFrameWork1.0" and "MFCViewLibLib 1.0 Type Library" to this project. And add the following code to the class:

VB
'Reference the document of application.
Dim WithEvents ThisDoc As VisualFrameWorkLib.Document

'Reference VB project
Dim WithEvents xForm1 As prjVBDoc.ud

'Reference MFC View.
Dim WithEvents xForm2 As MfcViewLibLib.AtlView3

Public Property Let TangramDoc(ByVal vNewValue As Object)
Set ThisDoc = vNewValue
'ObjectName must be unified with the object name you input in the designer.
    Set xForm1 = ThisDoc.ObjectX("Form1")
    Set xForm2 = ThisDoc.ObjectX("Form2")
End Property

Private Sub xForm1_ShowText(ByVal str As String)
    xForm2.GetText str
End Sub

Compile this project, and switch to the main interface. Find "DocProperty" in View option of the menu bar. Fill the VB DLL name in the "Document Object ID:" text box.

Sample Image - VisualFrameWork3.png

Save the change, you will find when you're filling some words in the textbox created by VB and clicking button "Command1", the words you input will appear in the right side edit control that was created by MFC view.

Sample Image - VisualFrameWork3.png

If you want to get a new version of objmanger, please visit our website here.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Generalusing MFC controls Pin
dostoyevsky19-Nov-07 6:13
dostoyevsky19-Nov-07 6:13 
GeneralTangram again.... Pin
wayward15-Dec-02 3:37
wayward15-Dec-02 3:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.