home *** CD-ROM | disk | FTP | other *** search
/ Mastering Microsoft Visual C++ 4 (2nd Edition) / VisualC4.ISO / tabdemo / tabdemvw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-30  |  3.6 KB  |  144 lines

  1. // TabDemVw.cpp : implementation of the CTabDemoView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "TabDemo.h"
  6.  
  7. #include "TabDeDoc.h"
  8. #include "TabDemVw.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. // CTabDemoView
  18.  
  19. IMPLEMENT_DYNCREATE(CTabDemoView, CView)
  20.  
  21. BEGIN_MESSAGE_MAP(CTabDemoView, CView)
  22.    //{{AFX_MSG_MAP(CTabDemoView)
  23.       // NOTE - the ClassWizard will add and remove mapping macros here.
  24.       //    DO NOT EDIT what you see in these blocks of generated code!
  25.    //}}AFX_MSG_MAP
  26. END_MESSAGE_MAP()
  27.  
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CTabDemoView construction/destruction
  30.  
  31. CTabDemoView::CTabDemoView()
  32. {
  33.    // TODO: add construction code here
  34.  
  35. }
  36.  
  37. CTabDemoView::~CTabDemoView()
  38. {
  39. }
  40.  
  41. BOOL CTabDemoView::PreCreateWindow(CREATESTRUCT& cs)
  42. {
  43.    // TODO: Modify the Window class or styles here by modifying
  44.    //  the CREATESTRUCT cs
  45.  
  46.    return CView::PreCreateWindow(cs);
  47. }
  48.  
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CTabDemoView drawing
  51.  
  52. void CTabDemoView::OnDraw(CDC* pDC)
  53. {
  54.    CTabDemoDoc* pDoc = GetDocument();
  55.    ASSERT_VALID(pDoc);
  56.  
  57.    // TODO: add draw code for native data here
  58.  
  59.    RECT ClientRect;   
  60.    CFont Font;
  61.    LOGFONT LF;
  62.    int LineHeight;
  63.    CFont *PtrOldFont;
  64.    int X, Y;
  65.  
  66.    // fill LF with the features of a standard system font:
  67.    CFont TempFont;
  68.    if (pDoc->m_Pitch == PITCH_VARIABLE)  
  69.       TempFont.CreateStockObject (SYSTEM_FONT);
  70.    else
  71.       TempFont.CreateStockObject (SYSTEM_FIXED_FONT);
  72.    TempFont.GetObject (sizeof (LOGFONT), &LF);
  73.  
  74.    // now customize lfWeight, lfItalic, and lfUnderline fields:
  75.    if (pDoc->m_Bold)
  76.       LF.lfWeight = FW_BOLD;
  77.    if (pDoc->m_Italic)
  78.       LF.lfItalic = 1;
  79.    if (pDoc->m_Underline)
  80.       LF.lfUnderline = 1;
  81.  
  82.    // create and select font:
  83.    Font.CreateFontIndirect (&LF);
  84.    PtrOldFont = pDC->SelectObject (&Font);
  85.    
  86.    // set justification:
  87.    GetClientRect (&ClientRect);
  88.    switch (pDoc->m_Justify)
  89.       {
  90.       case JUSTIFY_LEFT:
  91.          pDC->SetTextAlign (TA_LEFT);
  92.          X = ClientRect.left + 5;      
  93.          break;
  94.       case JUSTIFY_CENTER:
  95.          pDC->SetTextAlign (TA_CENTER);
  96.          X = ClientRect.right / 2;
  97.          break;
  98.       case JUSTIFY_RIGHT:
  99.          pDC->SetTextAlign (TA_RIGHT);
  100.          X = ClientRect.right - 5;      
  101.          break;         
  102.       }
  103.    
  104.    // set text color and background mode:
  105.    pDC->SetTextColor (::GetSysColor (COLOR_WINDOWTEXT));
  106.    pDC->SetBkMode (TRANSPARENT);
  107.    
  108.    // draw lines:
  109.    LineHeight = LF.lfHeight * pDoc->m_Spacing;
  110.    Y = 5;
  111.    pDC->TextOut (X, Y, "This is the first line of sample text.");
  112.    Y += LineHeight;
  113.    pDC->TextOut (X, Y, "This is the second line of sample text.");
  114.    Y += LineHeight;
  115.    pDC->TextOut (X, Y, "This is the third line of sample text.");
  116.    
  117.    // unselect font:
  118.    pDC->SelectObject (PtrOldFont);
  119. }
  120.  
  121. /////////////////////////////////////////////////////////////////////////////
  122. // CTabDemoView diagnostics
  123.  
  124. #ifdef _DEBUG
  125. void CTabDemoView::AssertValid() const
  126. {
  127.    CView::AssertValid();
  128. }
  129.  
  130. void CTabDemoView::Dump(CDumpContext& dc) const
  131. {
  132.    CView::Dump(dc);
  133. }
  134.  
  135. CTabDemoDoc* CTabDemoView::GetDocument() // non-debug version is inline
  136. {
  137.    ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTabDemoDoc)));
  138.    return (CTabDemoDoc*)m_pDocument;
  139. }
  140. #endif //_DEBUG
  141.  
  142. /////////////////////////////////////////////////////////////////////////////
  143. // CTabDemoView message handlers
  144.