小熠哥 小熠哥
关注数: 1 粉丝数: 0 发帖数: 147 关注贴吧数: 30
菜鸟求解释一段代码 求求求求求求求求求求.................. 下面好像是SNMP中本机到IP的传输速度的代码 void CSnmpManagerDlg::Draw(int x,int y,CDC *pDc) { pDc->MoveTo(x,0); pDc->LineTo(x,y); } void CSnmpManagerDlg::OnTimer(UINT nIDEvent) { if(nIDEvent==1) { if(true) { int i; //static double nIpin[200]; CWnd *pWnd=GetDlgItem(IDC_DRAW); CRect cRect; pWnd->GetClientRect(&cRect); CDC *pDc=pWnd->GetDC(); CBrush newBrush; newBrush.CreateSolidBrush(pDc->GetBkColor()); pDc->FillRect(cRect,&newBrush); pDc->SetMapMode(MM_ANISOTROPIC); pDc->SetViewportExt(cRect.Width(),cRect.Height()); pDc->SetWindowExt(-200,-10); pDc->SetViewportOrg(cRect.Width(),cRect.Height()-1); CPen pPen; pPen.CreatePen(PS_SOLID,1,RGB(0,0,255)); CPen* OldPen=(CPen*)pDc->SelectObject(&pPen); Start(); //nIpin[1]=nIpin[0]; for(i=200;i>0;i--) nIpin[i]=nIpin[i-1]; nIpin[0]=m_nIpin; nIpin[1]=nIpin[0]; //nIpin[m_nCount+1]=nIpin[m_nCount]; int j; for(i=0;i<=m_nCount;i++) { if((j=(nIpin[i]-nIpin[i+1])*5/m_nTrack)>=10) j=10; if(j<=0) j=0; Draw(i+1,j,pDc); } m_nCount++; pDc->SelectObject(OldPen); pWnd->ReleaseDC(pDc); m_speedin.Format("%d",(int)(nIpin [0]-atoi(strPreIn))); m_speedin+="kb/s"; UpdateData(false); strPreIn=m_sIpin; } #pragma region out if(true) { int i; static double nIpin[200]; CWnd *pWnd=GetDlgItem(IDC_DRAW1); CRect cRect; pWnd->GetClientRect(&cRect); CDC *pDc=pWnd->GetDC(); CBrush newBrush; newBrush.CreateSolidBrush(pDc->GetBkColor()); pDc->FillRect(cRect,&newBrush); pDc->SetMapMode(MM_ANISOTROPIC); pDc->SetViewportExt(cRect.Width(),cRect.Height()); pDc->SetWindowExt(-200,-10); pDc->SetViewportOrg(cRect.Width(),cRect.Height()-1); CPen pPen; pPen.CreatePen(PS_SOLID,1,RGB(255,0,0)); CPen* OldPen=(CPen*)pDc->SelectObject(&pPen); Start(); for(i=200;i>0;i--) nIpout[i]=nIpout[i-1]; nIpout[0]=atoi(m_sIpout); //nIpin[m_nCount+1]=nIpin[m_nCount]; int j; for(i=0;i<=m_nCount1&&i<200;i++) { if((j=(nIpout[i]-nIpout[i+1])*5/m_nTrack)>=10) j=10; if(j<=0) j=0; Draw(i+1,j,pDc); } m_nCount1++; pDc->SelectObject(OldPen); pWnd->ReleaseDC(pDc); m_speedsout.Format ("%d",(int)(nIpout[0]-nIpout[1])); m_speedsout+="kb/s"; UpdateData(false); } WriteLog(); #pragma endregion } else if(nIDEvent==2) { static int i=0; Start(); if(i++>=2) { m_nTrack=m_nIpin-m_preIn; m_nCount=0; m_nCount1=0; SetTimer(1,1000,NULL); KillTimer(2); } m_preIn=m_nIpin; } CDialog::OnTimer(nIDEvent); }
1 下一页