home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / labs / c05 / lab06 / baseline / progress.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  3.5 KB  |  152 lines

  1. // Progress.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "diff.h"
  6. #include "Progress.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CProgressStatusBar
  16.  
  17. CProgressStatusBar::CProgressStatusBar()
  18. {
  19.     m_bProgressMode = FALSE;
  20.     m_nProgressCtrlWidth = PROGRESS_CTRL_CX;
  21. }
  22.  
  23. CProgressStatusBar::~CProgressStatusBar()
  24. {
  25. }
  26.  
  27. void CProgressStatusBar::SetProgressCtrlWidth(UINT nWidth /*= PROGRESS_CTRL_CX*/)
  28. {
  29.     m_nProgressCtrlWidth = nWidth;
  30. }
  31.  
  32. void CProgressStatusBar::RecalcProgressDisplay()
  33. {
  34.     //    Adjust the postions of the Label and Progress Controls
  35.     //    Place the Label Control to the right of the 
  36.     //    Progress Control
  37.     //
  38.     //        [Progress Control] Label Text... 
  39.     
  40.     CRect ControlRect;
  41.     CRect ClientRect;
  42.     GetClientRect(&ClientRect);
  43.     ControlRect = ClientRect; 
  44.     
  45.     //    First the Progress bar
  46.     
  47.     ControlRect.left += X_MARGIN;
  48.     ControlRect.right = ControlRect.left + m_nProgressCtrlWidth;
  49.     ControlRect.top += Y_MARGIN;
  50.     ControlRect.bottom -= Y_MARGIN;
  51.     
  52.     m_ProgressCtrl.MoveWindow(ControlRect, FALSE);
  53.     
  54.     //    Then the text label using the rest of the status
  55.     //    bars client area
  56.     
  57.     ControlRect.left = ControlRect.right + X_MARGIN;
  58.     ControlRect.right = ClientRect.right - X_MARGIN;
  59.  
  60.     m_ProgressLabel.MoveWindow(ControlRect, FALSE);
  61. }
  62.  
  63. void CProgressStatusBar::SetProgressLabel(LPCSTR 
  64.                                                 lpszProgressLabel)
  65. {
  66.     
  67.     m_ProgressLabel.SetWindowText(lpszProgressLabel);
  68.  
  69.     //  If were currently displaying progress, update 
  70.     //    placement of label and progress control
  71.     
  72.     if(m_bProgressMode)
  73.     {
  74.         RecalcProgressDisplay();
  75.         Invalidate();
  76.         UpdateWindow();
  77.     }
  78. }
  79.  
  80. void CProgressStatusBar::ShowProgressDisplay(BOOL bShow)
  81. {
  82.     m_bProgressMode = bShow;
  83.     if(m_bProgressMode)
  84.     {
  85.         RecalcProgressDisplay();
  86.     }
  87.     m_ProgressLabel.ShowWindow(m_bProgressMode ?     SW_SHOW :
  88.                                                     SW_HIDE);
  89.     m_ProgressCtrl.ShowWindow (m_bProgressMode ?     SW_SHOW :
  90.                                                     SW_HIDE);
  91.     Invalidate();
  92.     UpdateWindow();
  93. }
  94.  
  95.  
  96. BEGIN_MESSAGE_MAP(CProgressStatusBar, CStatusBar)
  97.     //{{AFX_MSG_MAP(CProgressStatusBar)
  98.     ON_WM_CREATE()
  99.     ON_WM_PAINT()
  100.     //}}AFX_MSG_MAP
  101. END_MESSAGE_MAP()
  102.  
  103.  
  104. /////////////////////////////////////////////////////////////////////////////
  105. // CProgressStatusBar message handlers
  106.  
  107. int CProgressStatusBar::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  108. {
  109.     if (CStatusBar::OnCreate(lpCreateStruct) == -1)
  110.         return -1;
  111.     
  112.     //     Create the Progress Control - we'll calculate its size and
  113.     //    position later - in response to a ShowProgressDisplay() call.
  114.     
  115.     if(!m_ProgressCtrl.Create(    0,                 // Style - Don't Show Position or Percent
  116.                                 CRect(0,0,0,0),    // Initial position
  117.                                 this,            // Parent
  118.                                 0))                // Child ID
  119.     {
  120.         return -1;
  121.     }
  122.  
  123.     //     Create the Progress Label - we'll calculate its size and
  124.     //    position later - in response to a ShowProgressDisplay() call.
  125.     
  126.     if(!m_ProgressLabel.Create(    NULL,                // Text
  127.                                 WS_CHILD|SS_LEFT,     // Style
  128.                                 CRect(0,0,0,0),        // Initial position
  129.                                 this))                // Parent
  130.     {
  131.         return -1;
  132.     }
  133.     
  134.     //    Use the same font as the Status Bar
  135.     
  136.     m_ProgressLabel.SetFont(GetFont());
  137.     
  138.     return 0;
  139. }
  140.  
  141. void CProgressStatusBar::OnPaint() 
  142. {
  143.     //    If we were displaying the progress control, then we
  144.      //    need to handle painting of the Status Bar,
  145.     //    otherwise defer to the base class
  146.     
  147.     if(!m_bProgressMode)
  148.     {
  149.         CStatusBar::OnPaint();
  150.     }
  151. }
  152.