home *** CD-ROM | disk | FTP | other *** search
- // Menus3View.cpp : implementation of the CMenus3View class
- //
-
- #include "stdafx.h"
- #include "Menus3.h"
-
- #include "Menus3Doc.h"
- #include "Menus3View.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- const COLORREF BLACK=RGB(0,0,0);
- const COLORREF RED=RGB(255,0,0);
- const COLORREF GREEN=RGB(0,255,0);
- const COLORREF BLUE=RGB(0,0,255);
-
- /////////////////////////////////////////////////////////////////////////////
- // CMenus3View
-
- IMPLEMENT_DYNCREATE(CMenus3View, CView)
-
- BEGIN_MESSAGE_MAP(CMenus3View, CView)
- //{{AFX_MSG_MAP(CMenus3View)
- ON_COMMAND(ID_COLORS_BLACK, OnColors)
- ON_COMMAND(ID_COLORS_BLUE, OnColors)
- ON_COMMAND(ID_COLORS_GREEN, OnColors)
- ON_COMMAND(ID_COLORS_RED, OnColors)
- ON_UPDATE_COMMAND_UI(ID_COLORS_BLACK, OnUpdateColors)
- ON_UPDATE_COMMAND_UI(ID_COLORS_BLUE, OnUpdateColors)
- ON_UPDATE_COMMAND_UI(ID_COLORS_GREEN, OnUpdateColors)
- ON_UPDATE_COMMAND_UI(ID_COLORS_RED, OnUpdateColors)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CMenus3View construction/destruction
-
- CMenus3View::CMenus3View()
- {
- // TODO: add construction code here
-
- }
-
- CMenus3View::~CMenus3View()
- {
- }
-
- BOOL CMenus3View::PreCreateWindow(CREATESTRUCT& cs)
- {
- return CView::PreCreateWindow(cs);
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CMenus3View drawing
-
- void CMenus3View::OnDraw(CDC* pDC)
- {
- CMenus3Doc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
-
- CRect r;
- GetClientRect(&r);
- int x = r.right / 2, y = r.bottom / 2;
-
- pDC->SetTextColor(pDoc->GetColor());
- pDC->SetTextAlign (TA_CENTER | TA_BASELINE);
- pDC->TextOut (x, y, pDoc->GetPhrase());
- }
-
- ////////////////////////////////////////////////////////////////////////////
- // CMenus3View diagnostics
-
- #ifdef _DEBUG
- void CMenus3View::AssertValid() const
- {
- CView::AssertValid();
- }
-
- void CMenus3View::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
-
- CMenus3Doc* CMenus3View::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMenus3Doc)));
- return (CMenus3Doc*)m_pDocument;
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CMenus3View message handlers
-
- void CMenus3View::OnColors()
- {
- CMenus3Doc* pDoc = GetDocument();
-
- // Since all 4 menu selections end up here (see message map)
- // we need to know how we got here.
- MSG const * pMsg = GetCurrentMessage();
-
- switch (LOWORD(pMsg->wParam))
- {
- case ID_COLORS_RED:
- pDoc->SetColor(RED);
- break;
- case ID_COLORS_GREEN:
- pDoc->SetColor(GREEN);
- break;
- case ID_COLORS_BLUE:
- pDoc->SetColor(BLUE);
- break;
- default:
- pDoc->SetColor(BLACK);
- }
- pDoc->UpdateAllViews(NULL);
- }
-
- void CMenus3View::OnUpdateColors(CCmdUI* pCmdUI)
- {
- CMenus3Doc* pDoc = GetDocument();
-
- switch (pCmdUI->m_nID)
- {
- case ID_COLORS_RED:
- pCmdUI->Enable(pDoc->GetColor() != RED);
- break;
- case ID_COLORS_GREEN:
- pCmdUI->Enable(pDoc->GetColor() != GREEN);
- break;
- case ID_COLORS_BLUE:
- pCmdUI->Enable(pDoc->GetColor() != BLUE);
- break;
- default:
- pCmdUI->Enable(pDoc->GetColor() != BLACK);
- }
- }
-