📄 curveframe.cpp
字号:
// CurveFrame.cpp : implementation file
//
#include "stdafx.h"
#include "CurveFrame.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCurveFrame
CCurveFrame::CCurveFrame()
{
m_rectOffset.left = 50;
m_rectOffset.top = 20;
m_rectOffset.right = 20;
m_rectOffset.bottom = 40;
m_clrBkGround = RGB(0, 0, 0);
m_clrGridLine = RGB(26, 73, 20);
m_clrGridBoldLine = RGB(55, 158, 44);
m_clrGridXCoord = RGB(255, 0, 0);
m_clrCurve[0] = RGB(255,255,255);
m_clrCurve[1] = RGB(0,255,0);
m_clrCurve[2] = RGB(0,255,255);
for (int i=0; i<3; i++)
{
m_bChannelFlag[i] = FALSE;
m_nWidth[i] = 1;
}
m_fVerScale = 1.0;
m_nHorScale = 100;
}
CCurveFrame::~CCurveFrame()
{
}
BEGIN_MESSAGE_MAP(CCurveFrame, CStatic)
//{{AFX_MSG_MAP(CCurveFrame)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
/*
函数介绍: 根据lpRect设置绘图区的新位置
输入参数: LPCRECT lpRect
输出参数: 无
返回值 : 无
*/
/////////////////////////////////////////////////////////////////////////////
void CCurveFrame::SetCurvePos(LPCRECT lpRect)
{
MoveWindow(lpRect);
}
/////////////////////////////////////////////////////////////////////////////
/*
函数介绍: 绘制整个图形显示区的波形,以及坐标轴,坐标文字
输入参数: 无
输出参数: 无
返回值 : 无
*/
/////////////////////////////////////////////////////////////////////////////
void CCurveFrame::DrawCurve(double data0[1024], int num0,
double data1[1024], int num1,
double data2[1024], int num2,
double FreqencySample)
{
CDC *pDC = GetDC();//设备上下文指针
m_memDCClient.BitBlt(0,0,m_rectClientArea.Width(), m_rectClientArea.Height(), &m_memDC,m_rectOffset.left,m_rectOffset.top,SRCCOPY);
if (m_bChannelFlag[0] == TRUE || m_bChannelFlag[1] == TRUE ||
m_bChannelFlag[2] == TRUE)
{
for (int i=0; i<3; i++)
{
if(m_bChannelFlag[i])
{
if (i == 0)
DrawCurveDetail(&m_memDCClient,&m_rectClientArea, m_clrCurve[i], m_nWidth[i], data0, num0, FreqencySample);
else if(i == 1)
DrawCurveDetail(&m_memDCClient,&m_rectClientArea, m_clrCurve[i], m_nWidth[i], data1, num1, FreqencySample);
else
DrawCurveDetail(&m_memDCClient,&m_rectClientArea, m_clrCurve[i], m_nWidth[i], data2, num2, FreqencySample);
}
}
}
m_memDCCur.BitBlt(m_rectOffset.left,m_rectOffset.top,m_rectClientArea.Width(), m_rectClientArea.Height(), &m_memDCClient,0,0,SRCCOPY);
pDC->BitBlt(0,0,m_rectBkArea.Width(), m_rectBkArea.Height(), &m_memDCCur,0,0,SRCCOPY);
ReleaseDC(pDC);
}
/////////////////////////////////////////////////////////////////////////////
/*
函数介绍: 绘制图形显示区的,有立体感的背景,并填充波信显示区的背景
输入参数: CDC *pDC,
LPCRECT lpRect
输出参数: 无
返回值 : 无
*/
/////////////////////////////////////////////////////////////////////////////
void CCurveFrame::DrawBkGround(CDC *pDC, LPCRECT lpRect)
{
CPen penTop[2];//顶边线
CPen penLeft[9];//左边线
CPen penRight[14];//右边线
penTop[0].CreatePen(PS_SOLID, 1, RGB(208, 208, 208));
penTop[1].CreatePen(PS_SOLID, 1, RGB(203, 203, 203));
penLeft[0].CreatePen(PS_SOLID, 1, RGB(204, 204, 204));
penLeft[1].CreatePen(PS_SOLID, 1, RGB(208, 208, 208));
penLeft[2].CreatePen(PS_SOLID, 1, RGB(211, 211, 211));
penLeft[3].CreatePen(PS_SOLID, 1, RGB(211, 211, 211));
penLeft[4].CreatePen(PS_SOLID, 1, RGB(211, 211, 211));
penLeft[5].CreatePen(PS_SOLID, 1, RGB(210, 210, 210));
penLeft[6].CreatePen(PS_SOLID, 1, RGB(207, 207, 207));
penLeft[7].CreatePen(PS_SOLID, 1, RGB(203, 203, 203));
penLeft[8].CreatePen(PS_SOLID, 1, RGB(196, 196, 196));
penRight[0].CreatePen(PS_SOLID, 1, RGB(64, 64, 64));
penRight[1].CreatePen(PS_SOLID, 1, RGB(112, 112, 112));
penRight[2].CreatePen(PS_SOLID, 1, RGB(130, 130, 130));
penRight[3].CreatePen(PS_SOLID, 1, RGB(139, 139, 139));
penRight[4].CreatePen(PS_SOLID, 1, RGB(147, 147, 147));
penRight[5].CreatePen(PS_SOLID, 1, RGB(153, 153, 153));
penRight[6].CreatePen(PS_SOLID, 1, RGB(157, 157, 157));
penRight[7].CreatePen(PS_SOLID, 1, RGB(162, 162, 162));
penRight[8].CreatePen(PS_SOLID, 1, RGB(166, 166, 166));
penRight[9].CreatePen(PS_SOLID, 1, RGB(170, 170, 170));
penRight[10].CreatePen(PS_SOLID, 1, RGB(174, 174, 174));
penRight[11].CreatePen(PS_SOLID, 1, RGB(179, 179, 179));
penRight[12].CreatePen(PS_SOLID, 1, RGB(184, 184, 184));
penRight[13].CreatePen(PS_SOLID, 1, RGB(189, 189, 189));
//绘制上面的两根线
CPen *pOldPen = pDC->SelectObject(&penTop[0]);
pDC->MoveTo(lpRect->left, lpRect->top);
pDC->LineTo(lpRect->right-3,lpRect->top);
pDC->SelectObject(&penTop[1]);
pDC->MoveTo(lpRect->left+1, lpRect->top+1);
pDC->LineTo(lpRect->right-8,lpRect->top+1);
//绘制左边的9根线
for (int i=0; i<9; i++)
{
pDC->SelectObject(&penLeft[i]);
if (i==0)
{
pDC->MoveTo(lpRect->left+i, lpRect->top+1);
pDC->LineTo(lpRect->left+i, lpRect->bottom);
}
else
{
pDC->MoveTo(lpRect->left+i, lpRect->top+2);
pDC->LineTo(lpRect->left+i, lpRect->bottom);
}
}
//绘制右边的14根线
for (i=0; i<14; i++)
{
pDC->SelectObject(&penRight[i]);
if(i < 3)
{
pDC->MoveTo(lpRect->right-i-1, lpRect->top);
pDC->LineTo(lpRect->right-i-1, lpRect->bottom);
}
else if(i < 8)
{
pDC->MoveTo(lpRect->right-i-1, lpRect->top-1);
pDC->LineTo(lpRect->right-i-1, lpRect->bottom);
}
else
{
pDC->MoveTo(lpRect->right-i-1, lpRect->top-2);
pDC->LineTo(lpRect->right-i-1, lpRect->bottom);
}
}
CPen penInbound;
CBrush brushInbound;
penInbound.CreateStockObject(NULL_PEN);
brushInbound.CreateSolidBrush(RGB(191,191,191));
//填充背景
CBrush *pOldBrush = pDC->SelectObject(&brushInbound);
pDC->SelectObject(&penInbound);
pDC->Rectangle(lpRect->left+9, lpRect->top+2,
lpRect->right-13, lpRect->bottom+1);
pDC->SelectObject(pOldPen);
pDC->SelectObject(pOldBrush);
}
/////////////////////////////////////////////////////////////////////////////
/*
函数介绍: 绘制曲线背景客户区,也就是绘制网格
输入参数: CDC *pDC,
LPCRECT lpRect
输出参数: 无
返回值 : 无
*/
/////////////////////////////////////////////////////////////////////////////
void CCurveFrame::DrawBkGrid(CDC *pDC, LPCRECT lpRect,
COLORREF clrBkGround, COLORREF clrGridXCoord,
COLORREF clrGridLine, COLORREF clrGridBoldLine)
{
//绘图区的尺寸临时变量
CRect rectCur;
rectCur = lpRect;
CPen penBk;//绘图区背景画笔
CBrush brushBk;//绘图区背景画刷
CPen penXCorrd;//绘图区X轴线
CPen penGridLine;//绘图区网格细线
CPen penGridBoldLine;//绘图区网格粗线
CPen penScale;//绘制坐标文字旁的坐标刻度线
penBk.CreatePen(PS_SOLID, 1, m_clrBkGround);
brushBk.CreateSolidBrush(clrBkGround);//画背景的颜色
penXCorrd.CreatePen(PS_SOLID, 1, m_clrGridXCoord);
penGridLine.CreatePen(PS_SOLID, 1, m_clrGridLine);
penGridBoldLine.CreatePen(PS_SOLID, 1, m_clrGridBoldLine);
penScale.CreateStockObject(BLACK_PEN);
//用背景画刷填充背景
CPen *pOldPen = pDC->SelectObject(&penBk);
CBrush *pOldBrush = pDC->SelectObject(&brushBk);
pDC->Rectangle(rectCur);
//绘制网格线之前要设置映射模式,转换坐标,移动原点
int oldMapMode = pDC->SetMapMode(MM_HIMETRIC);
CPoint oldPtViewOrg = pDC->SetViewportOrg(rectCur.left, (rectCur.bottom+rectCur.top)/2);
pDC->DPtoLP(&rectCur);
//绘制刻度线
CPoint ptFrom(0, 0);
CPoint ptTo(rectCur.right, 0);
pDC->SelectObject(&penXCorrd);
pDC->MoveTo(ptFrom);
pDC->LineTo(ptTo);//绘制X轴
//绘制垂直坐标刻度,0刻度线
pDC->SelectObject(&penScale);
pDC->MoveTo(ptFrom.x - 50, ptFrom.y);
pDC->LineTo(ptFrom.x - 200, ptFrom.y);
int nIntervalHor = (rectCur.top)/25;
for (int i=0; i<25; i++)
{//绘制上半部分水平网格,横行为10大格,50小格
if ((i+1)%5 == 0)
pDC->SelectObject(&penGridBoldLine);
else
pDC->SelectObject(&penGridLine);
ptFrom.Offset(0, nIntervalHor);
ptTo.Offset(0, nIntervalHor);
pDC->MoveTo(ptFrom);
pDC->LineTo(ptTo);
//绘制垂直坐标刻度线
if((i+1)%5 == 0)
{
pDC->SelectObject(&penScale);
pDC->MoveTo(ptFrom.x - 50, ptFrom.y);
pDC->LineTo(ptFrom.x - 200, ptFrom.y);
}
}
ptFrom.x = 0;
ptFrom.y = 0;
ptTo.x = rectCur.right;
ptTo.y = 0;
for (i=0; i<25; i++)
{//绘制下半部分水平网格
if ((i+1)%5 == 0)
pDC->SelectObject(&penGridBoldLine);
else
pDC->SelectObject(&penGridLine);
ptFrom.Offset(0, -nIntervalHor);
ptTo.Offset(0, -nIntervalHor);
pDC->MoveTo(ptFrom);
pDC->LineTo(ptTo);
//绘制垂直坐标刻度线
if((i+1)%5 == 0)
{
if (i != 24)
{
pDC->SelectObject(&penScale);
pDC->MoveTo(ptFrom.x - 50, ptFrom.y);
pDC->LineTo(ptFrom.x - 200, ptFrom.y);
}
else
{
pDC->SelectObject(&penScale);
pDC->MoveTo(ptFrom.x - 50, ptFrom.y);
pDC->LineTo(ptFrom.x - 200, ptFrom.y);
//绘制x轴的最左边一条坐标线
pDC->MoveTo(ptFrom.x, ptFrom.y - 50);
pDC->LineTo(ptFrom.x, ptFrom.y - 200);
}
}
}
ptFrom = rectCur.TopLeft();
ptTo.x = rectCur.left;
ptTo.y = rectCur.bottom;
int nIntervalVer = (rectCur.right)/50;
pDC->SelectObject(&penGridBoldLine);
pDC->MoveTo(ptFrom.x+1, ptFrom.y);
pDC->LineTo(ptTo.x+1, ptTo.y);
for (i=0; i<50; i++)
{//绘制垂直部分网格,纵行为50小格,10大格
if ((i+1)%5 == 0)
pDC->SelectObject(&penGridBoldLine);
else
pDC->SelectObject(&penGridLine);
ptFrom.Offset(nIntervalVer, 0);
ptTo.Offset(nIntervalVer, 0);
pDC->MoveTo(ptFrom);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -