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

📄 flowctrl.cpp

📁 一个工业控制管道流动控件,能够反映管道内流动情况.不是我写的,但觉得不错,因此转载上来
💻 CPP
字号:
/***********************************************************************
* Copyright (c) 2007* All rights reserved.* 
* ATTRIBUTE:        一个管道流动类,用来仿真工业控制现场显示等
* FILE NAME:		FlowCtrl.cpp
* FILE ID:			SYSTEMCTRL-FLOW-CPP
* ABSTRACT:			可用于工业控制显示等
* CURRENT VERSION:	V1.0
* AUTHOR:			戚高
* CONTECT:			successq_g@163.com	
* BUILD DATA:		27/12/2007
* COMPLETION DATE:	27/12/2007
* PRE-VERSION:		NONE
* PRE-AUTHOR:		NONE
* PRE-COMPLETION DATE:	
* NOTE:	            This source code can be used freely but without guarantee. 
					You are respon responsible for using the following codes
***********************************************************************/
#include "stdafx.h"
#include "FlowCtrl.h"

CFlowCtrl::CFlowCtrl()
{
	m_enumDirectionType = LEFT_TO_RIGHT;
	m_enumFlowPattern = FP_HORIZONTAL;
	m_pFlowImpl = new CFlowImpl(this);
	m_pPipeImpl = new CPipeImpl(this);
	m_colorBack = RGB( 128, 128, 0);
	m_bFlow = true;
}

CFlowCtrl::~CFlowCtrl()
{
	MemBitmap.DeleteObject();
	MemDC.DeleteDC(); 	
}


BEGIN_MESSAGE_MAP(CFlowCtrl, CStatic)
	//{{AFX_MSG_MAP(CFlowCtrl)
	ON_WM_ERASEBKGND()
	ON_WM_PAINT()
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

BOOL CFlowCtrl::OnEraseBkgnd(CDC* pDC) 
{
	return FALSE;
}

void CFlowCtrl::OnPaint() 
{
	CPaintDC dc(this); 

	//这里采用双缓冲绘图
	CRect m_rectClient;
	GetClientRect(&m_rectClient); 

	CFlowMemDC memDC(&dc, &m_rectClient);
	
	if (MemDC.GetSafeHdc() == NULL || MemBitmap.m_hObject == NULL)
	{
		MemDC.CreateCompatibleDC(&dc);
		MemBitmap.CreateCompatibleBitmap(&dc, m_rectClient.Width(), m_rectClient.Height());
		pOldBitmap = MemDC.SelectObject(&MemBitmap); 		
		
		//绘制管道背景
		m_pPipeImpl->Draw(&MemDC);
	}
	
	memDC.BitBlt(m_rectClient.left, m_rectClient.top, m_rectClient.Width(), m_rectClient.bottom,
				&MemDC, 0, 0, SRCCOPY);	

	//绘制小滑块
	if (m_bFlow)
	{
		m_pFlowImpl->Draw(&memDC);
	}
}

void CFlowCtrl::OnTimer(UINT nIDEvent) 
{
	if (nIDEvent == FLOW_TIMER)
	{
		m_pFlowImpl->CalculateFlowUnit();
	}

	Invalidate();

	CStatic::OnTimer(nIDEvent);
}

void CFlowCtrl::PreSubclassWindow() 
{
	CStatic::PreSubclassWindow();

	m_pFlowImpl->InitFlowUnit();
	m_pPipeImpl->InitGradient();

	SetTimer(FLOW_TIMER, 10, NULL);
}

void CFlowCtrl::SetDirectionType(const DIRECTIONTYPE enumDirectionType)
{
	DLINEPATTERN enumDLinePattern;

	switch (enumDirectionType)
	{
	case LEFT_TO_RIGHT:
		enumDLinePattern = DP_RIGHT;
		break;

	case RIGHT_TO_LEFT:
		enumDLinePattern = DP_LEFT;
		break;

	case TOP_TO_BOTTOM:
		enumDLinePattern = DP_DOWN;
		break;

	case BOTTOM_TO_TOP:
		enumDLinePattern = DP_UP;
		break;
	}

	m_enumDirectionType = enumDirectionType;
	m_pFlowImpl->SetUnitDLinePattern(enumDLinePattern);
	m_pFlowImpl->InitFlowUnit(); 
}

void CFlowCtrl::SetFlow(bool bFlow)
{
	m_bFlow = bFlow;
	Invalidate();
}

void CFlowCtrl::SetBorderColor(const COLORREF colorBorder)
{
	m_pPipeImpl->SetBorderColor(colorBorder);
}

void CFlowCtrl::SetCenterColor(const COLORREF colorCenter)
{
	m_pPipeImpl->SetCenterColor(colorCenter);
}

void CFlowCtrl::SetUnitBackColor(const COLORREF colorBack)
{
	m_pFlowImpl->SetUnitBackColor(colorBack);	
}

void CFlowCtrl::ReconstructControl()
{
	if ( pOldBitmap != NULL && MemBitmap.GetSafeHandle() && MemDC.GetSafeHdc())
	{
		MemDC.SelectObject(pOldBitmap);
		MemDC.DeleteDC() ;
		MemBitmap.DeleteObject();
	}

	Invalidate ();
}

void CFlowCtrl::SetPipeStyle(int nInterpolationMethod)
{
	m_pPipeImpl->SetPipeStyle((CGradient::InterpolationMethod)nInterpolationMethod);
}

⌨️ 快捷键说明

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