home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / samples / c07 / mdi2viewsb / italicsview.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  2.2 KB  |  99 lines

  1. // ItalicsView.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "MDI2ViewsB.h"
  6.  
  7. #include "MDI2ViewsBDoc.h"
  8. #include "ItalicsView.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. // CItalicsView
  18.  
  19. IMPLEMENT_DYNCREATE(CItalicsView, CView)
  20.  
  21. CItalicsView::CItalicsView()
  22. {
  23. }
  24.  
  25. CItalicsView::~CItalicsView()
  26. {
  27. }
  28.  
  29.  
  30. BEGIN_MESSAGE_MAP(CItalicsView, CView)
  31.     //{{AFX_MSG_MAP(CItalicsView)
  32.         // NOTE - the ClassWizard will add and remove mapping macros here.
  33.     //}}AFX_MSG_MAP
  34. END_MESSAGE_MAP()
  35.  
  36. /////////////////////////////////////////////////////////////////////////////
  37. // CItalicsView drawing
  38.  
  39. void CItalicsView::OnDraw(CDC* pDC)
  40. {
  41.     CMDI2ViewsBDoc* pDoc = GetDocument();
  42.     ASSERT_VALID(pDoc);
  43.  
  44.     CFont * pOldFont, tempFont;
  45.     LOGFONT lf;  
  46.  
  47.     // Obtain a pointer to the current font.
  48.     pOldFont = pDC->GetCurrentFont();
  49.     
  50.     // Fill this function's LOGFONT object with the current font.
  51.     pOldFont->GetLogFont(&lf);
  52.     
  53.     // Make the desired modification(s).
  54.     lf.lfItalic = TRUE;
  55.  
  56.     // Fill this function's CFont object with the logfont.
  57.     tempFont.CreateFontIndirect(&lf);
  58.  
  59.     // Select the new font object into the device context.
  60.     pOldFont = (CFont *) pDC->SelectObject(&tempFont);
  61.  
  62.     CRect rect;
  63.     GetClientRect(&rect);
  64.     int x = rect.Width() / 2;
  65.     int y = rect.Height() / 2;
  66.  
  67.     pDC->SetTextColor(pDoc->GetColor());
  68.     pDC->SetTextAlign (TA_CENTER | TA_BASELINE);
  69.     pDC->TextOut (x, y, pDoc->GetPhrase());
  70.  
  71.     // Restore the font that existed at the beginning of this function.
  72.     pDC->SelectObject(pOldFont);
  73. }
  74.  
  75. /////////////////////////////////////////////////////////////////////////////
  76. // CItalicsView diagnostics
  77.  
  78. #ifdef _DEBUG
  79. void CItalicsView::AssertValid() const
  80. {
  81.     CView::AssertValid();
  82. }
  83.  
  84. void CItalicsView::Dump(CDumpContext& dc) const
  85. {
  86.     CView::Dump(dc);
  87. }
  88.  
  89. CMDI2ViewsBDoc* CItalicsView::GetDocument() // non-debug version is inline
  90. {
  91.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMDI2ViewsBDoc)));
  92.     return (CMDI2ViewsBDoc*)m_pDocument;
  93. }
  94.  
  95. #endif //_DEBUG
  96.  
  97. /////////////////////////////////////////////////////////////////////////////
  98. // CItalicsView message handlers
  99.