📄 recordgraph.cpp
字号:
{
if(page.pageAddr[page.dataOffset + page.dataSize*nRecord]>nMax)
nMax = page.pageAddr[page.dataOffset + page.dataSize*nRecord];
if(page.pageAddr[page.dataOffset + page.dataSize*nRecord]<nMin)
nMin = page.pageAddr[page.dataOffset + page.dataSize*nRecord];
}
}
else if(nPage == file.m_endPageIndex)
{
for(nRecord=0; nRecord<file.m_endRecordIndex; nRecord++)
{
if(page.pageAddr[page.dataOffset + page.dataSize*nRecord]>nMax)
nMax = page.pageAddr[page.dataOffset + page.dataSize*nRecord];
if(page.pageAddr[page.dataOffset + page.dataSize*nRecord]<nMin)
nMin = page.pageAddr[page.dataOffset + page.dataSize*nRecord];
}
}
else
{
for(nRecord=0; nRecord<6; nRecord++)
{
if(page.pageAddr[page.dataOffset + page.dataSize*nRecord]>nMax)
nMax = page.pageAddr[page.dataOffset + page.dataSize*nRecord];
if(page.pageAddr[page.dataOffset + page.dataSize*nRecord]<nMin)
nMin = page.pageAddr[page.dataOffset + page.dataSize*nRecord];
}
}
}
//绘制Y轴坐标值
CRect rcText;
CSize sizeText;
TCHAR szText[20] = {0};
int nBasex = m_rcClient.left + m_leftMargin;
int nBasey = m_rcClient.bottom - m_bottomMargin;
CFont* pOldFont = pDC->SelectObject(&m_scaleFont);
int oldBkMode = pDC->SetBkMode(TRANSPARENT);
COLORREF oldColor = pDC->SetTextColor(m_scaleColor);
CString strFormat;
strFormat.Format(_T("%%d"));
int nValueOfOneGrid = (nMax-nMin)/(m_yGridCount-2);
for (int i=1; i<=m_yGridCount; i++)
{
// if (i == m_nXGrids && fHasUnit) break;
memset(szText, 0, sizeof(szText));
_stprintf(szText, strFormat, nMin + i*nValueOfOneGrid);
sizeText = pDC->GetOutputTextExtent(szText);
rcText.left = nBasex - sizeText.cx -2;
//rcText.left = nBasex + i*m_gridWidth - sizeText.cx/2;
rcText.right = nBasex;
rcText.top = nBasey - m_gridHeight * i - sizeText.cy/2 ;
rcText.bottom = rcText.top + sizeText.cy;
pDC->DrawText(szText, rcText, DT_RIGHT | DT_BOTTOM);
}
pDC->SetBkMode(oldBkMode);
pDC->SelectObject(pOldFont);
pDC->SetTextColor(oldColor);
CPen* pOldPen = pDC->SelectObject(&vavePen);
int nOldMode = pDC->SetBkMode(TRANSPARENT);
int nStartx = m_rcClient.left + m_leftMargin;
int nEndx = m_rcClient.right - m_rightMargin;
int nStarty = m_rcClient.bottom - m_bottomMargin;
int nEndy = m_rcClient.top + m_topMargin;
pDC->SelectObject(&vavePen);
// UINT nStartPageIndex;
// UINT nStartRecordIndex;
if(m_nCurDrawNum>0)
{
nStartPageIndex = file.m_startPageIndex + m_nCurDrawNum*580/6 + (file.m_startRecordIndex + m_nCurDrawNum*580%6 + 1)/6;
nStartRecordIndex = (file.m_startRecordIndex + m_nCurDrawNum*580%6 + 1)%6;
}
else
{
nStartPageIndex = file.m_startPageIndex + m_nCurDrawNum*580/6 + (file.m_startRecordIndex + m_nCurDrawNum*580%6)/6;
nStartRecordIndex = (file.m_startRecordIndex + m_nCurDrawNum*580%6)%6;
}
// UINT nStartPageIndex = file.m_startPageIndex + m_nCurDrawNum*580/5/6 + (file.m_startRecordIndex + m_nCurDrawNum*580/5%6)/6;
// UINT nStartRecordIndex = (file.m_startRecordIndex + m_nCurDrawNum*580/5%6)%6;
// CString str;
// str.Format("%d,%d",nStartPageIndex,nStartRecordIndex);
// AfxMessageBox(str);
file.GetDataPageAt(nStartPageIndex, &page);
pDC->MoveTo(nStartx, nStarty - m_gridHeight*page.pageAddr[page.dataOffset + page.dataSize*nStartRecordIndex]/nValueOfOneGrid);
for(nPage=nStartPageIndex; nPage<=file.m_endPageIndex; nPage++)
{
file.GetDataPageAt(nPage, &page);
if(nPage == file.m_startPageIndex)
{
for(nRecord=nStartRecordIndex+1; nRecord<6 && nStartx<=nEndx; nRecord++)
{
pDC->LineTo(nStartx++, nStarty - m_gridHeight*page.pageAddr[page.dataOffset + page.dataSize*nRecord]/nValueOfOneGrid);
//nStartx +=4;
}
}
else if(nPage == file.m_endPageIndex)
{
for(nRecord=0; nRecord<file.m_endRecordIndex && nStartx<=nEndx; nRecord++)
{
pDC->LineTo(nStartx++, nStarty - m_gridHeight*page.pageAddr[page.dataOffset + page.dataSize*nRecord]/nValueOfOneGrid);
//nStartx +=4;
}
}
else
{
for(nRecord=0; nRecord<6 && nStartx<=nEndx; nRecord++)
{
pDC->LineTo(nStartx++, nStarty - m_gridHeight*page.pageAddr[page.dataOffset + page.dataSize*nRecord]/nValueOfOneGrid);
//nStartx +=4;
}
}
}
pDC->SetBkMode(nOldMode);
pDC->SelectObject(pOldPen);
//绘制X轴坐标
pOldFont = pDC->SelectObject(&m_scaleFont);
oldBkMode = pDC->SetBkMode(TRANSPARENT);
oldColor = pDC->SetTextColor(m_scaleColor);
strFormat.Format(_T("%%d"));
COleDateTime oleStartTime,oleEndTime;
COleDateTimeSpan spanStartTime(0,0,0,file.m_startRecordIndex);
COleDateTimeSpan spanEndTime(0,0,0,file.m_endRecordIndex);
file.GetHeadDataPageTime(oleStartTime);
file.GetTailDataPageTime(oleEndTime);
oleStartTime +=spanStartTime;
oleEndTime +=spanEndTime;
oleStartTime +=m_nCurDrawNum*(nEndx-nStartx);
int value = 0;
for (i=0; i<=m_xGridCount; i++)
{
// if (i == m_nXGrids && fHasUnit) break;
memset(szText, 0, sizeof(szText));
value += 1;
_stprintf(szText, strFormat, value);
sizeText = pDC->GetOutputTextExtent(szText);
rcText.left = nBasex + i*m_gridWidth - sizeText.cx/2;
rcText.right = rcText.left + sizeText.cx;
rcText.top = nBasey + 5;
rcText.bottom = rcText.top + sizeText.cy;
pDC->DrawText(szText, rcText, DT_RIGHT | DT_BOTTOM);
}
pDC->SetBkMode(oldBkMode);
pDC->SelectObject(pOldFont);
pDC->SetTextColor(oldColor);
// m_gridWidth = m_gridHeight = 20;
}
CATCH(CFileException, e)
{
}
CATCH(CRecordException, e)
{
//TRACE("ErrorDescription:%s\n",e->GetErrorDecription());
}
END_CATCH
}
void CRecordGraph::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
int nStartx = m_rcClient.left + m_leftMargin;
int nEndx = m_rcClient.right - m_rightMargin;
int nStarty = m_rcClient.bottom - m_bottomMargin;
int nEndy = m_rcClient.top + m_topMargin;
CRect drawRect(nStartx,nEndy,nEndx,nStarty);
if(!(drawRect.PtInRect(point)))
{
return;
}
// MessageBox( "Me Clicked!","提示!",MB_OK);
if(nCheck == 1)
{
bDrawBaseLineOne = TRUE;
XbaseLineOne = point.x;
}
else if(nCheck == 2)
{
bDrawBaseLineTwo = TRUE;
XbaseLineTwo = point.x;
}
CWnd::OnLButtonDblClk(nFlags, point);
Invalidate();
}
void CRecordGraph::OnAverage(int &nAverage)
{
if(!bDrawBaseLineOne || !bDrawBaseLineTwo)
return;
COleDateTime t1(2008, 11, 17, 17, 20, 02);
COleDateTime t2(2008, 11, 17, 17, 29, 50);
CRecordFile file(m_FilePath,t1,t2);
CDataPage page;
// nStartPageIndex;
// nStartRecordIndex;
long lStrartPoint,lEndPoint;
if(XbaseLineOne<=XbaseLineTwo)
{
lStrartPoint = nStartPageIndex*6+nStartRecordIndex + XbaseLineOne - m_leftMargin;
lEndPoint = nStartPageIndex*6+nStartRecordIndex + XbaseLineTwo - m_leftMargin;
}
else
{
lStrartPoint = nStartPageIndex*6+nStartRecordIndex + XbaseLineTwo - m_leftMargin;
lEndPoint = nStartPageIndex*6+nStartRecordIndex + XbaseLineOne - m_leftMargin;
}
UINT nTempStartPageIndex,nTempEndPageIndex,nTempStartRecordIndex,nTempEndRecordIndex;
nTempStartPageIndex = lStrartPoint/6;
nTempEndPageIndex = lEndPoint/6;
nTempStartRecordIndex = lStrartPoint%6;
nTempEndRecordIndex = lEndPoint%6;
long lSum = 0;
int st=0;
for(UINT nPage=nTempStartPageIndex; nPage<=nTempEndPageIndex; nPage++)
{
file.GetDataPageAt(nPage, &page);
if(nPage == nTempStartPageIndex)
{
UINT nMaxRecord;
if(nTempStartPageIndex == nTempEndPageIndex)
nMaxRecord = nTempEndRecordIndex;
else
nMaxRecord = 5;
for(UINT nRecord=nTempStartRecordIndex; nRecord<=nMaxRecord; nRecord++)
{
lSum += page.pageAddr[page.dataOffset + page.dataSize*nRecord];
//st ++;
}
}
else if(nPage == nTempEndPageIndex)
{
int nMaxRecord;
if(nTempStartPageIndex == nTempEndPageIndex)
nMaxRecord = -1;
else
nMaxRecord = nTempEndRecordIndex;
for(int nRecord=0; nRecord<=nMaxRecord ; nRecord++)
{
lSum += page.pageAddr[page.dataOffset + page.dataSize*nRecord];
//st ++;
}
}
else
{
for(UINT nRecord=0; nRecord<6; nRecord++)
{
lSum += page.pageAddr[page.dataOffset + page.dataSize*nRecord];
//st ++;
}
}
}
CString str;
// str.Format("%ld,%d\n,%d,%d,%d,%d,%d",lSum,abs(XbaseLineOne - XbaseLineTwo)+1,\
// nTempStartPageIndex,nTempEndPageIndex,nTempStartRecordIndex,nTempEndRecordIndex,st);
str.Format("the Average is %d of the sum %ld",lSum/(abs(XbaseLineOne - XbaseLineTwo)+1),lSum);
AfxMessageBox(str);
nAverage = lSum/(abs(XbaseLineOne - XbaseLineTwo)+1);
}
void CRecordGraph::OnGraphMessage(WPARAM wParam,LPARAM lParam)
{
switch(wParam)
{
case 0:
{
AfxMessageBox("zxb,sa");
break;
}
case 1:
{
break;
}
case 2:
{
HWND hWnd=::FindWindow(NULL,"");
break;
}
case 3:
{
HWND hWnd=::FindWindow(NULL,"");
break;
}
default:
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -