📄 graphwnd.cpp
字号:
// Written by JHCC, 1996-1997
// GraphWnd.cpp : implementation file
//
#include "stdafx.h"
#include "JHHB.h"
#include "GraphWnd.h"
#include "JHHBDoc.h"
#include "JHHBView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
const int nDiv = 6; // every division per hour
const int nHour = 24;
const int nPH = 15;
const int nDelta = 5;
//-----------------ljh Begin
//加COD、FLOW、NH4N 画图常量
//-----------------ljh end
const double nPI = 3.1415926536;
const double nTheta = nPI / 8;
const double nDeltaArrow = 8.0;
#include <math.h> // for sin(), cos()
/////////////////////////////////////////////////////////////////////////////
// CGraphWnd
CGraphWnd::CGraphWnd()
{
}
CGraphWnd::~CGraphWnd()
{
}
BOOL CGraphWnd::Create(CWnd* pParentWnd, UINT nID)
{
if (CStatic::Create(NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | WS_THICKFRAME | SS_SIMPLE,
CRect(0, 0, 0, 0), pParentWnd, nID) == FALSE)
return FALSE;
return TRUE;
}
BEGIN_MESSAGE_MAP(CGraphWnd, CStatic)
//{{AFX_MSG_MAP(CGraphWnd)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGraphWnd message handlers
void CGraphWnd::OnPaint()
{
CPaintDC dc(this); // device context for painting
const COLORREF clrBk = RGB(0, 0, 0); //黑色
const COLORREF clrAlert = RGB(150, 0, 0); //红色
const COLORREF clrSafe = RGB(0, 150, 0); //绿色
const COLORREF clrAxis = RGB(255, 255, 255); //白色
const COLORREF clrText = RGB(0, 255, 255); //青色
const COLORREF clrDot = RGB(255, 255, 255); //白色
const COLORREF clrDataLine = RGB(255, 255, 100); //黄色 // add by SQJ
CRect rtBounds;
GetClientRect(&rtBounds);
int nRight = rtBounds.right;
int nBottom = rtBounds.bottom;
//------------------ljh Begin
// 加IF或CASE分别处理COD、FLOW、NH4N的画图窗口
//------------------ljh End
int nUnitX = nRight / ((nHour + 2)* nDiv);
int nUnitY = nBottom / (nPH + 3);
dc.FillSolidRect(&rtBounds, clrBk);
CPen penAlert(PS_SOLID, 1, clrAlert);
CPen penSafe(PS_SOLID, 1, clrSafe);
CPen penAxis(PS_SOLID, 1, clrAxis);
CPen penDataLine(PS_SOLID, 1, clrDataLine); // add by SQJ
CFont fontX;
CFont fontY;
LOGFONT logFont;
memset(&logFont, 0, sizeof(logFont));
logFont.lfHeight = nUnitY + 4;
logFont.lfWidth = nUnitX + 2;
logFont.lfCharSet = OEM_CHARSET;
CString szFont = "宋体_GB2312"; // "Courier New";
lstrcpy(logFont.lfFaceName, szFont);
VERIFY(fontX.CreateFontIndirect(&logFont));
logFont.lfHeight = nUnitY;
logFont.lfWidth = nUnitX * (nDiv / 4) + 4;
VERIFY(fontY.CreateFontIndirect(&logFont));
dc.SetTextColor(clrText);
CPen* pPenOld = dc.SelectObject(&penAxis); // Coord Line
CFont* pFontOld = dc.SelectObject(&fontX); // Coord Line
for (int i = 0; i < nPH; i++)
{
TCHAR pNumBuf[20];
itoa(i, pNumBuf, 10);
if ((i %2)==0)
dc.TextOut(nUnitX * (nDiv / 2 )- 4 , nBottom - (i + 2) * nUnitY - nUnitY / 2,
pNumBuf);
dc.MoveTo(nUnitX * nDiv , nBottom - (i + 2) * nUnitY);
switch (i)
{
case 0:
{
int nRightX = nRight - nUnitX * nDiv;
int nRightY = nBottom - (i + 2) * nUnitY;
int nCosX = int(nDeltaArrow * cos(nTheta));
int nSinY = int(nDeltaArrow * sin(nTheta));
dc.LineTo(nRightX, nRightY);
dc.LineTo(nRightX - nCosX, nRightY - nSinY);
dc.MoveTo(nRightX, nRightY);
dc.LineTo(nRightX - nCosX, nRightY + nSinY);
break;
}
case 7:
dc.SelectObject(&penSafe);
dc.LineTo(nRight - nUnitX * nDiv, nBottom - (i + 2) * nUnitY);
dc.SelectObject(&penAxis);
break;
case 6:
case 9:
dc.SelectObject(&penAlert);
dc.LineTo(nRight - nUnitX * nDiv, nBottom - (i + 2) * nUnitY);
dc.SelectObject(&penAxis);
break;
default:
if ((i % 2)==0)
dc.LineTo(nUnitX * nDiv + nDelta + 2, nBottom - (i + 2) * nUnitY);
else
dc.LineTo(nUnitX * nDiv + nDelta, nBottom - (i + 2) * nUnitY);
}
}
CString strPH;
strPH.LoadString(IDS_PH);
CString strTime;
strTime.LoadString(IDS_TIME);
dc.TextOut(nUnitX + nDelta+20, nUnitY / 2, strPH);
dc.TextOut(nRight + nDelta - nUnitX * nDiv - 20 , nBottom - 2 * nUnitY - 20 , strTime);
dc.SelectObject(&penAxis);
dc.SelectObject(&fontY); // Coord Line
for (i = 0; i < nHour; ++ i)
{
TCHAR pNumBuf[20];
itoa(i, pNumBuf, 10);
if ((i % 2)==0)
dc.TextOut((i + 1) * nUnitX * nDiv - 2,
nBottom - 2 * nUnitY + nUnitY / 2,
pNumBuf);
dc.MoveTo((i + 1) * nUnitX * nDiv, nBottom - 2 * nUnitY);
switch (i)
{
case 0:
{
int nRightX = (i + 1) * nUnitX * nDiv;
int nRightY = nUnitY;
int nSinX = int(nDeltaArrow * sin(nTheta));
int nCosY = int(nDeltaArrow * cos(nTheta));
dc.LineTo(nRightX, nRightY);
dc.LineTo(nRightX - nSinX, nRightY + nCosY);
dc.MoveTo(nRightX, nRightY);
dc.LineTo(nRightX + nSinX, nRightY + nCosY);
break;
}
default:
if ((i %2)==0)
dc.LineTo((i + 1) * nUnitX * nDiv, nBottom - 2 * nUnitY - nDelta - 2);
else
dc.LineTo((i + 1) * nUnitX * nDiv, nBottom - 2 * nUnitY - nDelta);
}
}
dc.SelectObject(pFontOld);
dc.SelectObject(&penDataLine);
dc.MoveTo(nUnitX * nDiv, nBottom - 2 * nUnitY); // add by SQJ
CDocument* pActiveDoc = GetParentFrame()->GetActiveDocument();
POSITION pos = pActiveDoc->GetFirstViewPosition();
CJHHBView* pView = (CJHHBView*)(pActiveDoc->GetNextView(pos));
if (pView->GetDocument()->m_bUseDao) // DAO
{
CDaoHBRecSet* pDaoSet = pView->GetDocument()->m_pDaoHBRecSet;
ASSERT(pDaoSet != NULL);
if (pDaoSet->GetRecordCount() == 0)
goto LABEL_NORECORD;
pDaoSet->MoveFirst();
BOOL m_bBreak =TRUE;
int x_old,y_old,x_new,y_new,i;
i=pDaoSet->m_NO - 1;
x_old=x_new=nUnitX * (nDiv + i);
y_old=y_new=nBottom - 2 * nUnitY - int(pDaoSet->m_PH * nUnitY);
do
{
pDaoSet->MoveNext();
if ( pDaoSet->IsEOF())
break;
m_bBreak=(i+1!=pDaoSet->m_NO - 1)? TRUE: FALSE;
i=pDaoSet->m_NO - 1 ;
x_new = nUnitX * ( nDiv + i);
y_new = nBottom - 2 * nUnitY - int(pDaoSet->m_PH * nUnitY);
dc.MoveTo(x_old, y_old);
if (!m_bBreak)
dc.LineTo(x_new, y_new); // add by SQJ
for (int x=x_new-1;x<=x_new+1;++x)
dc.SetPixel(x, y_new, clrDot);
for (int y=y_new;y<=y_new+1;++y)
dc.SetPixel(x_new, y, clrDot);
x_old=x_new;
y_old=y_new;
}while ( i < nHour * nDiv && !pDaoSet->IsEOF());
for (int x=x_new-1;x<=x_new+1;++x)
dc.SetPixel(x, y_new, clrDot);
for (int y=y_new;y<=y_new+1;++y)
dc.SetPixel(x_new, y, clrDot);
}
else // ODBC
{
CHBRecSet* pSet = pView->GetDocument()->m_pHBRecSet;
ASSERT(pSet != NULL);
if (pSet->GetRecordCount() == 0)
goto LABEL_NORECORD;
pSet->MoveFirst();
for (i = 0; i < nHour * nDiv && !pSet->IsEOF(); ++ i)
{
int x = nUnitX * (nDiv + pSet->m_NO - 1);
int y = nBottom - 2 * nUnitY - int(pSet->m_PH * nUnitY);
dc.LineTo(x, y); // add by SQJ
dc.SetPixel(x, y, clrDot);
pSet->MoveNext();
}
}
LABEL_NORECORD:
dc.SelectObject(pPenOld);
// Do not call CStatic::OnPaint() for painting messages
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -