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

📄 axcircle.cpp

📁 vc++ acticex原代码
💻 CPP
字号:
// AxCircle.cpp : implementation file
//

#include "stdafx.h"
#include "MfcAASvr.h"
#include "AxCircle.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAxCircle

IMPLEMENT_DYNCREATE(CAxCircle, CCmdTarget)

CAxCircle::CAxCircle()
{
	EnableAutomation();
	
	// To keep the application running as long as an OLE automation 
	//	object is active, the constructor calls AfxOleLockApp.
	m_iRadius=0;
	m_iRed=0;
	m_iGreen=0;
	m_iBlue=0;
	
	AfxOleLockApp();
}

CAxCircle::~CAxCircle()
{
	// To terminate the application when all objects created with
	// 	with OLE automation, the destructor calls AfxOleUnlockApp.
	
	AfxOleUnlockApp();
}


void CAxCircle::OnFinalRelease()
{
	// When the last reference for an automation object is released
	// OnFinalRelease is called.  The base class will automatically
	// deletes the object.  Add additional cleanup required for your
	// object before calling the base class.

	CCmdTarget::OnFinalRelease();
}


BEGIN_MESSAGE_MAP(CAxCircle, CCmdTarget)
	//{{AFX_MSG_MAP(CAxCircle)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

BEGIN_DISPATCH_MAP(CAxCircle, CCmdTarget)
	//{{AFX_DISPATCH_MAP(CAxCircle)
	DISP_PROPERTY_EX(CAxCircle, "Radius", GetRadius, SetRadius, VT_I4)
	DISP_PROPERTY_EX(CAxCircle, "Red", GetRed, SetRed, VT_I2)
	DISP_PROPERTY_EX(CAxCircle, "Green", GetGreen, SetGreen, VT_I2)
	DISP_PROPERTY_EX(CAxCircle, "Blue", GetBlue, SetBlue, VT_I2)
	DISP_FUNCTION(CAxCircle, "DrawCircle", DrawCircle, VT_EMPTY, VTS_I4)
	//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()

// Note: we add support for IID_IAxCircle to support typesafe binding
//  from VBA.  This IID must match the GUID that is attached to the 
//  dispinterface in the .ODL file.

// {0D9C9261-5E70-11D4-A54D-0050BADB14A3}
static const IID IID_IAxCircle =
{ 0xd9c9261, 0x5e70, 0x11d4, { 0xa5, 0x4d, 0x0, 0x50, 0xba, 0xdb, 0x14, 0xa3 } };

BEGIN_INTERFACE_MAP(CAxCircle, CCmdTarget)
	INTERFACE_PART(CAxCircle, IID_IAxCircle, Dispatch)
END_INTERFACE_MAP()

// {0D9C9262-5E70-11D4-A54D-0050BADB14A3}
IMPLEMENT_OLECREATE(CAxCircle, "MfcAASvr.AxCircle", 0xd9c9262, 0x5e70, 0x11d4, 0xa5, 0x4d, 0x0, 0x50, 0xba, 0xdb, 0x14, 0xa3)

/////////////////////////////////////////////////////////////////////////////
// CAxCircle message handlers


long CAxCircle::GetRadius() 
{
	// TODO: Add your property handler here

	return m_iRadius;
}

void CAxCircle::SetRadius(long nNewValue) 
{
	// TODO: Add your property handler here
	m_iRadius=nNewValue;
}

short CAxCircle::GetRed() 
{
	// TODO: Add your property handler here

	return m_iRed;
}

void CAxCircle::SetRed(short nNewValue) 
{
	// TODO: Add your property handler here
	m_iRed=nNewValue;
}

short CAxCircle::GetGreen() 
{
	// TODO: Add your property handler here

	return m_iGreen;
}

void CAxCircle::SetGreen(short nNewValue) 
{
	// TODO: Add your property handler here
	m_iGreen=nNewValue;
}

short CAxCircle::GetBlue() 
{
	// TODO: Add your property handler here

	return m_iBlue;
}

void CAxCircle::SetBlue(short nNewValue) 
{
	// TODO: Add your property handler here
	m_iBlue=nNewValue;
}

void CAxCircle::DrawCircle(long lDC) 
{
	// TODO: Add your dispatch handler code here
	if(lDC==0)
		return;

	//	强制转换DC
	CDC* pDC=(CDC*)lDC;
	//	得到绘制区域大小
	CRect rect;
	pDC->GetWindow()->GetWindowRect(&rect);

	//	先清除绘制区域
	rect=CRect(0,0,rect.Width(),rect.Height());
	pDC->Rectangle(&rect);

	//	根据圆的颜色设置画笔
	CBrush brush(RGB(m_iRed,m_iGreen,m_iBlue));
	CBrush* pOldBrush=pDC->SelectObject(&brush);

	//	根据圆的半径设置包容矩形
	rect=CRect(rect.Width()/2-m_iRadius,rect.Height()/2-m_iRadius,
		rect.Width()/2+m_iRadius,rect.Height()/2+m_iRadius);
	
	//	绘制圆
	pDC->Ellipse(rect);

	pDC->SelectObject(pOldBrush);
}

⌨️ 快捷键说明

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