BitMapProgress.cpp
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:3k
源码类别:

模拟服务器

开发平台:

C/C++

  1. // BitMapProgress.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "autoupdate.h"
  5. #include "BitMapProgress.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // BitMapProgress
  13. BitMapProgress::BitMapProgress()
  14. :m_BackColor(0)
  15. {
  16. }
  17. BitMapProgress::~BitMapProgress()
  18. {
  19. }
  20. BEGIN_MESSAGE_MAP(BitMapProgress, CProgressCtrl)
  21. //{{AFX_MSG_MAP(BitMapProgress)
  22. ON_WM_PAINT()
  23. ON_WM_NCPAINT()
  24. //}}AFX_MSG_MAP
  25. END_MESSAGE_MAP()
  26. /////////////////////////////////////////////////////////////////////////////
  27. // BitMapProgress message handlers
  28. void BitMapProgress::OnPaint() 
  29. {
  30. CPaintDC dc(this); // device context for painting
  31. // TODO: Add your message handler code here
  32. //进度条的上下文环境句柄
  33. int pos=GetPos();
  34. int low,hight;
  35. low=hight=0;
  36. GetRange(low,hight);
  37. int range=hight-low;
  38. //得到当前进度(%)
  39. float percent=float(pos)/(float)range;
  40. CRect rect;
  41. GetClientRect(&rect);
  42. dc.FillSolidRect(&rect,m_BackColor);
  43. rect.right=rect.left+percent*rect.Width();
  44.     
  45. //根据进度填充矩形
  46. if((HBITMAP)m_cbForeground != NULL)
  47. {
  48. HDC memdc = CreateCompatibleDC(dc.GetSafeHdc());
  49. HBITMAP h = (HBITMAP)SelectObject(memdc, m_cbForeground);
  50.     BITMAP bm;
  51. m_cbForeground.GetBitmap(&bm);
  52. CRect ForegroundRect;
  53. ForegroundRect.left = 0;
  54.         ForegroundRect.top = 0;
  55.         ForegroundRect.bottom = bm.bmHeight;
  56. ForegroundRect.right =ForegroundRect.left + percent * bm.bmWidth; 
  57.          
  58. StretchBlt(dc.GetSafeHdc(), rect.left, rect.top, rect.right , rect.bottom, memdc, ForegroundRect.left, ForegroundRect.top,ForegroundRect.right  ,ForegroundRect.bottom, SRCCOPY);
  59. SelectObject(memdc,h);
  60. DeleteDC(memdc);
  61. }
  62. else
  63. {
  64. dc.FillSolidRect(&rect,RGB(0,255,0));
  65. }// Do not call CProgressCtrl::OnPaint() for painting messages
  66. }
  67. void BitMapProgress::SetForegroundBmp(UINT ForegroundBmpID)
  68. {
  69. if((HBITMAP)m_cbForeground)
  70. {
  71. if(!m_cbForeground.DeleteObject())
  72. {
  73. DisplayErrorInfo(string("DeleteObject"));
  74. }
  75. }
  76. if(!m_cbForeground.LoadBitmap(ForegroundBmpID))
  77. {
  78. DisplayErrorInfo(string("LoadBitmap"));
  79. }
  80. }
  81. void BitMapProgress::SetBackColor(COLORREF BackColor)
  82. {
  83. m_BackColor = BackColor;
  84. }
  85. void BitMapProgress::OnNcPaint() 
  86. {
  87. // TODO: Add your message handler code here
  88. // Do not call CProgressCtrl::OnNcPaint() for painting messages
  89. }