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?
- You must compile the lib objmanager.lib.
- Set correct include path in VS.NET environment in order to compile other projects correctly.
- Compile the project VisualFrameWork and link with objmanager.lib.
- Compile the project MfcViewLib.
- Compile the project VbComLib.
- Compile the project VCSharpComLib.
- Compile the project prjVBDoc in folder VBDoc.
- Compile the project PrjCnn in folder CNN.
- Run the project VisualFrameWork.
- 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.
(Design Interface: create a view in library MfcViewLib.dll)
(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).
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:
Dim WithEvents ThisDoc As VisualFrameWorkLib.Document
Dim WithEvents xForm1 As prjVBDoc.ud
Dim WithEvents xForm2 As MfcViewLibLib.AtlView3
Public Property Let TangramDoc(ByVal vNewValue As Object)
Set ThisDoc = vNewValue
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.
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.
If you want to get a new version of objmanger, please visit our website here.