home *** CD-ROM | disk | FTP | other *** search
/ Master Visual C++ 1.5 / MASTERVC15.ISO / vcprog / original / ch26 / mytimer / mytimvw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-03  |  2.7 KB  |  127 lines

  1. // mytimvw.cpp : implementation of the CMytimerView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "mytimer.h"
  6.  
  7. #include "mytimdoc.h"
  8. #include "mytimvw.h"
  9.  
  10. #ifdef _DEBUG
  11. #undef THIS_FILE
  12. static char BASED_CODE THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CMytimerView
  17.  
  18. IMPLEMENT_DYNCREATE(CMytimerView, CView)
  19.  
  20. BEGIN_MESSAGE_MAP(CMytimerView, CView)
  21.     //{{AFX_MSG_MAP(CMytimerView)
  22.     ON_WM_CREATE()
  23.     ON_WM_TIMER()
  24.     //}}AFX_MSG_MAP
  25. END_MESSAGE_MAP()
  26.  
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CMytimerView construction/destruction
  29.  
  30. CMytimerView::CMytimerView()
  31. {
  32.     // TODO: add construction code here
  33. }
  34.  
  35. CMytimerView::~CMytimerView()
  36. {
  37. }
  38.  
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CMytimerView drawing
  41.  
  42. void CMytimerView::OnDraw(CDC* pDC)
  43. {
  44.     CMytimerDoc* pDoc = GetDocument();
  45.     ASSERT_VALID(pDoc);
  46.  
  47.     // TODO: add draw code for native data here
  48. }
  49.  
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CMytimerView diagnostics
  52.  
  53. #ifdef _DEBUG
  54. void CMytimerView::AssertValid() const
  55. {
  56.     CView::AssertValid();
  57. }
  58.  
  59. void CMytimerView::Dump(CDumpContext& dc) const
  60. {
  61.     CView::Dump(dc);
  62. }
  63.  
  64. CMytimerDoc* CMytimerView::GetDocument() // non-debug version is inline
  65. {
  66.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMytimerDoc)));
  67.     return (CMytimerDoc*)m_pDocument;
  68. }
  69. #endif //_DEBUG
  70.  
  71. /////////////////////////////////////////////////////////////////////////////
  72. // CMytimerView message handlers
  73.  
  74. int CMytimerView::OnCreate(LPCREATESTRUCT lpCreateStruct)
  75. {
  76.     if (CView::OnCreate(lpCreateStruct) == -1)
  77.         return -1;
  78.     
  79.     // TODO: Add your specialized creation code here
  80.  
  81.  
  82.     //////////////////////
  83.     // MY CODE STARTS HERE
  84.     //////////////////////
  85.   
  86.    // Install a system timer with 500 milliseconds interval.
  87.    if ( SetTimer (1, 500, NULL) == 0 )
  88.         MessageBox ("Cannot install timer!!!");
  89.    
  90.     ////////////////////
  91.     // MY CODE ENDS HERE
  92.     ////////////////////
  93.  
  94.     
  95.     return 0;
  96. }
  97.  
  98. void CMytimerView::OnTimer(UINT nIDEvent)
  99. {
  100. // TODO: Add your message handler code here and/or call default
  101.  
  102.      ///////////////////////
  103.      // MY CODE STARTS HERE
  104.      //////////////////////
  105.  
  106.      //MessageBeep(-1);
  107.  
  108.      // Create an object of class CTime.
  109.      CTime tNow;
  110.  
  111.      // Update tNow with the current time.
  112.      tNow =  CTime::GetCurrentTime();
  113.  
  114.      // Format the current time.
  115.      CString sNow = tNow.Format("%I:%M:%S %p");
  116.  
  117.      // Display the current time.
  118.      CClientDC dc(this);
  119.      dc.TextOut(15,15,sNow);
  120.  
  121.      ////////////////////
  122.      // MY CODE ENDS HERE
  123.      ////////////////////
  124.     
  125.     CView::OnTimer(nIDEvent);
  126. }
  127.