multiboardctl.cpp

来自「MULTI BORAD 控制」· C++ 代码 · 共 654 行 · 第 1/2 页

CPP
654
字号
// MultiBoardCtl.cpp : Implementation of the CMultiBoardCtrl ActiveX Control class.

#include "stdafx.h"
#include "MultiBoard.h"
#include "MultiBoardCtl.h"
#include "MultiBoardPpg.h"
#include "DCMemory.h"

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


IMPLEMENT_DYNCREATE(CMultiBoardCtrl, COleControl)


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

BEGIN_MESSAGE_MAP(CMultiBoardCtrl, COleControl)
	//{{AFX_MSG_MAP(CMultiBoardCtrl)
	ON_WM_MOUSEMOVE()
	ON_WM_LBUTTONDOWN()
	ON_WM_RBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_RBUTTONUP()
	ON_WM_SIZE()
	ON_WM_KILLFOCUS()
	ON_WM_DESTROY()
	ON_WM_CREATE()
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
	ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()


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

BEGIN_DISPATCH_MAP(CMultiBoardCtrl, COleControl)
	//{{AFX_DISPATCH_MAP(CMultiBoardCtrl)
	DISP_PROPERTY_NOTIFY(CMultiBoardCtrl, "colorBackground", m_colorBackground, OnColorBackgroundChanged, VT_COLOR)
	DISP_PROPERTY_NOTIFY(CMultiBoardCtrl, "MarginLeft", m_marginLeft, OnMarginLeftChanged, VT_I2)
	DISP_PROPERTY_NOTIFY(CMultiBoardCtrl, "MarginTop", m_marginTop, OnMarginTopChanged, VT_I2)
	DISP_PROPERTY_NOTIFY(CMultiBoardCtrl, "MarginBottom", m_marginBottom, OnMarginBottomChanged, VT_I2)
	DISP_PROPERTY_NOTIFY(CMultiBoardCtrl, "ReshInst", m_reshInst, OnReshInstChanged, VT_HANDLE)
	DISP_FUNCTION(CMultiBoardCtrl, "SetBoardNum", SetBoardNum, VT_EMPTY, VTS_I2)
	DISP_FUNCTION(CMultiBoardCtrl, "GetBoardNum", GetBoardNum, VT_I2, VTS_NONE)
	DISP_FUNCTION(CMultiBoardCtrl, "SetBoardWidth", SetBoardWidth, VT_EMPTY, VTS_I2)
	DISP_FUNCTION(CMultiBoardCtrl, "GetBoardWidth", GetBoardWidth, VT_I2, VTS_NONE)
	DISP_FUNCTION(CMultiBoardCtrl, "SetSpace", SetSpace, VT_EMPTY, VTS_I2)
	DISP_FUNCTION(CMultiBoardCtrl, "GetSpace", GetSpace, VT_I2, VTS_NONE)
	DISP_FUNCTION(CMultiBoardCtrl, "SetBoardText", SetBoardText, VT_EMPTY, VTS_I2 VTS_BSTR)
	DISP_FUNCTION(CMultiBoardCtrl, "SetBoardIcon", SetBoardIcon, VT_EMPTY, VTS_I2 VTS_I2)
	DISP_FUNCTION(CMultiBoardCtrl, "SetBoardIconWidth", SetBoardIconWidth, VT_EMPTY, VTS_I2)
	DISP_FUNCTION(CMultiBoardCtrl, "GetBaordIconWidth", GetBaordIconWidth, VT_I2, VTS_NONE)
	DISP_FUNCTION(CMultiBoardCtrl, "GetBoardIconHeight", GetBoardIconHeight, VT_I2, VTS_NONE)
	DISP_FUNCTION(CMultiBoardCtrl, "SetBoardIconHeight", SetBoardIconHeight, VT_EMPTY, VTS_I2)
	DISP_FUNCTION(CMultiBoardCtrl, "SetBoardCircle", SetBoardCircle, VT_EMPTY, VTS_I2 VTS_COLOR)
	DISP_FUNCTION(CMultiBoardCtrl, "GetBoardCircle", GetBoardCircle, VT_COLOR, VTS_I2)
	DISP_FUNCTION(CMultiBoardCtrl, "GetBoardState", GetBoardState, VT_I2, VTS_I2)
	DISP_FUNCTION(CMultiBoardCtrl, "SetBoardState", SetBoardState, VT_EMPTY, VTS_I2 VTS_I2)
	DISP_FUNCTION(CMultiBoardCtrl, "GetBoardIconID", GetBoardIconID, VT_I2, VTS_I2)
	DISP_FUNCTION(CMultiBoardCtrl, "GetBoardText", GetBoardText, VT_BSTR, VTS_I2)
	//}}AFX_DISPATCH_MAP
	DISP_FUNCTION_ID(CMultiBoardCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()


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

BEGIN_EVENT_MAP(CMultiBoardCtrl, COleControl)
	//{{AFX_EVENT_MAP(CMultiBoardCtrl)
	EVENT_CUSTOM("BoardLClick", FireBoardLClick, VTS_I4  VTS_I2  VTS_XPOS_PIXELS  VTS_YPOS_PIXELS)
	EVENT_CUSTOM("BoardMouseMove", FireBoardMouseMove, VTS_I4  VTS_I2  VTS_XPOS_PIXELS  VTS_YPOS_PIXELS)
	//}}AFX_EVENT_MAP
END_EVENT_MAP()


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

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


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

IMPLEMENT_OLECREATE_EX(CMultiBoardCtrl, "MULTIBOARD.MultiBoardCtrl.1",
	0xfddc99cc, 0x39fd, 0x4790, 0x90, 0xc3, 0xbe, 0x62, 0x8f, 0x23, 0x4c, 0x59)


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

IMPLEMENT_OLETYPELIB(CMultiBoardCtrl, _tlid, _wVerMajor, _wVerMinor)


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

const IID BASED_CODE IID_DMultiBoard =
		{ 0x9aa2ff9, 0x43fe, 0x4a03, { 0x87, 0x4d, 0xe4, 0x43, 0x3f, 0xff, 0xeb, 0x1b } };
const IID BASED_CODE IID_DMultiBoardEvents =
		{ 0x9350ab71, 0xa9ca, 0x491a, { 0x9e, 0xb4, 0x4d, 0xce, 0x2f, 0xef, 0xb, 0xef } };


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

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

IMPLEMENT_OLECTLTYPE(CMultiBoardCtrl, IDS_MULTIBOARD, _dwMultiBoardOleMisc)


/////////////////////////////////////////////////////////////////////////////
// CMultiBoardCtrl::CMultiBoardCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CMultiBoardCtrl

BOOL CMultiBoardCtrl::CMultiBoardCtrlFactory::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_MULTIBOARD,
			IDB_MULTIBOARD,
			afxRegApartmentThreading,
			_dwMultiBoardOleMisc,
			_tlid,
			_wVerMajor,
			_wVerMinor);
	else
		return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}


/////////////////////////////////////////////////////////////////////////////
// CMultiBoardCtrl::CMultiBoardCtrl - Constructor

CMultiBoardCtrl::CMultiBoardCtrl()
{
	InitializeIIDs(&IID_DMultiBoard, &IID_DMultiBoardEvents);

	EnableSimpleFrame();
	// TODO: Initialize your control's instance data here.
	m_colorBackground = ::GetSysColor(COLOR_3DSHADOW);// ::GetSysColor(COLOR_3DFACE);
	m_marginLeft =3;
	m_marginTop =3;
	m_marginBottom = 3;
	m_iBoardNum = 0;	
	m_iBoardWidth = 30;
	m_iSpace = 5;
	m_iBoardIconWidth = 16;
	m_iBoardIconHeight = 16;
	m_bSelBoard = FALSE;
	m_iSelBoardID = -1;
	m_pSingleBoard = NULL;
	if( m_iBoardNum > 0 )
		m_pSingleBoard = new CSingleBoard[m_iBoardNum];
	m_reshInst = (UINT)AfxGetResourceHandle();
}


/////////////////////////////////////////////////////////////////////////////
// CMultiBoardCtrl::~CMultiBoardCtrl - Destructor

CMultiBoardCtrl::~CMultiBoardCtrl()
{
	if(m_pSingleBoard != NULL)
	{
		delete [] m_pSingleBoard;
		m_pSingleBoard = NULL;
	}
}


/////////////////////////////////////////////////////////////////////////////
// CMultiBoardCtrl::OnDraw - Drawing function

void CMultiBoardCtrl::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(LTGRAY_BRUSH)));

//	pdc->FillSolidRect(rcBounds,m_colorBackground);
//	pdc->DrawEdge((LPRECT)&rcBounds,BDR_SUNKENOUTER,BF_RECT);
//	CDCMemory *pDCMem = new CDCMemory(pdc,rcBounds);
//	pDCMem->FillSolidRect(rcBounds,m_colorBackground);
//	pDCMem->DrawEdge((LPRECT)&rcBounds,BDR_SUNKENOUTER,BF_RECT);	
//	Display(pDCMem);
//	if(pDCMem != NULL) delete pDCMem;
}


/////////////////////////////////////////////////////////////////////////////
// CMultiBoardCtrl::DoPropExchange - Persistence support

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

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

}


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

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

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


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

void CMultiBoardCtrl::AboutBox()
{
	CDialog dlgAbout(IDD_ABOUTBOX_MULTIBOARD);
	dlgAbout.DoModal();
}


/////////////////////////////////////////////////////////////////////////////
// CMultiBoardCtrl message handlers

void CMultiBoardCtrl::OnMouseMove(UINT nFlags, CPoint point) 
{
	int nSelBoardID  = -1 ;
	nSelBoardID= HitTestEx(point,nSelBoardID);	
	FireBoardMouseMove((UINT)nFlags,nSelBoardID,point.x,point.y);
	COleControl::OnMouseMove(nFlags, point);
}

void CMultiBoardCtrl::OnLButtonDown(UINT nFlags, CPoint point) 
{
	int nSelBoardID  = -1 ;
	nSelBoardID= HitTestEx(point,nSelBoardID);

	if(m_iSelBoardID != nSelBoardID)
	{
		m_bSelBoard = TRUE;
	}
	else
	{
		m_bSelBoard = !m_bSelBoard;
	}
	
	m_iSelBoardID = nSelBoardID;
	
	Invalidate();	
	
	FireBoardLClick((UINT)nFlags,m_iSelBoardID,point.x,point.y);
	
	COleControl::OnLButtonDown(nFlags, point);
}

void CMultiBoardCtrl::OnLButtonUp(UINT nFlags, CPoint point) 
{
	
	COleControl::OnLButtonUp(nFlags, point);
}

void CMultiBoardCtrl::OnRButtonDown(UINT nFlags, CPoint point) 
{	
	COleControl::OnRButtonDown(nFlags, point);
}

void CMultiBoardCtrl::OnRButtonUp(UINT nFlags, CPoint point) 
{
		
	COleControl::OnRButtonUp(nFlags, point);
}

void CMultiBoardCtrl::SetBoardNum(short nBoardNum) 
{
	if((nBoardNum < 0) || (nBoardNum >= 32767) || (m_iBoardNum == nBoardNum))return;
	if(nBoardNum == 0)
	{
		if(m_pSingleBoard != NULL){
			delete []m_pSingleBoard;
			m_pSingleBoard = NULL;
		}
		m_iBoardNum = nBoardNum;
		Invalidate();
		return;
	}

	CSingleBoard *p =NULL;
	p = new CSingleBoard[nBoardNum];
	
	int i = 0;
	if(m_iBoardNum < nBoardNum)
	{	
		for(i = 0; i < m_iBoardNum ; i++)
		{
			p[i] = m_pSingleBoard[i]; 
		}		
	}
	else if(m_iBoardNum > nBoardNum)
	{

⌨️ 快捷键说明

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