0% found this document useful (0 votes)
175 views6 pages

Graphic Devices and Colors

This document defines a CExp3aView class that represents a view in an MFC application. The class contains attributes like a rectangle and color integer and overrides functions like OnDraw to draw an ellipse on the view. It also contains message map entries like handling left mouse clicks to change the ellipse color.

Uploaded by

michael.ferraris
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
175 views6 pages

Graphic Devices and Colors

This document defines a CExp3aView class that represents a view in an MFC application. The class contains attributes like a rectangle and color integer and overrides functions like OnDraw to draw an ellipse on the view. It also contains message map entries like handling left mouse clicks to change the ellipse color.

Uploaded by

michael.ferraris
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

PROGRAM

// exp3aView.h : interface of the CExp3aView class

#if !
defined(AFX_EXP3AVIEW_H__30255CA8_0BBE_4EE5_A61D_D0484601CB5
1__INCLUDED_)
#define
AFX_EXP3AVIEW_H__30255CA8_0BBE_4EE5_A61D_D0484601CB51__INC
LUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class CExp3aView : public CView


{
protected: // create from serialization only
CExp3aView();
DECLARE_DYNCREATE(CExp3aView)
// Attributes
public:
CExp3aDoc* GetDocument();
CRect m_rectEllipse;
int m_ncolor;
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CExp3aView)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);

protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
//}}AFX_VIRTUAL

// Implementation
public:
virtual ~CExp3aView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif

protected:
// Generated message map functions
protected:
//{{AFX_MSG(CExp3aView)
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

#ifndef _DEBUG // debug version in exp3aView.cpp


inline CExp3aDoc* CExp3aView::GetDocument()
{ return (CExp3aDoc*)m_pDocument; }
#endif
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the
previous line.

#endif // !
defined(AFX_EXP3AVIEW_H__30255CA8_0BBE_4EE5_A61D_D0484601CB5
1__INCLUDED_)
// exp3aView.cpp : implementation of the CExp3aView class

#include "stdafx.h"
#include "exp3a.h"
#include "exp3aDoc.h"
#include "exp3aView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

// CExp3aView
IMPLEMENT_DYNCREATE(CExp3aView, CView)
BEGIN_MESSAGE_MAP(CExp3aView, CView)
//{{AFX_MSG_MAP(CExp3aView)
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW,
CView::OnFilePrintPreview)
END_MESSAGE_MAP()

// CExp3aView construction/destruction

CExp3aView::CExp3aView():m_rectEllipse(100,100,200,200)
{
m_ncolor=GRAY_BRUSH;
}

BOOL CExp3aView::PreCreateWindow(CREATESTRUCT& cs)


{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs

return CView::PreCreateWindow(cs);
}

// CExp3aView drawing
void CExp3aView::OnDraw(CDC* pDC)
{
CExp3aDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDC->SelectStockObject(m_ncolor);
pDC->Ellipse(m_rectEllipse);
}

// CExp3aView printing
BOOL CExp3aView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}

// CExp3aView diagnostics

#ifdef _DEBUG
void CExp3aView::AssertValid() const
{
CView::AssertValid();
}
void CExp3aView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CExp3aDoc* CExp3aView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CExp3aDoc)));
return (CExp3aDoc*)m_pDocument;
}
#endif //_DEBUG

// CExp3aView message handlers

void CExp3aView::OnLButtonDown(UINT nFlags, CPoint point)


{
CView::OnLButtonDown(nFlags, point);
if(m_rectEllipse.PtInRect(point))
{
if(m_ncolor==GRAY_BRUSH)
m_ncolor=WHITE_BRUSH;
else
m_ncolor=GRAY_BRUSH;
Invalidate();
}
}

OUTPUT

You might also like