DlgSetupStatusWnd.cpp
上传用户:lds876
上传日期:2013-05-25
资源大小:567k
文件大小:3k
源码类别:

P2P编程

开发平台:

Visual C++

  1. // DlgSetupStatusWnd.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "testbt.h"
  5. #include "DlgSetupStatusWnd.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CDlgSetupStatusWnd
  13. CDlgSetupStatusWnd::CDlgSetupStatusWnd()
  14. {
  15. }
  16. CDlgSetupStatusWnd::~CDlgSetupStatusWnd()
  17. {
  18. }
  19. BEGIN_MESSAGE_MAP(CDlgSetupStatusWnd, CWnd)
  20. //{{AFX_MSG_MAP(CDlgSetupStatusWnd)
  21. ON_WM_PAINT()
  22. ON_WM_CREATE()
  23. ON_WM_ERASEBKGND()
  24. //}}AFX_MSG_MAP
  25. END_MESSAGE_MAP()
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CDlgSetupStatusWnd message handlers
  28. void CDlgSetupStatusWnd::SetStatusText(CString strText)
  29. {
  30. m_strText = strText;
  31. if (GetSafeHwnd()) Invalidate();
  32. }
  33. BOOL CDlgSetupStatusWnd::CreateEx(CWnd *pParent, CRect rc, UINT uID, long lParam)
  34. {
  35. return Create(0, 0, WS_CHILD|WS_BORDER|WS_VISIBLE, rc, pParent, uID);
  36. }
  37. int CDlgSetupStatusWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  38. {
  39. if (CWnd::OnCreate(lpCreateStruct) == -1)
  40. return -1;
  41. m_font.CreateFont(-12, 0, 0, 0, 400, 0, 0, 0, 134, 0, 0, 0, 2, "宋体");
  42. // m_bmpBk.LoadBitmap(IDB_BITMAP_SETUP_DLG_STATUS);
  43. return 0;
  44. }
  45. BOOL CDlgSetupStatusWnd::OnEraseBkgnd(CDC* pDC) 
  46. {
  47. /*
  48. CDC memdc;
  49. memdc.CreateCompatibleDC(pDC);
  50. memdc.SelectObject(m_bmpBk);
  51.     CRect rc;
  52.     pDC->GetClipBox(&rc);
  53. pDC->BitBlt(rc.left, rc.top, rc.Width(), rc.Height(),
  54. &memdc, rc.left, rc.top, SRCCOPY); 
  55.   //*/
  56.     CRect rc;
  57.     pDC->GetClipBox(&rc);
  58. DrawFace(RGB(255, 255, 255), RGB(233, 235, 254), rc, rc, pDC);
  59. return TRUE;
  60. // return CWnd::OnEraseBkgnd(pDC);
  61. }
  62. void CDlgSetupStatusWnd::OnPaint() 
  63. {
  64. CPaintDC dc(this); // device context for painting
  65. CRect rc;
  66.     GetClientRect(rc);
  67. rc.DeflateRect(20, 0);
  68. CFont* pOldFont = dc.SelectObject(&m_font);
  69. dc.SetBkMode(TRANSPARENT);
  70. dc.SetTextColor(RGB(180,180, 180));
  71. dc.DrawText(m_strText, rc, DT_LEFT|DT_VCENTER|DT_SINGLELINE);
  72. dc.SelectObject(pOldFont);
  73. /*
  74. CString strText;
  75. strText.Format("DL:%s/s, UL:%s/s", FormatSize(m_lDownRate).data(), FormatSize(m_lUpRate).data());
  76. CFont* pOldFont = dc.SelectObject(&m_font);
  77. CRect rc;
  78.     GetClientRect(rc);
  79. dc.SetBkMode(TRANSPARENT);
  80. dc.DrawText(strText, rc, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
  81. dc.SelectObject(pOldFont);
  82. //*/
  83. // Do not call CWnd::OnPaint() for painting messages
  84. }
  85. void CDlgSetupStatusWnd::DrawFace(COLORREF Top, COLORREF Bottom, CRect& rc, CRect CalRc, CDC* pDC)
  86. {
  87. if (!CalRc.Height())
  88. return;
  89. int R, G, B;
  90. R = (GetRValue(Top) - GetRValue(Bottom)) / CalRc.Height();
  91. G = (GetGValue(Top) - GetGValue(Bottom)) / CalRc.Height();
  92. B = (GetBValue(Top) - GetBValue(Bottom)) / CalRc.Height();
  93. int ColR = GetRValue(Top), ColG = GetGValue(Top), ColB = GetBValue(Top);
  94. COLORREF ColMax = Top > Bottom ? Top : Bottom;
  95. COLORREF ColMin = Top > Bottom ? Bottom: Top;
  96. for(int i=0; i<rc.Height(); i++)
  97. {
  98. ColR -= R;
  99. ColG -= G;
  100. ColB -= B;
  101. CPen Pen;
  102. Pen.CreatePen(PS_SOLID, 1, RGB(ColR, ColG, ColB));
  103. CPen* pOldPen = pDC->SelectObject(&Pen);
  104. // pDC->SelectObject(&Pen);
  105. pDC->MoveTo(rc.left, rc.top+i);
  106. pDC->LineTo(rc.right, rc.top+i);
  107. pDC->SelectObject(pOldPen);
  108. Pen.DeleteObject();
  109. }
  110. }