// Eg5_2View.cpp : implementation of the CEg5_2View class
//

#include "stdafx.h"
#include "Eg5_2.h"

#include "Eg5_2Doc.h"
#include "Eg5_2View.h"
#include "MainFrm.h"

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

/////////////////////////////////////////////////////////////////////////////
// CEg5_2View

IMPLEMENT_DYNCREATE(CEg5_2View, CView)

BEGIN_MESSAGE_MAP(CEg5_2View, CView)
	//{{AFX_MSG_MAP(CEg5_2View)
	ON_COMMAND(ID_DRAW_CIRCLE, OnDrawCircle)
	ON_UPDATE_COMMAND_UI(ID_DRAW_CIRCLE, OnUpdateDrawCircle)
	ON_COMMAND(ID_DRAW_RECT, OnDrawRect)
	ON_UPDATE_COMMAND_UI(ID_DRAW_RECT, OnUpdateDrawRect)
	ON_WM_LBUTTONDOWN()
	ON_WM_MOUSEMOVE()
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CEg5_2View construction/destruction

CEg5_2View::CEg5_2View()
{
	// TODO: add construction code here
    m_Shape=0;   //圆
	m_x=0;       //x的坐标为0
	m_y=0;       //y的坐标为0
}

CEg5_2View::~CEg5_2View()
{
}

BOOL CEg5_2View::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CEg5_2View drawing

void CEg5_2View::OnDraw(CDC* pDC)
{
	CEg5_2Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	
	RECT rect;


	if(m_Shape==0)                       //圆
	{
	  rect.left=m_x-50;                  //设置圆的大小
	  rect.right=m_x+50;
	  rect.top=m_y-50;
	  rect.bottom=m_y+50;
	  pDC->Ellipse(&rect);
	}
	 else                                 //矩形
	 {                                    //设置矩形的大小
	  rect.left=m_x-50;
	  rect.right=m_x+50;
	  rect.top=m_y-30;
	  rect.bottom=m_y+30;
	  pDC->Rectangle (&rect);
	 }
	 
}

/////////////////////////////////////////////////////////////////////////////
// CEg5_2View printing

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

void CEg5_2View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CEg5_2View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CEg5_2View diagnostics

#ifdef _DEBUG
void CEg5_2View::AssertValid() const
{
	CView::AssertValid();
}

void CEg5_2View::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CEg5_2Doc* CEg5_2View::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEg5_2Doc)));
	return (CEg5_2Doc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CEg5_2View message handlers

void CEg5_2View::OnDrawCircle() 
{
	// TODO: Add your command handler code here
	m_Shape=0;                 //设置为圆
	
}

void CEg5_2View::OnUpdateDrawCircle(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	//如果为圆，则将圆按钮压下，在圆菜单前显示一个对钩号
	if(m_Shape==0)
		pCmdUI->SetCheck (1);
	else
		pCmdUI->SetCheck (0);
	
}

void CEg5_2View::OnDrawRect() 
{
	// TODO: Add your command handler code he
	 m_Shape=1;             //设置为圆

	
}

void CEg5_2View::OnUpdateDrawRect(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	//如果为矩形，则将矩形按钮压下，在矩形菜单前显示一个对钩号
	if(m_Shape==1)

	pCmdUI->SetCheck (1);
	else
		pCmdUI->SetCheck (0);
	
}

void CEg5_2View::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	//设置x，y坐标
	m_x=point.x;
	m_y=point.y;

	//更新视图
	Invalidate();
	
	CView::OnLButtonDown(nFlags, point);
}

void CEg5_2View::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default

	char PositionString[50];
	//获取主框架指针
	CMainFrame *MFrame=(CMainFrame *)AfxGetMainWnd();
	//在状态信息行1中显示X坐标
	sprintf(PositionString,"X:%d",point.x);
	MFrame->m_wndStatusBar .SetPaneText (1,PositionString);
    //在状态信息行2中显示Y坐标
	sprintf(PositionString,"Y:%d",point.y);
	MFrame->m_wndStatusBar .SetPaneText (2,PositionString);

	
	CView::OnMouseMove(nFlags, point);
}
