?? flowctrl.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 + -