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

📄 groundingctl.cpp

📁 VC写的ActiveX控件源码
💻 CPP
字号:
// GroundingCtl.cpp : Implementation of the CGroundingCtrl ActiveX Control class.

#include "stdafx.h"
#include "grounding.h"
#include "GroundingCtl.h"
#include "GroundingPpg.h"


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


IMPLEMENT_DYNCREATE(CGroundingCtrl, COleControl)


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

BEGIN_MESSAGE_MAP(CGroundingCtrl, COleControl)
	//{{AFX_MSG_MAP(CGroundingCtrl)
	// 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(CGroundingCtrl, COleControl)
	//{{AFX_DISPATCH_MAP(CGroundingCtrl)
	DISP_PROPERTY_EX(CGroundingCtrl, "BackColor", GetBackColor, SetBackColor, VT_COLOR)
	DISP_PROPERTY_EX(CGroundingCtrl, "ForeColor", GetForeColor, SetForeColor, VT_COLOR)
	DISP_PROPERTY_EX(CGroundingCtrl, "ImageHollow", GetImageHollow, SetImageHollow, VT_BOOL)
	DISP_PROPERTY_EX(CGroundingCtrl, "LineSize", GetLineSize, SetLineSize, VT_I2)
	DISP_STOCKPROP_TEXT()
	//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()


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

BEGIN_EVENT_MAP(CGroundingCtrl, COleControl)
	//{{AFX_EVENT_MAP(CGroundingCtrl)
	// 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(CGroundingCtrl, 1)
	PROPPAGEID(CGroundingPropPage::guid)
END_PROPPAGEIDS(CGroundingCtrl)


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

IMPLEMENT_OLECREATE_EX(CGroundingCtrl, "GROUNDING.GroundingCtrl.1",
	0x81b02568, 0xd002, 0x4f27, 0x83, 0x7d, 0x41, 0xb7, 0xc2, 0x1, 0x6a, 0x2b)


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

IMPLEMENT_OLETYPELIB(CGroundingCtrl, _tlid, _wVerMajor, _wVerMinor)


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

const IID BASED_CODE IID_DGrounding =
		{ 0x49ef4d76, 0x2acb, 0x4ebc, { 0x83, 0x20, 0xdb, 0xa4, 0x1e, 0xf4, 0xa2, 0x34 } };
const IID BASED_CODE IID_DGroundingEvents =
		{ 0x806515c2, 0x29c3, 0x4753, { 0x82, 0x3c, 0xb4, 0xb5, 0xb5, 0xed, 0xb9, 0x91 } };


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

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

IMPLEMENT_OLECTLTYPE(CGroundingCtrl, IDS_GROUNDING, _dwGroundingOleMisc)


/////////////////////////////////////////////////////////////////////////////
// CGroundingCtrl::CGroundingCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CGroundingCtrl

BOOL CGroundingCtrl::CGroundingCtrlFactory::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_GROUNDING,
			IDB_GROUNDING,
			afxRegApartmentThreading,
			_dwGroundingOleMisc,
			_tlid,
			_wVerMajor,
			_wVerMinor);
	else
		return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}


/////////////////////////////////////////////////////////////////////////////
// CGroundingCtrl::CGroundingCtrl - Constructor

CGroundingCtrl::CGroundingCtrl()
{
	InitializeIIDs(&IID_DGrounding, &IID_DGroundingEvents);

	// TODO: Initialize your control's instance data here.
	m_foreColor = RGB(0,0,0);
	m_backColor = RGB(255,255,255);
	m_bImageHollow =TRUE;
	m_lineSize =2;
}


/////////////////////////////////////////////////////////////////////////////
// CGroundingCtrl::~CGroundingCtrl - Destructor

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


/////////////////////////////////////////////////////////////////////////////
// CGroundingCtrl::OnDraw - Drawing function

void CGroundingCtrl::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;
	COLORREF colBack,colFore;

	OleTranslateColor(m_backColor, NULL, &colBack);
	bkBrush.CreateSolidBrush(colBack);
	oldBrush=pdc->SelectObject(&bkBrush);
	pdc->FillRect(&rc,&bkBrush);
	pdc->SelectObject(&oldBrush);
	bkBrush.DeleteObject();

	OleTranslateColor(m_foreColor, NULL, &colFore);
	CBrush bkBrush2,*oldBrush2;
	if(m_bImageHollow)
	{
		bkBrush2.CreateStockObject(NULL_BRUSH);
	}
	else
	{
		bkBrush2.CreateSolidBrush(colFore);
	}
	oldBrush2=pdc->SelectObject(&bkBrush2);

	CPen forePen,*oldPen=NULL;
	forePen.CreatePen(PS_SOLID,m_lineSize,colFore);
	oldPen=pdc->SelectObject(&forePen);
	
	POINT pt;
	double dVal,dVal2;
	short iWidth;
	short iHeight;


	dVal2=0.4;
	iHeight=(int)(rc.Height() * dVal2);

	pt.x = rc.left + rc.Width()/2;
	pt.y = rc.top + iHeight;
	pdc->MoveTo(pt);
	pt.x = rc.left + rc.Width()/2;
	pt.y = rc.top;
	pdc->LineTo(pt);

	dVal=1.0;
	dVal2=0.4;
	iWidth=(rc.Width() - (int)(rc.Width() * dVal))/2; 
	iHeight=(int)(rc.Height() * dVal2);

	pt.x = rc.left + iWidth;
	pt.y = rc.top + iHeight;
	pdc->MoveTo(pt);
	pt.x = rc.right - iWidth;
	pt.y = rc.top + iHeight;
	pdc->LineTo(pt);

	dVal=0.7;
	dVal2=0.6;
	iWidth=(rc.Width() - (int)(rc.Width() * dVal))/2; 
	iHeight=(int)(rc.Height() * dVal2);

	pt.x = rc.left + iWidth;
	pt.y = rc.top + iHeight;
	pdc->MoveTo(pt);
	pt.x = rc.right - iWidth;
	pt.y = rc.top + iHeight;
	pdc->LineTo(pt);

	dVal=0.3;
	dVal2=0.8;
	iWidth=(rc.Width() - (int)(rc.Width() * dVal))/2; 
	iHeight=(int)(rc.Height() * dVal2);

	pt.x = rc.left + iWidth;
	pt.y = rc.top + iHeight;
	pdc->MoveTo(pt);
	pt.x = rc.right - iWidth;
	pt.y = rc.top + iHeight;
	pdc->LineTo(pt);

	pdc->SelectObject(oldBrush2);
	bkBrush2.DeleteObject();
	pdc->SelectObject(oldPen); 
	forePen.DeleteObject();
}

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

	return 0;
}

/////////////////////////////////////////////////////////////////////////////
// CGroundingCtrl::DoPropExchange - Persistence support

void CGroundingCtrl::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_Bool(pPX,"ImageHollow",m_bImageHollow);
	PX_Short(pPX,"LineSize",m_lineSize);
}


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

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

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


/////////////////////////////////////////////////////////////////////////////
// CGroundingCtrl message handlers

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

	return m_backColor;
}

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

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

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

	return m_foreColor;
}

void CGroundingCtrl::SetForeColor(OLE_COLOR nNewValue) 
{
	// TODO: Add your property handler here

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

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

	return m_bImageHollow;
}

void CGroundingCtrl::SetImageHollow(BOOL bNewValue) 
{
	// TODO: Add your property handler here

	m_bImageHollow=bNewValue;
	SetModifiedFlag();
	InvalidateControl();
}

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

	return m_lineSize;
}

void CGroundingCtrl::SetLineSize(short nNewValue) 
{
	// TODO: Add your property handler here

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

BOOL CGroundingCtrl::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 + -