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

📄 snmpmanagerview.cpp

📁 路由信息查看程序
💻 CPP
字号:
// SnmpManagerView.cpp : implementation of the CSnmpManagerView class
//

#include "stdafx.h"
#include "SnmpManager.h"

#include "SnmpManagerDoc.h"
#include "SnmpManagerView.h"
#include <math.h>

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

struct DigitList
{
	int InDigit;
	struct DigitList *next;
};

struct DigitList *head, *temp;
/////////////////////////////////////////////////////////////////////////////
// CSnmpManagerView

IMPLEMENT_DYNCREATE(CSnmpManagerView, CView)

BEGIN_MESSAGE_MAP(CSnmpManagerView, CView)
	//{{AFX_MSG_MAP(CSnmpManagerView)	
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSnmpManagerView construction/destruction

CSnmpManagerView::CSnmpManagerView()
{
	// TODO: add construction code here
	head = (struct DigitList*)malloc(sizeof(struct DigitList));
	head->InDigit = 0;
	head->next = NULL;
}

CSnmpManagerView::~CSnmpManagerView()
{
}

BOOL CSnmpManagerView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CSnmpManagerView drawing

void CSnmpManagerView::OnDraw(CDC* pDC)
{
	CSnmpManagerDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	initDrawPic();
}

/////////////////////////////////////////////////////////////////////////////
// CSnmpManagerView diagnostics

#ifdef _DEBUG
void CSnmpManagerView::AssertValid() const
{
	CView::AssertValid();
}

void CSnmpManagerView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CSnmpManagerDoc* CSnmpManagerView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSnmpManagerDoc)));
	return (CSnmpManagerDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CSnmpManagerView message handlers


void CSnmpManagerView::initDrawPic()
{
	CClientDC dc(this);
	CRect rect;
	POINT point;
	GetClientRect(&rect);
	CBrush boardcolor ;
	boardcolor.CreateSolidBrush (RGB(0, 0, 0));
	dc.SelectObject (&boardcolor);


	yValue = (float)(2*rect.bottom)/(3*100);
	if(yValue < 0.05)
		yValue = 0.05;
	xValue = 20*yValue;
	point.x = 30 ;
	point.y = rect.bottom*4/5;

	dc.MoveTo (point);

	point.x = rect.right ;

	dc.LineTo (point);
	CString st;
	st.Format ("%d", 0);
	dc.TextOut (point.x, point.y, st);

	point.x = 30;

	dc.MoveTo (point);
	dc.LineTo (30, rect.top - 10);

	for(int i = 1; i <= 100; i++)
	{
		CPen pen1;

		point.x = 30;
		point.y = 4*rect.bottom/5 - i*yValue;

		if(i%10 == 0)
		{
			pen1.CreatePen(PS_DASHDOT, 0.5, RGB(255, 0, 0));
			dc.SelectObject (&pen1);
			CString str;
			str.Format ("%d", i);
			dc.TextOut (point.x - 25, point.y, str);
			dc.MoveTo (point);

			point.x = rect.right ;

			dc.LineTo (point);
			pen1.DeleteObject ();
		}
		else
		{
			if(yValue >= 1)
			{
				dc.MoveTo (point);

				point.x = 25;

				dc.LineTo (point);
			}
		}
	}

	for(i = 30; i < rect.right; i += (int)xValue)
	{
		CPen pen2;
		pen2.CreatePen(PS_DASHDOT, 0.5, RGB(0, 0, 255));
		dc.SelectObject (&pen2);

		point.x = i + (int)xValue;
		point.y = rect.bottom*4/5;

		dc.MoveTo (point);
        
        point.y = rect.top - 10;
		
		dc.LineTo (point);
		pen2.DeleteObject ();
	}

	boardcolor.DeleteObject ();
}

void CSnmpManagerView::DrawPic (int IpInReceive)
{
	struct DigitList *p1, *p2, *p;
	if(head->next == NULL)
	{
		p1 = (struct DigitList*)malloc(sizeof(struct DigitList));
		p1->InDigit = IpInReceive;
		p1->next = NULL;
		head->next = p1;
	}
	else
	{
		p = head;
		while(p->next != NULL)
		{
			p = p->next;
		}
		p2 = (struct DigitList*)malloc(sizeof(struct DigitList));
		p2->InDigit = IpInReceive;
		p2->next = NULL;
		p->next = p2;
	}
}

void CSnmpManagerView::ClearDigit ()
{
	struct DigitList *p1, *p2;
	if(head->next != NULL)
	{
        p1 = head->next ;

		while(1)
		{
		    p2 = p1;
			if(p1->next != NULL)
		        p1 = p1->next ;
			else
				break;
			free(p2);
		}
	}
}


void CSnmpManagerView::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	CPoint point;
	CRect rect;
	int i = 0;
	GetClientRect(&rect);
	// TODO: Add your message handler code here
	OnDraw(&dc);
	if(head->next != NULL)
	{
		temp = head->next ;
		while(temp->next->next != NULL)
		{
			 point.x = 30 + i;
			 point.y = rect.bottom*4/5 - fabs(temp->next->InDigit - temp->InDigit)*yValue;
			 dc.MoveTo(point);
			 i++;
			 point.x = 30 + i;
			 point.y = rect.bottom*4/5 - fabs(temp->next->next->InDigit - temp->next->InDigit)*yValue;
			 dc.LineTo(point);
			 temp = temp->next;
		}
	}

	// Do not call CView::OnPaint() for painting messages
}

⌨️ 快捷键说明

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