You are on page 1of 6

PROJECT NAME : mdi

In mdiView.h

#if !
defined(AFX_MDIVIEW_H__14EAD8AA_9578_48A6_A70D_3F09EEACC5CC__INCL
UDED_)
#define
AFX_MDIVIEW_H__14EAD8AA_9578_48A6_A70D_3F09EEACC5CC__INCLUDED_

#if _MSC_VER > 1000


#pragma once
#endif // _MSC_VER > 1000

class CMdiView : public CView


{
protected: // create from serialization only
CMdiView();
DECLARE_DYNCREATE(CMdiView)

// Attributes
public:
CMdiDoc* GetDocument();
int ch;

// Operations
public:

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMdiView)
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 ~CMdiView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions


protected:
//{{AFX_MSG(CMdiView)
afx_msg void OnDrawEllipse();
afx_msg void OnDrawRectangle();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

#ifndef _DEBUG // debug version in mdiView.cpp


inline CMdiDoc* CMdiView::GetDocument()
{ return (CMdiDoc*)m_pDocument; }
#endif

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the
previous line.

#endif // !
defined(AFX_MDIVIEW_H__14EAD8AA_9578_48A6_A70D_3F09EEACC5CC__INCL
UDED_)

In mdiView.cpp

// mdiView.cpp : implementation of the CMdiView class

#include "stdafx.h"
#include "mdi.h"
#include "mdiDoc.h"
#include "mdiView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

// CMdiView

IMPLEMENT_DYNCREATE(CMdiView, CView)

BEGIN_MESSAGE_MAP(CMdiView, CView)
//{{AFX_MSG_MAP(CMdiView)
ON_COMMAND(ID_DRAW_ELLIPSE, OnDrawEllipse)
ON_COMMAND(ID_DRAW_RECTANGLE, OnDrawRectangle)
//}}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()

BOOL CMdiView::PreCreateWindow(CREATESTRUCT& cs)


{
return CView::PreCreateWindow(cs);
}

// CMdiView drawing

void CMdiView::OnDraw(CDC* pDC)


{
CMdiDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if(ch==1)
pDC->Ellipse(0,0,100,100);
else if(ch==2)
pDC->Rectangle(0,0,100,100);
}

// CMdiView printing

BOOL CMdiView::OnPreparePrinting(CPrintInfo* pInfo)


{ return DoPreparePrinting(pInfo); }

void CMdiView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)


{ }

void CMdiView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)


{ }

// CMdiView diagnostics
#ifdef _DEBUG
void CMdiView::AssertValid() const
{
CView::AssertValid();
}

void CMdiView::Dump(CDumpContext& dc) const


{
CView::Dump(dc);
}

CMdiDoc* CMdiView::GetDocument() // non-debug version is inline


{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMdiDoc)));
return (CMdiDoc*)m_pDocument;
}
#endif //_DEBUG

// CMdiView message handlers

void CMdiView::OnDrawEllipse()
{
ch=1;
OnDraw(GetDC());

void CMdiView::OnDrawRectangle()
{
ch=2;
OnDraw(GetDC());
}
OUTPUT

You might also like