⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 srvritem.cpp

📁 VisualC++实践与提高-ActiveX篇源码
💻 CPP
字号:
// SrvrItem.cpp : implementation of the CAxServerSrvrItem class
//

#include "stdafx.h"
#include "AxServer.h"

#include "AxServerDoc.h"
#include "SrvrItem.h"
#include <afxpriv.h>    // for CSharedFile

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAxServerSrvrItem implementation

IMPLEMENT_DYNAMIC(CAxServerSrvrItem, COleServerItem)

CAxServerSrvrItem::CAxServerSrvrItem(CAxServerDoc* pContainerDoc)
	: COleServerItem(pContainerDoc, TRUE)
{
	// TODO: add one-time construction code here
	//  (eg, adding additional clipboard formats to the item's data source)
}

CAxServerSrvrItem::~CAxServerSrvrItem()
{
	// TODO: add cleanup code here
}

void CAxServerSrvrItem::Serialize(CArchive& ar)
{
	// CAxServerSrvrItem::Serialize will be called by the framework if
	//  the item is copied to the clipboard.  This can happen automatically
	//  through the OLE callback OnGetClipboardData.  A good default for
	//  the embedded item is simply to delegate to the document's Serialize
	//  function.  If you support links, then you will want to serialize
	//  just a portion of the document.

	if (!IsLinkedItem())
	{
		CAxServerDoc* pDoc = GetDocument();
		ASSERT_VALID(pDoc);
		pDoc->Serialize(ar);
	}
}

BOOL CAxServerSrvrItem::OnGetExtent(DVASPECT dwDrawAspect, CSize& rSize)
{
	// Most applications, like this one, only handle drawing the content
	//  aspect of the item.  If you wish to support other aspects, such
	//  as DVASPECT_THUMBNAIL (by overriding OnDrawEx), then this
	//  implementation of OnGetExtent should be modified to handle the
	//  additional aspect(s).

	if (dwDrawAspect != DVASPECT_CONTENT)
		return COleServerItem::OnGetExtent(dwDrawAspect, rSize);

	// CAxServerSrvrItem::OnGetExtent is called to get the extent in
	//  HIMETRIC units of the entire item.  The default implementation
	//  here simply returns a hard-coded number of units.

	CAxServerDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	// TODO: replace this arbitrary size
	CClientDC dc(NULL);
	dc.SetMapMode(MM_ANISOTROPIC);
	rSize = CSize(120, 120);
	dc.LPtoHIMETRIC(&rSize);

	return TRUE;
}

BOOL CAxServerSrvrItem::OnDraw(CDC* pDC, CSize& rSize)
{
	CAxServerDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	// TODO: set mapping mode and extent
	//  (The extent is usually the same as the size returned from OnGetExtent)
	pDC->SetMapMode(MM_ANISOTROPIC);
	pDC->SetWindowOrg(0,0);
	pDC->SetWindowExt(120,120);
	// TODO: add drawing code here.  Optionally, fill in the HIMETRIC extent.
	//  All drawing takes place in the metafile device context (pDC).
	GetDocument()->Draw(pDC);
	return TRUE;
}

COleDataSource* CAxServerSrvrItem::OnGetClipboardData(BOOL bIncludeLink,
	LPPOINT pptOffset, LPSIZE pSize)
{
	ASSERT_VALID(this);

	COleDataSource* pDataSource = new COleDataSource;
	TRY
	{
		GetNativeClipboardData(pDataSource);
		GetClipboardData(pDataSource, bIncludeLink, pptOffset, pSize);
	}
	CATCH_ALL(e)
	{
		delete pDataSource;
		THROW_LAST();
	}
	END_CATCH_ALL

	ASSERT_VALID(pDataSource);
	return pDataSource;
}

void CAxServerSrvrItem::GetNativeClipboardData(COleDataSource *pDataSource)
{
	ASSERT_VALID(this);
	ASSERT(CAxServerDoc::m_cfPrivate != NULL);

	// Create a shared file and associate a CArchive with it
	CSharedFile file;
	CArchive ar(&file,CArchive::store);

	// Serialize selected objects to the archive
	GetDocument()->Serialize(ar);
	ar.Close();

	// put on local format instead of or in addation to
	pDataSource->CacheGlobalData(CAxServerDoc::m_cfPrivate,file.Detach());
}

/////////////////////////////////////////////////////////////////////////////
// CAxServerSrvrItem diagnostics

#ifdef _DEBUG
void CAxServerSrvrItem::AssertValid() const
{
	COleServerItem::AssertValid();
}

void CAxServerSrvrItem::Dump(CDumpContext& dc) const
{
	COleServerItem::Dump(dc);
}
#endif

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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -