home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / samples / c05 / menus1 / menuview.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  2.6 KB  |  127 lines

  1. // MenuView.cpp : implementation of the CMenus1View class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Menus1.h"
  6.  
  7. #include "Menu1Doc.h"
  8. #include "MenuView.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. const COLORREF BLACK=RGB(0,0,0);
  17. const COLORREF RED=RGB(255,0,0);
  18. const COLORREF GREEN=RGB(0,255,0);
  19. const COLORREF BLUE=RGB(0,0,255);
  20.  
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CMenus1View
  23.  
  24. IMPLEMENT_DYNCREATE(CMenus1View, CView)
  25.  
  26. BEGIN_MESSAGE_MAP(CMenus1View, CView)
  27.     //{{AFX_MSG_MAP(CMenus1View)
  28.     ON_COMMAND(ID_COLORS_BLACK, OnColorsBlack)
  29.     ON_COMMAND(ID_COLORS_BLUE, OnColorsBlue)
  30.     ON_COMMAND(ID_COLORS_GREEN, OnColorsGreen)
  31.     ON_COMMAND(ID_COLORS_RED, OnColorsRed)
  32.     //}}AFX_MSG_MAP
  33. END_MESSAGE_MAP()
  34.  
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CMenus1View construction/destruction
  37.  
  38. CMenus1View::CMenus1View()
  39. {
  40. }
  41.  
  42. CMenus1View::~CMenus1View()
  43. {
  44. }
  45.  
  46. BOOL CMenus1View::PreCreateWindow(CREATESTRUCT& cs)
  47. {
  48.     return CView::PreCreateWindow(cs);
  49. }
  50.  
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CMenus1View drawing
  53.  
  54. void CMenus1View::OnDraw(CDC* pDC)
  55. {
  56.     CMenus1Doc* pDoc = GetDocument();
  57.     ASSERT_VALID(pDoc);
  58.  
  59.     CRect r;
  60.     GetClientRect(&r);
  61.     int x = r.right / 2, y = r.bottom / 2;
  62.  
  63.     pDC->SetTextColor(pDoc->GetColor());
  64.     pDC->SetTextAlign (TA_CENTER | TA_BASELINE);
  65.     pDC->TextOut (x, y, pDoc->GetPhrase());
  66. }
  67.  
  68. /////////////////////////////////////////////////////////////////////////////
  69. // CMenus1View diagnostics
  70.  
  71. #ifdef _DEBUG
  72. void CMenus1View::AssertValid() const
  73. {
  74.     CView::AssertValid();
  75. }
  76.  
  77. void CMenus1View::Dump(CDumpContext& dc) const
  78. {
  79.     CView::Dump(dc);
  80. }
  81.  
  82. CMenus1Doc* CMenus1View::GetDocument() // non-debug version is inline
  83. {
  84.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMenus1Doc)));
  85.     return (CMenus1Doc*)m_pDocument;
  86. }
  87. #endif //_DEBUG
  88.  
  89. /////////////////////////////////////////////////////////////////////////////
  90. // CMenus1View message handlers
  91.  
  92. void CMenus1View::OnColorsBlack() 
  93. {
  94.     CMenus1Doc* pDoc = GetDocument();
  95.     ASSERT_VALID(pDoc);
  96.  
  97.     pDoc->SetColor(BLACK);
  98.     Invalidate();
  99. }
  100.  
  101. void CMenus1View::OnColorsBlue() 
  102. {
  103.     CMenus1Doc* pDoc = GetDocument();
  104.     ASSERT_VALID(pDoc);
  105.  
  106.     pDoc->SetColor(BLUE);
  107.     Invalidate();
  108. }
  109.  
  110. void CMenus1View::OnColorsGreen() 
  111. {
  112.     CMenus1Doc* pDoc = GetDocument();
  113.     ASSERT_VALID(pDoc);
  114.  
  115.     pDoc->SetColor(GREEN);
  116.     Invalidate();
  117. }
  118.  
  119. void CMenus1View::OnColorsRed() 
  120. {
  121.     CMenus1Doc* pDoc = GetDocument();
  122.     ASSERT_VALID(pDoc);
  123.  
  124.     pDoc->SetColor(RED);
  125.     Invalidate();
  126. }
  127.