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

📄 arrowctl.cpp

📁 VC写的一个箭头ActiveX控件
💻 CPP
字号:
// ArrowCtl.cpp : Implementation of the CArrowCtrl ActiveX Control class.

#include "stdafx.h"
#include "arrow.h"
#include "ArrowCtl.h"
#include "ArrowPpg.h"


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


IMPLEMENT_DYNCREATE(CArrowCtrl, COleControl)


/////////////////////////////////////////////////////////////////////////////
// Message map

BEGIN_MESSAGE_MAP(CArrowCtrl, COleControl)
	//{{AFX_MSG_MAP(CArrowCtrl)
	// NOTE - ClassWizard will add and remove message map entries
	//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_MSG_MAP
	ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
	ON_MESSAGE(WM_MY_MESSAGE101, OnMyMessage101)
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// Dispatch map

BEGIN_DISPATCH_MAP(CArrowCtrl, COleControl)
	//{{AFX_DISPATCH_MAP(CArrowCtrl)
	DISP_PROPERTY_EX(CArrowCtrl, "BackColor", GetBackColor, SetBackColor, VT_COLOR)
	DISP_PROPERTY_EX(CArrowCtrl, "ForeColor", GetForeColor, SetForeColor, VT_COLOR)
	DISP_PROPERTY_EX(CArrowCtrl, "ArrowStyle", GetArrowStyle, SetArrowStyle, VT_I2)
	DISP_PROPERTY_EX(CArrowCtrl, "ImageHollow", GetImageHollow, SetImageHollow, VT_BOOL)
	DISP_PROPERTY_EX(CArrowCtrl, "LineSize", GetLineSize, SetLineSize, VT_I2)
	DISP_STOCKPROP_TEXT()
	//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()


/////////////////////////////////////////////////////////////////////////////
// Event map

BEGIN_EVENT_MAP(CArrowCtrl, COleControl)
	//{{AFX_EVENT_MAP(CArrowCtrl)
	// NOTE - ClassWizard will add and remove event map entries
	//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_EVENT_MAP
END_EVENT_MAP()


/////////////////////////////////////////////////////////////////////////////
// Property pages

// TODO: Add more property pages as needed.  Remember to increase the count!
BEGIN_PROPPAGEIDS(CArrowCtrl, 1)
	PROPPAGEID(CArrowPropPage::guid)
END_PROPPAGEIDS(CArrowCtrl)


/////////////////////////////////////////////////////////////////////////////
// Initialize class factory and guid

IMPLEMENT_OLECREATE_EX(CArrowCtrl, "ARROW.ArrowCtrl.1",
	0x6ae79b89, 0x4496, 0x4cbc, 0x9d, 0x1a, 0x3d, 0x33, 0x52, 0x9a, 0xec, 0x4)


/////////////////////////////////////////////////////////////////////////////
// Type library ID and version

IMPLEMENT_OLETYPELIB(CArrowCtrl, _tlid, _wVerMajor, _wVerMinor)


/////////////////////////////////////////////////////////////////////////////
// Interface IDs

const IID BASED_CODE IID_DArrow =
		{ 0xa98df514, 0x7360, 0x4717, { 0xb0, 0xeb, 0, 0xbf, 0xee, 0xb4, 0xa4, 0x25 } };
const IID BASED_CODE IID_DArrowEvents =
		{ 0x663ea94d, 0x96b8, 0x4c82, { 0xb3, 0xa7, 0x21, 0x69, 0xa5, 0x34, 0x7e, 0x9d } };


/////////////////////////////////////////////////////////////////////////////
// Control type information

static const DWORD BASED_CODE _dwArrowOleMisc =
	OLEMISC_ACTIVATEWHENVISIBLE |
	OLEMISC_SETCLIENTSITEFIRST |
	OLEMISC_INSIDEOUT |
	OLEMISC_CANTLINKINSIDE |
	OLEMISC_RECOMPOSEONRESIZE;

IMPLEMENT_OLECTLTYPE(CArrowCtrl, IDS_ARROW, _dwArrowOleMisc)


/////////////////////////////////////////////////////////////////////////////
// CArrowCtrl::CArrowCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CArrowCtrl

BOOL CArrowCtrl::CArrowCtrlFactory::UpdateRegistry(BOOL bRegister)
{
	// TODO: Verify that your control follows apartment-model threading rules.
	// Refer to MFC TechNote 64 for more information.
	// If your control does not conform to the apartment-model rules, then
	// you must modify the code below, changing the 6th parameter from
	// afxRegApartmentThreading to 0.

	if (bRegister)
		return AfxOleRegisterControlClass(
			AfxGetInstanceHandle(),
			m_clsid,
			m_lpszProgID,
			IDS_ARROW,
			IDB_ARROW,
			afxRegApartmentThreading,
			_dwArrowOleMisc,
			_tlid,
			_wVerMajor,
			_wVerMinor);
	else
		return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}


/////////////////////////////////////////////////////////////////////////////
// CArrowCtrl::CArrowCtrl - Constructor

CArrowCtrl::CArrowCtrl()
{
	InitializeIIDs(&IID_DArrow, &IID_DArrowEvents);

	// TODO: Initialize your control's instance data here.
	m_foreColor = RGB(255,255,0);
	m_backColor = RGB(255,255,255);
	m_arrowStyle= 1;  //top arrow
	m_bImageHollow =false;
	m_lineSize =1;
}


/////////////////////////////////////////////////////////////////////////////
// CArrowCtrl::~CArrowCtrl - Destructor

CArrowCtrl::~CArrowCtrl()
{
	// TODO: Cleanup your control's instance data here.
}


/////////////////////////////////////////////////////////////////////////////
// CArrowCtrl::OnDraw - Drawing function

void CArrowCtrl::OnDraw(
			CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
	// TODO: Replace the following code with your own drawing code.
	CRect rc;
	rc = rcBounds;
	CBrush bkBrush,*oldBrush;
	bkBrush.CreateSolidBrush(m_backColor);
	oldBrush=pdc->SelectObject(&bkBrush);
	pdc->FillRect(&rc,&bkBrush);
	pdc->SelectObject(&oldBrush);
	bkBrush.DeleteObject();

	POINT vertex[3];
	switch(m_arrowStyle)
	{
		case 1:   //top arrow
			vertex[0].x=rc.left;
			vertex[0].y=rc.bottom;
			vertex[1].x=rc.left+(rc.right-rc.left)/2;
			vertex[1].y=rc.top;
			vertex[2].x=rc.right;
			vertex[2].y=rc.bottom;
			break;
		case 2:   //bottom arrow
			vertex[0].x=rc.left;
			vertex[0].y=rc.top;
			vertex[1].x=rc.left+(rc.right-rc.left)/2;
			vertex[1].y=rc.bottom;
			vertex[2].x=rc.right;
			vertex[2].y=rc.top;
			break;
		case 3:   //left arrow
			vertex[0].x=rc.right;
			vertex[0].y=rc.top;
			vertex[1].x=rc.left;
			vertex[1].y=rc.top+(rc.bottom-rc.top)/2;
			vertex[2].x=rc.right;
			vertex[2].y=rc.bottom;
			break;
		case 4:   //right arrow
			vertex[0].x=rc.left;
			vertex[0].y=rc.top;
			vertex[1].x=rc.right;
			vertex[1].y=rc.top+(rc.bottom-rc.top)/2;
			vertex[2].x=rc.left;
			vertex[2].y=rc.bottom;
			break;
	}
	CBrush bkBrush2,*oldBrush2;
	if(m_bImageHollow)
	{
		bkBrush2.CreateStockObject(NULL_BRUSH);
	}
	else
	{
		bkBrush2.CreateSolidBrush(m_foreColor);
	}
	oldBrush2=pdc->SelectObject(&bkBrush2);

	CPen forePen;
	forePen.CreatePen(PS_SOLID,m_lineSize,m_foreColor);
	pdc->SelectObject(&forePen);
	
	pdc->Polygon(vertex,3); 
	
	pdc->SelectObject(oldBrush2);
	bkBrush2.DeleteObject();
	forePen.DeleteObject();
}

LRESULT CArrowCtrl::OnMyMessage101(WPARAM wParam, LPARAM lParam)
{
	// TODO: 处理用户自定义消息
	COLORREF colCustom;
	colCustom=(COLORREF)lParam;
	SetForeColor(colCustom);

	return 0;
}

/////////////////////////////////////////////////////////////////////////////
// CArrowCtrl::DoPropExchange - Persistence support

void CArrowCtrl::DoPropExchange(CPropExchange* pPX)
{
	ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
	COleControl::DoPropExchange(pPX);

	// TODO: Call PX_ functions for each persistent custom property.
	PX_Color(pPX,"BackColor",m_backColor);
	PX_Color(pPX,"ForeColor",m_foreColor);
	PX_Short(pPX,"ArrowStyle",m_arrowStyle);
	PX_Bool(pPX,"ImageHollow",m_bImageHollow);
	PX_Short(pPX,"LineSize",m_lineSize);
}


/////////////////////////////////////////////////////////////////////////////
// CArrowCtrl::OnResetState - Reset control to default state

void CArrowCtrl::OnResetState()
{
	COleControl::OnResetState();  // Resets defaults found in DoPropExchange

	// TODO: Reset any other control state here.
}


/////////////////////////////////////////////////////////////////////////////
// CArrowCtrl message handlers

OLE_COLOR CArrowCtrl::GetBackColor() 
{
	// TODO: Add your property handler here

	return m_backColor;
}

void CArrowCtrl::SetBackColor(OLE_COLOR nNewValue) 
{
	// TODO: Add your property handler here

	m_backColor=nNewValue;
	SetModifiedFlag();
	InvalidateControl();
}

OLE_COLOR CArrowCtrl::GetForeColor() 
{
	// TODO: Add your property handler here

	return m_foreColor;
}

void CArrowCtrl::SetForeColor(OLE_COLOR nNewValue) 
{
	// TODO: Add your property handler here
	
	m_foreColor=nNewValue;
	SetModifiedFlag();
	InvalidateControl();
}

short CArrowCtrl::GetArrowStyle() 
{
	// TODO: Add your property handler here

	return m_arrowStyle;
}

void CArrowCtrl::SetArrowStyle(short nNewValue) 
{
	// TODO: Add your property handler here
	
	m_arrowStyle=nNewValue; 
	SetModifiedFlag();
	InvalidateControl();
}

BOOL CArrowCtrl::GetImageHollow() 
{
	// TODO: Add your property handler here

	return m_bImageHollow;
}

void CArrowCtrl::SetImageHollow(BOOL bNewValue) 
{
	// TODO: Add your property handler here
	
	m_bImageHollow=bNewValue;
	SetModifiedFlag();
	InvalidateControl();
}

short CArrowCtrl::GetLineSize() 
{
	// TODO: Add your property handler here

	return m_lineSize;
}

void CArrowCtrl::SetLineSize(short nNewValue) 
{
	// TODO: Add your property handler here
	
	m_lineSize=nNewValue;
	SetModifiedFlag();
	InvalidateControl();
}

BOOL CArrowCtrl::PreCreateWindow(CREATESTRUCT& cs) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	return COleControl::PreCreateWindow(cs);
}

⌨️ 快捷键说明

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