Click here to Skip to main content
15,884,986 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.3K   668   24  
Introduce a programming technology to design a very complex, rich document type.
//*******************************************************************************
// COPYRIGHT NOTES
// ---------------
// This source code is a part of Tangram library.
// You may use, compile or redistribute it as part of your application 
// for free. You cannot redistribute it as a part of a software development 
// library without the agreement of the author. If the sources are 
// distributed along with the application, you should leave the original 
// copyright notes in the source code without any changes.
// This code can be used WITHOUT ANY WARRANTIES on your own risk.
// 
// For the latest updates to this library, check site:
// http://www.tangramdev.com
// 
// sunhui
//*******************************************************************************
// Documents.h : Declaration of the CDocuments

#ifndef __DOCUMENTS_H_
#define __DOCUMENTS_H_

#include "stdafx.h"
#include "resource.h"       // main symbols
class EnumDocuments;

/////////////////////////////////////////////////////////////////////////////
// CDocuments
class ATL_NO_VTABLE CDocuments : public CTangramDocuments,
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CDocuments, &CLSID_Documents>,
	public IDispatchImpl<IDocuments, &IID_IDocuments, &LIBID_VisualFrameWorkLib>
{
	friend class EnumDocuments;
public:
	STDMETHOD(Connect)(/*[in]*/long TangramServerObj);
	virtual void AddToCollection(CTangramDoc *pDoc);
	virtual void RemoveFromCollection(CTangramDoc *pDoc);
	CDocuments()
	{
	}
	~CDocuments()
	{
	}

DECLARE_REGISTRY_RESOURCEID(IDR_DOCUMENTS)
DECLARE_NOT_AGGREGATABLE(CDocuments)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CDocuments)
	COM_INTERFACE_ENTRY(IDocuments)
	COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()

	virtual void ClearCollection();
	HRESULT RemoveFromCollection(CString strName);
	HRESULT AddToCollection(IDocument* pDoc);

// IDocuments
	virtual int GetDocsCount();
	STDMETHOD(Add)(/*[out retval]*/IDocument** ppVal);
	STDMETHOD(Open)(/*[in]*/ BSTR FileName, /*[out, retval]*/ IDocument** ppVal);
	STDMETHOD(Item)(/*[in]*/ VARIANT Index, /*[out, retval]*/ IDocument** ppVal);
	STDMETHOD(get__NewEnum)(/*[out, retval]*/ IUnknown* *pVal);
	STDMETHOD(get_Count)(/*[out, retval]*/ long *pVal);

};

class EnumDocuments : public IEnumVARIANT
{
public:
	EnumDocuments(CDocuments* pDocs); //main constructor
	EnumDocuments(EnumDocuments* pEnum); //clone constructor

	//IUnknown methods
	STDMETHOD(QueryInterface)(REFIID riid, LPVOID* ppvObj);
	STDMETHOD_(ULONG, AddRef)() { return ++m_cRef; }
	STDMETHOD_(ULONG, Release)() { if (--m_cRef == 0) { delete this; return 0;} return m_cRef; }

	//IEnumVARIANT methods
	STDMETHOD(Next)(ULONG celt, VARIANT* rgvar, ULONG* celtFetched);
	STDMETHOD(Skip)(ULONG celt);
	STDMETHOD(Reset)();
	STDMETHOD(Clone)(IEnumVARIANT** ppenum);

private:
	ULONG m_cRef;
	CPtrList* m_plistDocs;
	POSITION m_posCur;
};
OBJECT_ENTRY_AUTO(__uuidof(Documents), CDocuments)

#endif //__DOCUMENTS_H_

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