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

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