📄 relayshow.cpp
字号:
// RelayShow.cpp : implementation file
//
#include "stdafx.h"
#include "JHHB.h"
#include "RelayShow.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CRelayShow
CRelayShow::CRelayShow()
{
m_status = RELAY_STATUS_STOP;
m_bNeedRedraw = FALSE;
}
CRelayShow::~CRelayShow()
{
}
BEGIN_MESSAGE_MAP(CRelayShow, CButton)
//{{AFX_MSG_MAP(CRelayShow)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRelayShow message handlers
BOOL CRelayShow::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}
//-------------------ljh begin
//OnPaint(COD),OnPaint(FLOW),OnPaint(NH4N)
//-------------------ljh end
void CRelayShow::OnPaint()
{
CPaintDC dc(this); // device context for painting
const COLORREF clrBk = RGB(0, 0, 0);
const COLORREF clrAlert = RGB(255, 0, 0);
const COLORREF clrSafe = RGB(0, 255, 0);
const COLORREF clrWait = RGB(255, 255, 0);
CRect rtBounds;
GetClientRect(&rtBounds);
int nRight = rtBounds.right;
int nBottom = rtBounds.bottom;
dc.FillSolidRect(&rtBounds, clrBk);
CFont font;
LOGFONT logFont;
memset(&logFont, 0, sizeof(logFont));
logFont.lfHeight =24;
logFont.lfWidth = 18;
logFont.lfCharSet = OEM_CHARSET;
CString szFont = "宋体_GB2312"; // "Courier New";
lstrcpy(logFont.lfFaceName, szFont);
VERIFY(font.CreateFontIndirect(&logFont));
dc.SetTextColor(clrWait);
CFont* pFontOld = dc.SelectObject(&font); // Coord Line
switch (m_status)
{
case RELAY_STATUS_WAITFRIST:
{
dc.TextOut(40,40,_T(" 开始通讯 "));
break;
}
case RELAY_STATUS_STRANSDATA:
{
if (m_bNeedRedraw)
m_timeLast = CTime::GetCurrentTime() - CTimeSpan(0,0,0,10);
CTime t = m_timeLast;
CString strDisplay;
for (int i=0;i<10;i++)
{
strDisplay.Format(_T("%2.2d:%2.2d:%2.2d_%05.2f"),
t.GetHour(),
t.GetMinute(),
t.GetSecond(),
CalcPHValue((BYTE)*(m_pDisplayDataBuf + i)));
dc.TextOut(4,i*24, strDisplay);
t+=CTimeSpan(0,0,0,1);
}
m_bNeedRedraw=FALSE;
break;
}
case RELAY_STATUS_STOP:
{
dc.TextOut(10,10,_T(" 等待通讯 "));
break;
}
}
dc.SelectObject(pFontOld);
return;
// Do not call CButton::OnPaint() for painting messages
}
/*
The format of relay data 18 Bytes
Type Content
-------------------------------
BYTE 'H'
BYTE 'E'
BYTE 'A'
BYTE 'D'
BYTE Station
BYTE PH_data at 9 Seconds befor now
BYTE PH_data at 8 Seconds befor now
...
BYTE PH_data at 1 Seconds befor now
BYTE PH_data at now
BYTE 'T'
BYTE 'A'
BYTE 'I'
BYTE 'L'
*/
void CRelayShow::UpdateDisplayBuff(BYTE * pUpdateBuff)
{
memcpy(m_pDisplayDataBuf,pUpdateBuff + 5 ,10);
}
double CRelayShow::CalcPHValue(WORD nPHNubmer) //BYTE nPHNubmer) ljh
{
double dPHNumber = (double)nPHNubmer;
int nPHTop =14;
int nPHBottom =0;
double nADTop=255;
double nADBottom=51;
if (dPHNumber < nADBottom)
dPHNumber = nADBottom; // Update at 1997.5.29 Let return value >=0
return (dPHNumber - nADBottom) * (nPHTop - nPHBottom) / (nADTop - nADBottom) + nPHBottom;
}
//---------------------ljh begin
double CRelayShow::CalcCODValue(WORD nCODNubmer) //BYTE nPHNubmer) ljh
{
double dCODNumber = (double)nCODNubmer;
nCODTOP =14;
nCODBOT =0;
nCODTOP =2000;
nCODBOT =0;
return (1);
}
double CRelayShow::CalcFLOWValue(WORD nFLOWNubmer) //BYTE nPHNubmer) ljh
{
double dFLOWNumber = (double)nFLOWNubmer;
nFLOWTOP =14;
nFLOWBOT =0;
nFLOWTOP =255;
nFLOWBOT =51;
return (1);
}
double CRelayShow::CalcNH4NValue(WORD nNH4NNubmer) //BYTE nPHNubmer) ljh
{
double dNH4NNumber = (double)nNH4NNubmer;
nNH4NTOP =14;
nNH4NBOT =0;
nNH4NTOP =255;
nNH4NBOT =51;
return (1);
}
//---------------------ljh end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -