home *** CD-ROM | disk | FTP | other *** search
/ Using Visual C++ 4 (Special Edition) / Using_Visual_C_4_Special_Edition_QUE_1996.iso / ch03 / ch3_diag / ch3mview.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-23  |  4.6 KB  |  202 lines

  1. // ch3mView.cpp : implementation of the CChapter03MenuView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "ch3_menu.h"
  6.  
  7. #include "ch3mDoc.h"
  8. #include "ch3mView.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CChapter03MenuView
  18.  
  19. IMPLEMENT_DYNCREATE(CChapter03MenuView, CView)
  20.  
  21. BEGIN_MESSAGE_MAP(CChapter03MenuView, CView)
  22.     //{{AFX_MSG_MAP(CChapter03MenuView)
  23.     ON_COMMAND(ID_TIME_DATETIME, OnTimeDateTime)
  24.     ON_COMMAND(ID_TIME_STARTTIMER, OnTimeStartTimer)
  25.     ON_COMMAND(ID_TIME_STOPTIMER, OnTimeStopTimer)
  26.     ON_WM_LBUTTONDOWN()
  27.     ON_WM_RBUTTONDOWN()
  28.     ON_WM_CHAR()
  29.     ON_WM_MOUSEMOVE()
  30.     ON_WM_TIMER()
  31.     ON_COMMAND(ID_TIME_TIMEDIALOG, OnTimeTimeDialog)
  32.     //}}AFX_MSG_MAP
  33.     // Standard printing commands
  34.     ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  35.     ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  36.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  37. END_MESSAGE_MAP()
  38.  
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CChapter03MenuView construction/destruction
  41.  
  42. CChapter03MenuView::CChapter03MenuView()
  43. {
  44.     // TODO: add construction code here
  45.  
  46. }
  47.  
  48. CChapter03MenuView::~CChapter03MenuView()
  49. {
  50. }
  51.  
  52. BOOL CChapter03MenuView::PreCreateWindow(CREATESTRUCT& cs)
  53. {
  54.     // TODO: Modify the Window class or styles here by modifying
  55.     //  the CREATESTRUCT cs
  56.  
  57.     return CView::PreCreateWindow(cs);
  58. }
  59.  
  60. /////////////////////////////////////////////////////////////////////////////
  61. // CChapter03MenuView drawing
  62.  
  63. void CChapter03MenuView::OnDraw(CDC* pDC)
  64. {
  65.     CChapter03MenuDoc* pDoc = GetDocument();
  66.     ASSERT_VALID(pDoc);
  67.  
  68.     // TODO: add draw code for native data here
  69. }
  70.  
  71. /////////////////////////////////////////////////////////////////////////////
  72. // CChapter03MenuView printing
  73.  
  74. BOOL CChapter03MenuView::OnPreparePrinting(CPrintInfo* pInfo)
  75. {
  76.     // default preparation
  77.     return DoPreparePrinting(pInfo);
  78. }
  79.  
  80. void CChapter03MenuView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  81. {
  82.     // TODO: add extra initialization before printing
  83. }
  84.  
  85. void CChapter03MenuView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  86. {
  87.     // TODO: add cleanup after printing
  88. }
  89.  
  90. /////////////////////////////////////////////////////////////////////////////
  91. // CChapter03MenuView diagnostics
  92.  
  93. #ifdef _DEBUG
  94. void CChapter03MenuView::AssertValid() const
  95. {
  96.     CView::AssertValid();
  97. }
  98.  
  99. void CChapter03MenuView::Dump(CDumpContext& dc) const
  100. {
  101.     CView::Dump(dc);
  102. }
  103.  
  104. CChapter03MenuDoc* CChapter03MenuView::GetDocument() // non-debug version is inline
  105. {
  106.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CChapter03MenuDoc)));
  107.     return (CChapter03MenuDoc*)m_pDocument;
  108. }
  109. #endif //_DEBUG
  110.  
  111. /////////////////////////////////////////////////////////////////////////////
  112. // CChapter03MenuView message handlers
  113.  
  114. void CChapter03MenuView::OnTimeDateTime() 
  115. {
  116.     // display current date/time in long format
  117.     CClientDC dc(this);
  118.     dc.TextOut(10, 40, CTime::GetCurrentTime().Format("%#c"));
  119.     
  120. }
  121.  
  122. void CChapter03MenuView::OnTimeStartTimer() 
  123. {
  124.     // trigger a timer every second
  125.     SetTimer(1, 1000, NULL);
  126. }
  127.  
  128. void CChapter03MenuView::OnTimeStopTimer() 
  129. {
  130.     // just shut it down
  131.     KillTimer(1);
  132. }
  133.  
  134. void CChapter03MenuView::OnLButtonDown(UINT nFlags, CPoint point) 
  135. {
  136.     // display current date/time in standard format
  137.     CClientDC dc(this);
  138.     dc.TextOut(10, 20, CTime::GetCurrentTime().Format("%c"));
  139.  
  140. }
  141.  
  142. void CChapter03MenuView::OnRButtonDown(UINT nFlags, CPoint point) 
  143. {
  144.     // display current date/time in long format
  145.     OnTimeDateTime();
  146.  
  147. }
  148.  
  149. void CChapter03MenuView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
  150. {
  151.     CClientDC dc(this);
  152.     char buffer[200];
  153.     sprintf(buffer, 
  154.         "Char: %c   Repeat Count: %2d   Flags: %08x    ",
  155.         (char)nChar,
  156.         nRepCnt,
  157.         nFlags);
  158.  
  159.     dc.TextOut(10, 60, buffer);
  160.         
  161. }
  162.  
  163. void CChapter03MenuView::OnMouseMove(UINT nFlags, CPoint point) 
  164. {
  165.     // TODO: Add your message handler code here and/or call default
  166.     
  167.     CClientDC dc(this);
  168.     char buffer[200];
  169.     sprintf(buffer, 
  170.         "Mouse: %4d,%4d   Flags: %08x      ",
  171.         point.x,
  172.         point.y,
  173.         nFlags);
  174.  
  175.     dc.TextOut(10, 80, buffer);
  176. }
  177.  
  178. void CChapter03MenuView::OnTimer(UINT nIDEvent) 
  179. {
  180.     static int count = 0;
  181.     count++;
  182.     CClientDC dc(this);
  183.     char buffer[200];
  184.     sprintf(buffer, 
  185.         "Total Timer Count: %4d",
  186.         count);
  187.  
  188.     dc.TextOut(10, 100, buffer);
  189.     OnLButtonDown(0,0);
  190.     OnRButtonDown(0,0);
  191. }
  192.  
  193. #include "TInABox.h"
  194.  
  195. void CChapter03MenuView::OnTimeTimeDialog() 
  196. {
  197.     // TODO: Add your command handler code here
  198.     TimeInABox time_dialog;
  199.     time_dialog.DoModal();
  200.     
  201. }
  202.