Introduction
In a MFC Application, it is very difficult to use dynamic view which exists in a mfc dll library at runtime, because such a view object may be has nothing to do with this application or this view is created after this application be created. If some application can create view dynamic, it certainly can be extended infinitely. If you use Tangram SDK (you can get it free from http://www.tangramdev.com/english/downloads.asp), you can create such kind of application easily.
Steps:
- First, You must install Tangram SDK
- Create a Tangram Application use wizard�Tangram Application�. (Please reference:http://www.codeproject.com/useritems/Tangram_class_library.asp).
- Create a Tangram Component Dll use Wizard �Tangram component Dll�.
- I will give you a simple example. Add a new class for this component Dll. Use wizard �Tangram component� to add a new class.
- For get value I add an edit control and a button for the new component. Then map a variable for the edit control.
- Add an event for this component to transfer values. Open class �TangramDllLeftLib�, right click �_IAtlLeftEvents�, select option �Add�, the click �Add Method�, and select type �BSTR� in the parameter type, fill �str� into parameter name, then click button �add�.
- Next, compile idl file �TangramDllLeft.idl�, and add connection point on class �CAtlLeft� (Right Click class �CAtlLeft�, select option �Add�, then select sub option �Add connection point�. Then dbClick �_IAtlLeftEvents� make it to the right side.)
- After adding an event, the next step is active this event. DbClick �Button1� in the recourse view. And add the codes below:
UpdateData(TRUE);
m_pComObj->Fire_ShowText(m_strEdit.AllocSysString());
Remark: �m_pComObj� is a pointer variable point to class �CAtlLeft�.
Then when you click �button1�, this event will be active and the value from edit control will send our.
- Use step 3~4 to create an new Tangram component Dll. Only add an edit control, and map a variable for this edit control.
- Add a method for this component to get the value. Right click class �IAtlRight�, select option �Add�, then select sub option �Add method�.
- Open class �CAtlRight�, DbClick method �AddText�. Delete the code �AFX_MANAGE_STATE(AfxGetStaticModuleState());� and add the following codes:
m_pMfcWnd->m_strEditR=strText;
m_pMfcWnd->UpdateData(FALSE);
Remark: m_pMfcWnd is a pointer variable point to class �CRightView�.
- Add the two components to Tangram. Build and Run �Tangram Application�.
- Open a new document, click �Design�. Input �1� row and �2� columns in the splitter Tab pane, and click �CreateSplitter� button. Then you will see this document divided into two part.
- Click �Design� which is in the left side, fill the tangram component Dll project name and class name �TangramDllLeft.CLeftView� into the ComWnd tab pane. In the same way, fill another tangram Component Dll �TangramDllRight.CRightView� int the com wnd which is in the right side window. And then click button �Create COM Window�.
- After that, you will see the figure like below.
- Interface each other. Open �Tool� in the menu bar, and click option �Visual Basic� to the VBA Code interface. Add the following codes in the CleftView object.
CRightView.AddText(str)
- Save the change, and close VBA interface. Switch to the document, fill some words in the edit control which is on the left side. And Click �button1�. You will see the words you input appear in the edit control which is on the right side.