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

📄 switchctl.cpp

📁 VC写的用于电力行业的一个ActiveX控件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			pdc->MoveTo(pt1);
			pt.x=pt1.x-iWidth;
			pt.y=pt1.y+iHeight;
			pdc->LineTo(pt);

			pdc->MoveTo(pt1);
			pt.x=pt1.x+iWidth;
			pt.y=pt1.y-iHeight;
			pdc->LineTo(pt);

			//draw top's vetical line
			pdc->MoveTo(pt2);
			pt.x=pt2.x;
			pt.y=rc.top;
			pdc->LineTo(pt);

			//draw bottom's vetical line
			pdc->MoveTo(pt1);
			pt.x=pt1.x;
			pt.y=rc.bottom;
			pdc->LineTo(pt);

			//draw switch slanting line
			pdc->MoveTo(pt2);
			pdc->LineTo(pt3);
			break;
	}		
}

/*
void CSwitchCtrl::DrawSwitch3(CDC* pdc, const CRect& rc,short iSwitchType)
{
	short iAdjust,iRadius;
	POINT CenterPt;
	iAdjust=1;

	iRadius = min(rc.right-rc.left,rc.bottom-rc.top)/3;
	CenterPt.x = rc.right - iRadius-iAdjust; 
	CenterPt.y = rc.bottom - iRadius; 
	if(!m_bOnOff)
	{
		//draw bevel-edge
		pdc->MoveTo(rc.left,rc.top+(rc.bottom-rc.top)/4+m_lineSize/2); 
		pdc->LineTo(CenterPt.x,CenterPt.y); 
	}

	//draw the switch control's top line
	pdc->MoveTo(rc.left-(iAdjust*2)+(rc.right-rc.left)/3,rc.top+m_lineSize/2); 
	pdc->LineTo(rc.right,rc.top+m_lineSize/2); 

	if(m_bVerticalLine)
	{
		pdc->MoveTo(CenterPt.x,rc.top); 
		pdc->LineTo(CenterPt.x,CenterPt.y); 
	}

	pdc->Ellipse((CenterPt.x - iRadius), (CenterPt.y - iRadius), (CenterPt.x +iRadius),(CenterPt.y+ iRadius));

}
*/
/////////////////////////////////////////////////////////////////////////////
// CSwitchCtrl::OnDraw - Drawing function

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

	COLORREF colFill;
	OleTranslateColor(m_fillColor, NULL, &colFill);

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

	CPen forePen,*oldPen;
	forePen.CreatePen(PS_SOLID,m_lineSize,colFore);
	oldPen=pdc->SelectObject(&forePen);

	switch(m_iSwitchType)
	{
		case 1:
		case 2:
			DrawSwitch1(pdc, rc, m_iSwitchType);
			break;
		case 3:
		case 4:
			DrawSwitch2(pdc, rc, m_iSwitchType);
			break;
	}

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

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

	return 0;
}
LRESULT CSwitchCtrl::OnMyMessage102(WPARAM wParam, LPARAM lParam)
{
	// TODO: 处理用户自定义消息
	boolean bCustom;
	bCustom=(boolean)lParam;
	SetOnOff(bCustom);

	return 0;
}

/////////////////////////////////////////////////////////////////////////////
// CSwitchCtrl::DoPropExchange - Persistence support

void CSwitchCtrl::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);
	PX_Color(pPX,"FillColor",m_fillColor);
	PX_Bool(pPX,"OnOff",m_bOnOff);
//	PX_Bool(pPX,"VerticalLine",m_bVerticalLine);
	PX_Short(pPX,"SwitchType",m_iSwitchType);
}


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

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

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


/////////////////////////////////////////////////////////////////////////////
// CSwitchCtrl message handlers

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

	return m_backColor;
}

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

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

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

	return m_foreColor;
}

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

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

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

	return m_lineSize;
}

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

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

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

	return m_bImageHollow;
}

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

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

BOOL CSwitchCtrl::OnSetExtent(LPSIZEL lpSizeL) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	lpSizeL->cx=m_iControlWidth;
	lpSizeL->cy=m_iControlHeight;
	return COleControl::OnSetExtent(lpSizeL);
}

OLE_COLOR CSwitchCtrl::GetFillColor() 
{
	// TODO: Add your property handler here

	return m_fillColor;
}

void CSwitchCtrl::SetFillColor(OLE_COLOR nNewValue) 
{
	// TODO: Add your property handler here
	
	m_fillColor=nNewValue;
	SetModifiedFlag();
	InvalidateControl();
}

BOOL CSwitchCtrl::GetOnOff() 
{
	// TODO: Add your property handler here

	return m_bOnOff;
}

void CSwitchCtrl::SetOnOff(BOOL bNewValue) 
{
	// TODO: Add your property handler here
	
	m_bOnOff=bNewValue;
	SetModifiedFlag();
	InvalidateControl();
}
/*
BOOL CSwitchCtrl::GetVerticalLine() 
{
	// TODO: Add your property handler here

	return m_bVerticalLine;
}

void CSwitchCtrl::SetVerticalLine(BOOL bNewValue) 
{
	// TODO: Add your property handler here

	m_bVerticalLine=bNewValue;
	SetModifiedFlag();
	InvalidateControl();
}
*/
LRESULT CSwitchCtrl::OnMySetExtent(WPARAM wParam, LPARAM lParam) 
{ 
	// TODO: 处理用户自定义消息

	SIZEL SizeL;
	SizeL.cx=m_iControlWidth;
	SizeL.cy=m_iControlHeight;
	return OnSetExtent(&SizeL);
}

int CSwitchCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (COleControl::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	
	PostMessage(WM_MY_SETEXTENT,0,0);
	return 0;
}

short CSwitchCtrl::GetSwitchType() 
{
	// TODO: Add your property handler here

	return m_iSwitchType;
}

void CSwitchCtrl::SetSwitchType(short nNewValue) 
{
	// TODO: Add your property handler here

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

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