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

📄 celineargaugectl.cpp

📁 一个标尺控件
💻 CPP
字号:
// CELinearGaugeCtl.cpp : Implementation of the CCELinearGaugeCtrl ActiveX Control class.

#include "stdafx.h"
#include "CELinearGauge.h"
#include "CELinearGaugeCtl.h"
#include "CELinearGaugePpg.h"

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


IMPLEMENT_DYNCREATE(CCELinearGaugeCtrl, COleControl)


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

BEGIN_MESSAGE_MAP(CCELinearGaugeCtrl, COleControl)
	//{{AFX_MSG_MAP(CCELinearGaugeCtrl)
	// 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)
END_MESSAGE_MAP()


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

BEGIN_DISPATCH_MAP(CCELinearGaugeCtrl, COleControl)
	//{{AFX_DISPATCH_MAP(CCELinearGaugeCtrl)
	DISP_FUNCTION(CCELinearGaugeCtrl, "SetCount", SetCount, VT_I4, VTS_I4)
	DISP_FUNCTION(CCELinearGaugeCtrl, "SetCountEx", SetCountEx, VT_I4, VTS_I4 VTS_I4)
	DISP_FUNCTION(CCELinearGaugeCtrl, "SetCellStyle", SetCellStyle, VT_I4, VTS_I4 VTS_I4 VTS_I4 VTS_I4)
	DISP_FUNCTION(CCELinearGaugeCtrl, "SetCellStyleEx", SetCellStyleEx, VT_I4, VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4)
	DISP_FUNCTION(CCELinearGaugeCtrl, "SetCellFrame", SetCellFrame, VT_I4, VTS_I4 VTS_COLOR VTS_COLOR)
	DISP_FUNCTION(CCELinearGaugeCtrl, "SetCellFrameEx", SetCellFrameEx, VT_I4, VTS_I4 VTS_I4 VTS_COLOR VTS_COLOR)
	DISP_FUNCTION(CCELinearGaugeCtrl, "SetCellRulerEx", SetCellRulerEx, VT_I4, VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_COLOR VTS_COLOR VTS_COLOR)
	DISP_FUNCTION(CCELinearGaugeCtrl, "SetCellValueCount", SetCellValueCount, VT_I4, VTS_I4 VTS_I4)
	DISP_FUNCTION(CCELinearGaugeCtrl, "SetCellValueCountEx", SetCellValueCountEx, VT_I4, VTS_I4 VTS_I4 VTS_I2)
	DISP_FUNCTION(CCELinearGaugeCtrl, "SetCellValueFrame", SetCellValueFrame, VT_I4, VTS_I4 VTS_I4 VTS_COLOR VTS_COLOR VTS_R8)
	DISP_FUNCTION(CCELinearGaugeCtrl, "SetCellValueFrameEx", SetCellValueFrameEx, VT_I4, VTS_I4 VTS_I4 VTS_I4 VTS_COLOR VTS_COLOR VTS_R8)
	DISP_FUNCTION(CCELinearGaugeCtrl, "SetCellRuler", SetCellRuler, VT_I4, VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_COLOR VTS_COLOR VTS_COLOR)
	//}}AFX_DISPATCH_MAP
	DISP_FUNCTION_ID(CCELinearGaugeCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()


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

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


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

IMPLEMENT_OLECREATE_EX(CCELinearGaugeCtrl, "CELINEARGAUGE.CELinearGaugeCtrl.1",
	0x13f7501f, 0xf240, 0x45bf, 0xb0, 0x82, 0xe0, 0x96, 0x2f, 0x4f, 0xbb, 0xb3)


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

IMPLEMENT_OLETYPELIB(CCELinearGaugeCtrl, _tlid, _wVerMajor, _wVerMinor)


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

const IID BASED_CODE IID_DCELinearGauge =
		{ 0x3313bcd5, 0xd23c, 0x4b5a, { 0x99, 0xa, 0xd4, 0x57, 0x46, 0x4f, 0x52, 0xce } };
const IID BASED_CODE IID_DCELinearGaugeEvents =
		{ 0x96864045, 0x8115, 0x43f8, { 0xaa, 0x19, 0x9c, 0x21, 0xab, 0xc3, 0xc2, 0x7f } };


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

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

IMPLEMENT_OLECTLTYPE(CCELinearGaugeCtrl, IDS_CELINEARGAUGE, _dwCELinearGaugeOleMisc)


/////////////////////////////////////////////////////////////////////////////
// CCELinearGaugeCtrl::CCELinearGaugeCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CCELinearGaugeCtrl

BOOL CCELinearGaugeCtrl::CCELinearGaugeCtrlFactory::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_CELINEARGAUGE,
			IDB_CELINEARGAUGE,
			afxRegApartmentThreading,
			_dwCELinearGaugeOleMisc,
			_tlid,
			_wVerMajor,
			_wVerMinor);
	else
		return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}


/////////////////////////////////////////////////////////////////////////////
// CCELinearGaugeCtrl::CCELinearGaugeCtrl - Constructor

CCELinearGaugeCtrl::CCELinearGaugeCtrl()
{
	InitializeIIDs(&IID_DCELinearGauge, &IID_DCELinearGaugeEvents);

	// TODO: Initialize your control's instance data here.
}


/////////////////////////////////////////////////////////////////////////////
// CCELinearGaugeCtrl::~CCELinearGaugeCtrl - Destructor

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


/////////////////////////////////////////////////////////////////////////////
// CCELinearGaugeCtrl::OnDraw - Drawing function

void CCELinearGaugeCtrl::OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
	// TODO: Replace the following code with your own drawing code.
	pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
	//pdc->Ellipse(rcBounds);
	m_LinearGauges.m_rect=rcBounds;
	m_LinearGauges.Draw(pdc->m_hDC); 
}


/////////////////////////////////////////////////////////////////////////////
// CCELinearGaugeCtrl::DoPropExchange - Persistence support

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

	// TODO: Call PX_ functions for each persistent custom property.

}


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

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

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


/////////////////////////////////////////////////////////////////////////////
// CCELinearGaugeCtrl::AboutBox - Display an "About" box to the user

void CCELinearGaugeCtrl::AboutBox()
{
	CDialog dlgAbout(IDD_ABOUTBOX_CELINEARGAUGE);
	dlgAbout.DoModal();
}


/////////////////////////////////////////////////////////////////////////////
// CCELinearGaugeCtrl message handlers

long CCELinearGaugeCtrl::SetCount(long count) 
{
	

	return 0;
}

long CCELinearGaugeCtrl::SetCountEx(long row, long col) 
{
	if(row<=0) return -1;
	if(col<=0) return -1;

	m_LinearGauges.SetGrid(row,col); 

	InvalidateControl ();
	return 0;
}

long CCELinearGaugeCtrl::SetCellStyle(long index, long style, long orientation, long rulerStyle) 
{
	if(index < 0) return -1;
	if(index > m_LinearGauges.m_arrayCellLinearGauge.GetSize()-1) return -1;

	m_LinearGauges.m_arrayCellLinearGauge[index].SetStyle(style,orientation,rulerStyle);  

	InvalidateControl ();
	return 0;
}

long CCELinearGaugeCtrl::SetCellStyleEx(long row, long col, long style, long orientation, long rulerstyle) 
{	
	return SetCellStyle(row * col,style,orientation,rulerstyle);
}

long CCELinearGaugeCtrl::SetCellFrame(long index, OLE_COLOR frameColor, OLE_COLOR bkColor) 
{
	if(index < 0) return -1;
	if(index > m_LinearGauges.m_arrayCellLinearGauge.GetSize()-1) return -1;

	m_LinearGauges.m_arrayCellLinearGauge[index].SetFrame(TranslateColor(frameColor),TranslateColor(bkColor));  

	InvalidateControl ();
	return 0;
}

long CCELinearGaugeCtrl::SetCellFrameEx(long row, long col, OLE_COLOR frameColor, OLE_COLOR bkColor) 
{
	return SetCellFrame(row*col,frameColor,bkColor);
}

long CCELinearGaugeCtrl::SetCellRuler(long index, long max, long min, long majortics, long minortics, OLE_COLOR majorticsColor, OLE_COLOR minorticsColor, OLE_COLOR rulerFontColor) 
{
	if(index < 0) return -1;
	if(index > m_LinearGauges.m_arrayCellLinearGauge.GetSize()-1) return -1;

	m_LinearGauges.m_arrayCellLinearGauge[index].SetRuler(max,min,majortics,minortics,majorticsColor,minorticsColor,rulerFontColor); 

	InvalidateControl ();
	return 0;
}

long CCELinearGaugeCtrl::SetCellRulerEx(long row, long col, long max, long min, long majortics, long minortics, OLE_COLOR majorticsColor, OLE_COLOR minorticsColor, OLE_COLOR rulerFontColor) 
{
	return SetCellRuler(row*col,max,min,majortics,minortics,majorticsColor,minorticsColor,rulerFontColor);
}

long CCELinearGaugeCtrl::SetCellValueCount(long index, long Count) 
{
	if(index < 0) return -1;
	if(index > m_LinearGauges.m_arrayCellLinearGauge.GetSize()-1) return -1;
	if(Count < 0) return -1;

	m_LinearGauges.m_arrayCellLinearGauge[index].SetValueCount(Count); 

	InvalidateControl ();
	return 0;
}

long CCELinearGaugeCtrl::SetCellValueCountEx(long row, long col, long count) 
{
	
	return SetCellValueCount(row*col,count);
}

long CCELinearGaugeCtrl::SetCellValueFrame(long index, long valueIndex, OLE_COLOR valueframeColor, OLE_COLOR valuebkColor, double value) 
{
	if(index < 0) return -1;
	if(index > m_LinearGauges.m_arrayCellLinearGauge.GetSize()-1) return -1;
	if(valueIndex < m_LinearGauges.m_arrayCellLinearGauge[index].GetValueCount()) return -1; 

	m_LinearGauges.m_arrayCellLinearGauge[index].SetValueFrame(valueIndex,valueframeColor,valuebkColor,value); 

	InvalidateControl ();
	return 0;
}

long CCELinearGaugeCtrl::SetCellValueFrameEx(long row, long col, long valueIndex, OLE_COLOR valueframeColor, OLE_COLOR valuebkColor, double value) 
{

	return SetCellValueFrame(row*col,valueIndex, valueframeColor, valuebkColor, value );
}

⌨️ 快捷键说明

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