MonitorSpeedWnd.cpp
资源名称:GGBT.rar [点击查看]
上传用户:lds876
上传日期:2013-05-25
资源大小:567k
文件大小:4k
源码类别:
P2P编程
开发平台:
Visual C++
- // MonitorSpeedWnd.cpp : implementation file
- //
- #include "stdafx.h"
- #include "testbt.h"
- #include "MonitorSpeedWnd.h"
- #include "FileBase.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #define DISPLAY_TIMEOUT_ID 2
- /////////////////////////////////////////////////////////////////////////////
- // CMonitorSpeedWnd
- CMonitorSpeedWnd::CMonitorSpeedWnd()
- {
- m_pCategoryDownload = 0;
- }
- CMonitorSpeedWnd::~CMonitorSpeedWnd()
- {
- }
- BEGIN_MESSAGE_MAP(CMonitorSpeedWnd, CWnd)
- //{{AFX_MSG_MAP(CMonitorSpeedWnd)
- ON_WM_PAINT()
- ON_WM_TIMER()
- ON_WM_CREATE()
- ON_WM_ERASEBKGND()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMonitorSpeedWnd message handlers
- BOOL CMonitorSpeedWnd::CreateEx(CWnd *pParent, CRect rc, UINT uID, long lParam, CCategoryDownload* pCategoryDownload)
- {
- ASSERT(pCategoryDownload);
- m_pCategoryDownload = pCategoryDownload;
- CMonitorSpeedbase::CreateEx(pCategoryDownload, 10);
- return Create(0, 0, WS_CHILD|WS_BORDER|WS_VISIBLE, rc, pParent, uID);
- }
- int CMonitorSpeedWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
- BOOL bRet = SetTimer(DISPLAY_TIMEOUT_ID, 1000, 0);
- ASSERT(bRet);
- // m_bmpBk.LoadBitmap(IDB_BITMAP_MONITOR_SPEED_BK);
- return 0;
- }
- BOOL CMonitorSpeedWnd::OnEraseBkgnd(CDC* pDC)
- {
- CRect rc;
- pDC->GetClipBox(&rc);
- DrawFace(RGB(255, 255, 255), RGB(213, 232, 245), rc, rc, pDC);
- return TRUE;
- return CWnd::OnEraseBkgnd(pDC);
- }
- void CMonitorSpeedWnd::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
- CRect rc;
- GetClientRect(rc);
- CMonitorSpeedbase::OnPaint(dc, rc, false);
- /*
- CRect rcText = rc;
- rcText.bottom = rcText .top + 10;
- CRect rcUp = rc;
- rcUp.top += 10;
- rcUp.right = rcUp.left + rcUp.Width()/2;
- int iVisibleCount = rcUp.Width()/m_lGridWidth;
- long lMax = 5;
- long lRet = GetMaxValue(m_lValueUp, iVisibleCount);
- if (lRet > lMax ) lMax = lRet;
- lRet = GetMaxValue(m_lValueDown, iVisibleCount);
- if (lRet > lMax ) lMax = lRet;
- lMax = (lMax/5 + 1) * 5;
- assert (lMax > 0);
- CString strText;
- // strText.Format("D:%s/s, U:%s/s", FormatSize(m_lDownRate).data(), FormatSize(m_lUpRate).data());
- strText.Format("%dK/S", lMax);
- CFont* pOldFont = dc.SelectObject(&m_font);
- dc.SetBkMode(TRANSPARENT);
- dc.DrawText(strText, rcText, DT_RIGHT|DT_VCENTER|DT_SINGLELINE);
- dc.SelectObject(pOldFont);
- DrawLine(m_lValueDown, dc, RGB(125, 172, 249), rcUp, lMax , iVisibleCount);
- rcUp.OffsetRect(rcUp.Width(), 0);
- DrawLine(m_lValueUp, dc, RGB(249, 152, 111), rcUp, lMax, iVisibleCount);
- //*/
- // Do not call CWnd::OnPaint() for painting messages
- }
- void CMonitorSpeedWnd::OnTimer(UINT nIDEvent)
- {
- if (DISPLAY_TIMEOUT_ID != nIDEvent)
- return;
- CMonitorSpeedbase::OnTimer();
- Invalidate();
- // CWnd::OnTimer(nIDEvent);
- }
- void CMonitorSpeedWnd::DrawFace(COLORREF Top, COLORREF Bottom, CRect& rc, CRect CalRc, CDC* pDC)
- {
- if (!CalRc.Height())
- return;
- int R, G, B;
- R = (GetRValue(Top) - GetRValue(Bottom)) / CalRc.Height();
- G = (GetGValue(Top) - GetGValue(Bottom)) / CalRc.Height();
- B = (GetBValue(Top) - GetBValue(Bottom)) / CalRc.Height();
- int ColR = GetRValue(Top), ColG = GetGValue(Top), ColB = GetBValue(Top);
- COLORREF ColMax = Top > Bottom ? Top : Bottom;
- COLORREF ColMin = Top > Bottom ? Bottom: Top;
- for(int i=0; i<rc.Height(); i++)
- {
- ColR -= R;
- ColG -= G;
- ColB -= B;
- CPen Pen;
- Pen.CreatePen(PS_SOLID, 1, RGB(ColR, ColG, ColB));
- CPen* pOldPen = pDC->SelectObject(&Pen);
- // pDC->SelectObject(&Pen);
- pDC->MoveTo(rc.left, rc.top+i);
- pDC->LineTo(rc.right, rc.top+i);
- pDC->SelectObject(pOldPen);
- Pen.DeleteObject();
- }
- }