Click here to Skip to main content
15,896,606 members
Articles / Desktop Programming / ATL

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.4K   668   24  
Introduce a programming technology to design a very complex, rich document type.
//*************************************************************
// ��Ȩ������
// ---------------
// ���ļ���TangramDeveloper����ϵͳ��һ����
// ��Ȩ���� (C) 2000-2002 TangramDeveloper Team��
//
// δ����ɣ���ϵͳ��Դ���벻�����κη�ʽ�޸ġ����û򷢲�
//*************************************************************
// ObjExtManager.cpp : implementation file
//

#include "stdafx.h"
#include "TangramComponentLib.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CRuntimeClass* g_pLibClass = NULL;
CTangramServerObj* g_pTangramServer=NULL;

void InitLib()
{
	AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
	g_pLibClass = pModuleState->m_classList;
};

void ConnectClsInfo()
{
	AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
	CRuntimeClass* pClass;
	AfxLockGlobals(CRIT_RUNTIMECLASSLIST);
	for (pClass = pModuleState->m_classList; pClass != NULL;
		pClass = pClass->m_pNextClass)
	{
		if(pClass->m_pNextClass==NULL)
		{
			if(g_pLibClass)
			{
				pClass->m_pNextClass = g_pLibClass;
				g_pLibClass = NULL;
				break;
			}
		}
	}
	AfxUnlockGlobals(CRIT_RUNTIMECLASSLIST);
};

/////////////////////////////////////////////////////////////////////////////

void CTangramManager::AddMfcObject(CRuntimeClass *pMfcObjInfo,CRuntimeClass *pMfcConnectObjInfo,CString strHeader)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
	//TRACE("AppName:%s\n\n",pModuleState->m_lpszCurrentAppName);
	CString strAppName = _T("");
	if(pModuleState->m_pCurrentWinApp)
		strAppName = pModuleState->m_pCurrentWinApp->m_pszExeName;
	else
		strAppName = pModuleState->m_lpszCurrentAppName;
	ASSERT(pMfcObjInfo);
	void* pObjInfo = NULL;

	CString strClsInfo = _T("");
	if(strAppName==_T(""))
		strClsInfo = pMfcObjInfo->m_lpszClassName;
	else
	{
		int nPos = -1;
		nPos = m_pTGObj->m_strCurExternCnn.Find(_T("."));
		CString str = m_pTGObj->m_strCurExternCnn.Left(nPos);
		if(str == _T(""))str = strHeader;
		strClsInfo.Format("%s.%s",str,pMfcObjInfo->m_lpszClassName);
	}
	strClsInfo.MakeLower();
	if(!m_pTGObj->m_MfcObjInfoDictionary.Lookup(LPCTSTR(strClsInfo),pObjInfo))
	{
		//TRACE("Current CnnString:%s\n",m_pTGObj->m_strCurExternCnn);
		if(!(m_pTGObj->m_strCurExternCnn==_T("")))
			m_pTGObj->m_MfcConnectExternalInfoDictionary[LPCTSTR(strClsInfo)] = m_pTGObj->m_strCurExternCnn;
		m_pTGObj->m_MfcObjInfoDictionary[strClsInfo] = pMfcObjInfo;
	}
}

HRESULT CTangramObject::getAPCName(BSTR* pVal)
{
	if(m_pApcDisp)
	{
		DISPID ObjectID;
		LPWSTR wszObject = OLESTR("Name");
		if (SUCCEEDED(m_pApcDisp->GetIDsOfNames(IID_NULL,&wszObject,1,LOCALE_NEUTRAL,&ObjectID))) 
		{
			DISPPARAMS dp = {NULL, NULL, 0, 0};
			VARIANT vRet;
			m_pApcDisp->Invoke(ObjectID,IID_NULL,LOCALE_NEUTRAL,DISPATCH_PROPERTYGET,&dp,&vRet,NULL,NULL);
			*pVal = vRet.bstrVal;
		}
	}
	return S_OK;
}

HRESULT CTangramObject::putAPCName(BSTR newName)
{
	if(m_pApcDisp)
	{
		BSTR szMember1=L"Name";
		DISPID dispid1;
		DISPPARAMS dispparams1;
		HRESULT hr = m_pApcDisp->GetIDsOfNames(IID_NULL, &szMember1, 1,	LOCALE_USER_DEFAULT, &dispid1);
		if(hr == S_OK)
		{
			DISPID dispidarg1=DISPID_PROPERTYPUT;
			VARIANTARG rgvarg1[1];
			dispparams1.cArgs=1;
			dispparams1.rgdispidNamedArgs=&dispidarg1;
			dispparams1.rgvarg=rgvarg1;
			dispparams1.rgvarg[0].vt=VT_BSTR;
			dispparams1.rgvarg[0].bstrVal=newName;
			dispparams1.cNamedArgs=1;
			hr = m_pApcDisp->Invoke(dispid1,	IID_NULL,LOCALE_USER_DEFAULT,DISPATCH_PROPERTYPUT, &dispparams1, NULL,NULL,	NULL);
		
			if(hr != S_OK)
			{
				m_pApcDisp->Release();
				return S_FALSE;
			}			
		}
	}
	return S_OK;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

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