home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / labs / c11 / lab04 / ex02 / baseline / gpsrcview.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  3.0 KB  |  137 lines

  1. // gpsrcView.cpp : implementation of the CGpsrcView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "gpsrc.h"
  6.  
  7. #include "gpsrcDoc.h"
  8. #include "gpsrcView.h"
  9.  
  10.  
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CGpsrcView
  19.  
  20. IMPLEMENT_DYNCREATE(CGpsrcView, CScrollView)
  21.  
  22. BEGIN_MESSAGE_MAP(CGpsrcView, CScrollView)
  23.     //{{AFX_MSG_MAP(CGpsrcView)
  24.     ON_WM_CREATE()
  25.     ON_COMMAND(ID_VIEW_CLEAR, OnViewClear)
  26.     //}}AFX_MSG_MAP
  27. END_MESSAGE_MAP()
  28.  
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CGpsrcView construction/destruction
  31.  
  32. CGpsrcView::CGpsrcView()
  33. {
  34.     // TODO: add construction code here
  35.  
  36. }
  37.  
  38. CGpsrcView::~CGpsrcView()
  39. {
  40. }
  41.  
  42. BOOL CGpsrcView::PreCreateWindow(CREATESTRUCT& cs)
  43. {
  44.     // TODO: Modify the Window class or styles here by modifying
  45.     //  the CREATESTRUCT cs
  46.  
  47.     return CScrollView::PreCreateWindow(cs);
  48. }
  49.  
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CGpsrcView drawing
  52.  
  53. void CGpsrcView::OnDraw(CDC* pDC)
  54. {
  55.     CGpsrcDoc* pDoc = GetDocument();
  56.     ASSERT_VALID(pDoc);
  57.  
  58.     // TODO: add draw code for native data here
  59.         // jh:  set scroll size based upon number of strings in document.
  60.     CStringArray& strings= GetDocument()->m_strings;
  61.     CSize sizeTotal;
  62.     sizeTotal.cx = 100;
  63.     TEXTMETRIC tm;
  64.     pDC->GetTextMetrics(&tm);
  65.     sizeTotal.cy = tm.tmHeight*strings.GetSize();
  66.     SetScrollSizes(MM_TEXT, sizeTotal);
  67.  
  68.     for (int idx=0; idx<strings.GetSize(); idx++) {
  69.         CString str;
  70.         str.Format("%d: %s", idx, strings.GetAt(idx));
  71.         pDC->TabbedTextOut(0,idx*tm.tmHeight,str,0,NULL,0);
  72.     }
  73.  
  74. }
  75.  
  76. void CGpsrcView::OnInitialUpdate()
  77. {
  78.     CScrollView::OnInitialUpdate();
  79.     CSize sizeTotal;
  80.     // TODO: calculate the total size of this view
  81.     sizeTotal.cx = sizeTotal.cy = 100;
  82.     SetScrollSizes(MM_TEXT, sizeTotal);
  83. }
  84.  
  85. /////////////////////////////////////////////////////////////////////////////
  86. // CGpsrcView diagnostics
  87.  
  88. #ifdef _DEBUG
  89. void CGpsrcView::AssertValid() const
  90. {
  91.     CScrollView::AssertValid();
  92. }
  93.  
  94. void CGpsrcView::Dump(CDumpContext& dc) const
  95. {
  96.     CScrollView::Dump(dc);
  97. }
  98.  
  99. CGpsrcDoc* CGpsrcView::GetDocument() // non-debug version is inline
  100. {
  101.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGpsrcDoc)));
  102.     return (CGpsrcDoc*)m_pDocument;
  103. }
  104. #endif //_DEBUG
  105.  
  106. /////////////////////////////////////////////////////////////////////////////
  107. // CGpsrcView message handlers
  108. // Timer 
  109. void CALLBACK EXPORT TimerProc(
  110.    HWND hWnd,      //handle of CWnd that called SetTimer
  111.    UINT nMsg,      //WM_TIMER
  112.    UINT nIDEvent,   //timer identification
  113.    DWORD dwTime   //system time
  114. )
  115. {
  116.  
  117. }
  118.  
  119.  
  120.  
  121. int CGpsrcView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  122. {
  123.     if (CScrollView::OnCreate(lpCreateStruct) == -1)
  124.         return -1;
  125.     
  126.     // TODO: Add your specialized creation code here
  127.  
  128.     return 0;
  129. }
  130.  
  131. void CGpsrcView::OnViewClear() 
  132. {
  133.     // TODO: Add your command handler code here
  134.     GetDocument()->DeleteContents();
  135.     
  136. }
  137.