⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 curvedynamicflow.cpp

📁 远程视频监控系统最新程序代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// CurveDynamicFlow.cpp : implementation file
//

#include "stdafx.h"
#include "CurveDynamicFlow.h"
#include <math.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CCurveDynamicFlow

CCurveDynamicFlow::CCurveDynamicFlow()
{
    
}

CCurveDynamicFlow::~CCurveDynamicFlow()
{	
	if (m_MemDC.GetSafeHdc()!=NULL) m_MemDC.SelectObject(m_preBitmap);
	int nIndex=m_nItems.GetSize();
	for(int i=0;i<nIndex;i++)
	{
		delete m_nItems.GetAt(i);
	}
	m_nItems.RemoveAll();
}


BEGIN_MESSAGE_MAP(CCurveDynamicFlow, CWnd)
	//{{AFX_MSG_MAP(CCurveDynamicFlow)
	ON_WM_PAINT()
	ON_WM_CREATE()
	ON_WM_HSCROLL()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CCurveDynamicFlow message handlers
void CCurveDynamicFlow::SetBkFrameColor(long BkColor, long FrameColor) 
{
	// TODO: Add your dispatch handler code here
    m_nBkColor=(BkColor);
	m_nFrameColor=(FrameColor);
}

void CCurveDynamicFlow::SetPrimCompart(short xSum, short ySum, short PenWidth, short PenStyle, long PenColor) 
{
	// TODO: Add your dispatch handler code here
    if (xSum>5) xSum=5;
	if (xSum<0) xSum=0;
	if (ySum>5) ySum=5;
	if (xSum<0) xSum=0;
    m_xPrimLineSum=xSum;
	m_yPrimLineSum=ySum;
	m_PrimPenWidth=PenWidth;
	m_PrimPenStyle=PenStyle;
	m_PrimPenColor=(PenColor);
	if (m_xPrimLineSum<0) m_xPrimLineSum=0;
	if (m_yPrimLineSum<0) m_yPrimLineSum=0;
}


void CCurveDynamicFlow::SetSecCompart(short xSum, short ySum, short PenWidth, short PenStyle, long PenColor) 
{
 	// TODO: Add your dispatch handler code here
	if (xSum>5) xSum=5;
	if (xSum<0) xSum=0;
	if (ySum>5) ySum=5;
	if (xSum<0) xSum=0;
    m_xSecLineSum=xSum;
	m_ySecLineSum=ySum;
	m_SecPenWidth=PenWidth;
	m_SecPenStyle=PenStyle;
	m_SecPenColor=(PenColor);
    if (m_xSecLineSum<0) m_xSecLineSum=0;
	if (m_ySecLineSum<0) m_ySecLineSum=0;
} 


void CCurveDynamicFlow::SetXId(short xCount, long nColor,short nFontSize,char *nFontName) 
{
	// TODO: Add your dispatch handler code here  
   m_xIdentifySum=xCount;
   if (m_xIdentifySum<0) m_xIdentifySum=0;
   if (m_xIdentifySum>6) m_xIdentifySum=6;  
   m_xIdentifyColor=(nColor);
   m_nTimeCoordFontSize=nFontSize;
   strcpy(m_nTimeCoordFontName,nFontName);
}

 
void CCurveDynamicFlow::SetSplitLine(short nPenStyle, short nPenWidth, long nPenColor) 
{
	// TODO: Add your dispatch handler code here
   m_nSplitPenStyle=nPenStyle;
   m_nSplitPenWidth=nPenWidth;
   m_nSplitPenColor=(nPenColor);
}


void CCurveDynamicFlow::InitCtrl(short nHeight,short nWidth,short nFrameTopH,short nFrameLeftW,short nFrameRightW,short nFrameBottomH) 
{
	// TODO: Add your dispatch handler code here
	
   if (m_MemDC.GetSafeHdc()==NULL)
	{
      CClientDC dc(this);  
	  m_nHeight=nHeight;
	  m_nWidth=nWidth;
	  m_nFrameTopH=nFrameTopH;
      m_nFrameLeftW=nFrameLeftW;
	  m_nFrameRightW=nFrameRightW;
	  m_nFrameBottomH=nFrameBottomH;
	  m_nPtInSplitLine=FALSE;
	  m_MemDC.CreateCompatibleDC(&dc);
	  m_Bitmap.CreateCompatibleBitmap(&dc,m_nWidth,m_nHeight+m_nFrameBottomH);
	  m_preBitmap=m_MemDC.SelectObject(&m_Bitmap);
	
	}
}

void CCurveDynamicFlow::InvalidateCtrl(long nCurrentTime) 
{
	// TODO: Add your dispatch handler code here	  
	  if (m_MemDC.GetSafeHdc()==NULL) return;
	  m_nInitTime=(time_t)nCurrentTime;  // init time;
	  m_nEndTime=nCurrentTime;
	  m_nStartTime=nCurrentTime-m_nTimer*m_nWidth/m_nPigment;
	  m_nCurrentSplitTime=m_nEndTime;
	  m_nLineX=m_nWidth;
	  m_nCurveMoved=0;                   // init curve moved 
	  m_nSecLineMoved=0;
	  m_nSecPrecision=0;
	    nCheck=0;
	    nBCount=0;
      CRect nRect;
	  CBrush nBkBrush(m_nBkColor);
	  CBrush nFrameBrush(m_nFrameColor);
	  nRect.SetRect(0,0,m_nWidth,m_nHeight+m_nFrameBottomH);
	  m_MemDC.FillRect(&nRect,&nFrameBrush);
      nRect.SetRect(0,0,m_nWidth,m_nHeight);
	  m_MemDC.FillRect(&nRect,&nBkBrush);
	  int i,j;
	  float x,y,nRange;
	  CPen *prePen;
	  CPen nPen1(m_PrimPenStyle,m_PrimPenWidth,m_PrimPenColor);
      CPen nPen2(m_PrimPenStyle,m_SecPenWidth,m_SecPenColor);
	  x=nRect.right-nRect.left;
	  y=nRect.bottom-nRect.top;
      nRange=x/(m_xPrimLineSum+1);
      for(i=0;i<=m_xPrimLineSum+1;i++)
	  {   
		  prePen=m_MemDC.SelectObject(&nPen1);
		  m_MemDC.MoveTo((int)(i*nRange),nRect.top);
		  m_MemDC.LineTo((int)(i*nRange),nRect.bottom);
		  m_MemDC.SelectObject(prePen); 
		  if (i<m_xPrimLineSum+1) 
		  {		
			prePen=m_MemDC.SelectObject(&nPen2);
		    for(j=1;j<m_xSecLineSum+1;j++)
			{ 

		     m_MemDC.MoveTo((int)(i*nRange+j*nRange/(m_xSecLineSum+1)),nRect.top);
		     m_MemDC.LineTo((int)(i*nRange+j*nRange/(m_xSecLineSum+1)),nRect.bottom);
			}	
		    m_MemDC.SelectObject(prePen);
		  }
	  }
	  nRange=y/(m_yPrimLineSum+1);
	  for(i=0;i<=m_yPrimLineSum+1;i++)
	  {   
		  prePen=m_MemDC.SelectObject(&nPen1);
		  m_MemDC.MoveTo(nRect.left,(int)(i*nRange));
		  m_MemDC.LineTo(nRect.right,(int)(i*nRange));
		  m_MemDC.SelectObject(prePen);
		  if (i<m_yPrimLineSum+1)
		  {     
			 prePen=m_MemDC.SelectObject(&nPen2);
			 for(j=1;j<m_ySecLineSum+1;j++)
			 { 
		       m_MemDC.MoveTo(nRect.left,(int)(i*nRange+j*nRange/(m_ySecLineSum+1)));
		       m_MemDC.LineTo(nRect.right,(int)(i*nRange+j*nRange/(m_ySecLineSum+1)));
			 }
		     m_MemDC.SelectObject(prePen);
		  }
	  }
	  
     if (m_xIdentifySum>0) // if have time coordinate identify 
	 {
		 if ((m_nTimer*(m_nWidth/m_nPigment))%m_xIdentifySum!=0) m_xIdentifySum--;
		 m_xIdentifySpace=m_nWidth/m_xIdentifySum;				
		 CString str;	
		 str.Format("%2d:%2d:%2d  ",m_nInitTime.GetHour(),m_nInitTime.GetMinute(),m_nInitTime.GetSecond());
		 m_nTimeStr=str;
		 m_nPerTime=m_nTimer*(m_nWidth/m_nPigment)/m_xIdentifySum;
		 CFont nFont;
		  nFont.CreatePointFont(m_nTimeCoordFontSize,m_nTimeCoordFontName,NULL);
		  CFont *preFont=m_MemDC.SelectObject(&nFont);
		  CSize nSize=m_MemDC.GetTextExtent(str);
		  m_xIdentifyWidth=nSize.cx;
		  m_xIdentifyCy=m_nHeight+(m_nFrameBottomH-nSize.cy)/2;
		  m_xIdentifyMoved=(m_xIdentifyWidth+1)/2;
		  COLORREF preTextColor=m_MemDC.SetTextColor(m_xIdentifyColor);
		  COLORREF preBkColor=m_MemDC.SetBkColor(m_nFrameColor);
		  for (i=m_xIdentifySum;i>=0;i--)
		  {
		     m_MemDC.TextOut(i*m_xIdentifySpace-m_xIdentifyWidth/2,m_xIdentifyCy,str);
             CTime nTime;
			 nTime=(time_t)(m_nInitTime.GetTime()-(m_xIdentifySum-i+1)*m_nPerTime);
             str.Format("%2d:%2d:%2d",nTime.GetHour(),nTime.GetMinute(),nTime.GetSecond());
		  }
          m_MemDC.SelectObject(preFont);			
		  m_MemDC.SetTextColor(preTextColor);
		  m_MemDC.SetBkColor(preBkColor);
		  nFont.DeleteObject();
		  str.Empty();
	 }
	Invalidate(FALSE);
}

void CCurveDynamicFlow::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	OnDraw(&dc);
	// Do not call CWnd::OnPaint() for painting messages
}

void CCurveDynamicFlow::SetTimePigment(short nTime, short nPigment) 
{
	// TODO: Add your dispatch handler code here
	// (0<pigment<6)
	if(nPigment<1)  nPigment=1;   
	if(nPigment>6)  nPigment=6;
	m_nTimer=nTime;
	m_nPigment=nPigment;   
}


BOOL CCurveDynamicFlow::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
{
	// TODO: Add your specialized code here and/or call the base class
	m_pParentWnd=pParentWnd;
	if (CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext))
	{
			ResetScrollBars();
			return TRUE;
	}
	return FALSE;
}

int CCurveDynamicFlow::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	
	return 0;
}


void  CCurveDynamicFlow::OnDraw(CDC* pDC)
{
	
     CRect nRect;
	 CBrush nFrameBrush(m_nFrameColor);
	 nRect.SetRect(0,0,m_nFrameLeftW,m_nFrameTopH+m_nHeight+m_nFrameBottomH);	
	 pDC->FillRect(&nRect,&nFrameBrush);
	 nRect.SetRect(m_nFrameLeftW,0,m_nFrameLeftW+m_nWidth,m_nFrameTopH);
     pDC->FillRect(&nRect,&nFrameBrush);
     nRect.SetRect(m_nFrameLeftW+m_nWidth,0,m_nFrameLeftW+m_nWidth+m_nFrameRightW,m_nFrameTopH+m_nHeight+m_nFrameBottomH);
     pDC->FillRect(&nRect,&nFrameBrush);
	 
	if (m_MemDC.GetSafeHdc()!=NULL)
	{		
		pDC->BitBlt(m_nFrameLeftW,m_nFrameTopH,m_nWidth,m_nHeight+m_nFrameBottomH,&m_MemDC,0,0,SRCCOPY);  				
	    CPen nPen(m_nSplitPenStyle,m_nSplitPenWidth,m_nSplitPenColor);
        CPen *prePen=pDC->SelectObject(&nPen);
		pDC->MoveTo(m_nLineX+m_nFrameLeftW,m_nFrameTopH);
		pDC->LineTo(m_nLineX+m_nFrameLeftW,m_nHeight+m_nFrameTopH);
        pDC->SelectObject(prePen);
		m_nCurrentSplitTime=m_nStartTime+((m_nLineX)/m_nPigment)*m_nTimer;	
		if (m_nLineX%m_nPigment!=0) 
		if (m_nLineX%m_nPigment>(float)m_nPigment/2)m_nCurrentSplitTime+=m_nTimer;	
	}
	CLineChartItem *pItem;
	short nCount=m_yPrimLineSum+1;
	COLORREF oldBkColor=pDC->SetBkColor(m_nFrameColor);
	CSize nSize;
	CString nStr;
 	for(int i=0;i<2;i++)
	{
	   if (i>=m_nItems.GetSize()) break;
	   pItem=m_nItems.GetAt(i);
	   float nSpace=(pItem->m_nUpper-pItem->m_nLower)/nCount;
	   float nHeightSpace=m_nHeight/nCount;
       float nTemp;
	   for(int j=0;j<=nCount;j++)
	   {
         nTemp=pItem->m_nLower+j*nSpace;
		 if (nSpace>10.0)
		 {
			 nStr.Format("%6.0f",nTemp);
		 }
		 else  if (nSpace>1.0)
		 {		   
			 nStr.Format("%6.1f",nTemp);
		 }
	     else
		 {		   
			 nStr.Format("%6.2f",nTemp);
		 }
		 nStr.TrimLeft();
		 nSize=pDC->GetTextExtent(nStr);
		 if (i==0)
		 {
			  if (j==0 ) pDC->TextOut(m_nFrameLeftW-nSize.cx-2,m_nFrameTopH+m_nHeight-nHeightSpace*j-nSize.cy,nStr);
			  else pDC->TextOut(m_nFrameLeftW-nSize.cx-2,m_nFrameTopH+m_nHeight-nHeightSpace*j-nSize.cy/2,nStr);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -