
// movingEllipseView.cpp : CmovingEllipseView 類別的實作
//

#include "stdafx.h"
// SHARED_HANDLERS 可以定義在實作預覽、縮圖和搜尋篩選條件處理常式的
// ATL 專案中，並允許與該專案共用文件程式碼。
#ifndef SHARED_HANDLERS
#include "movingEllipse.h"
#endif

#include "movingEllipseDoc.h"
#include "movingEllipseView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CmovingEllipseView

IMPLEMENT_DYNCREATE(CmovingEllipseView, CView)

BEGIN_MESSAGE_MAP(CmovingEllipseView, CView)
	// 標準列印命令
	ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CmovingEllipseView::OnFilePrintPreview)
	ON_WM_CONTEXTMENU()
	ON_WM_RBUTTONUP()
	ON_WM_CREATE()
	ON_WM_TIMER()
END_MESSAGE_MAP()

// CmovingEllipseView 建構/解構

CmovingEllipseView::CmovingEllipseView():m_x(10),m_y(10)
{
	// TODO: 在此加入建構程式碼

}

CmovingEllipseView::~CmovingEllipseView()
{
}

BOOL CmovingEllipseView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: 在此經由修改 CREATESTRUCT cs 
	// 達到修改視窗類別或樣式的目的

	return CView::PreCreateWindow(cs);
}

// CmovingEllipseView 描繪

void CmovingEllipseView::OnDraw(CDC* pDC)
{
	CmovingEllipseDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	// TODO: 在此加入原生資料的描繪程式碼
	pDC->Ellipse(m_x-10, m_y-10, m_x+10, m_y+10);
}


// CmovingEllipseView 列印


void CmovingEllipseView::OnFilePrintPreview()
{
#ifndef SHARED_HANDLERS
	AFXPrintPreview(this);
#endif
}

BOOL CmovingEllipseView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// 預設的準備列印程式碼
	return DoPreparePrinting(pInfo);
}

void CmovingEllipseView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: 加入列印前額外的初始設定
}

void CmovingEllipseView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: 加入列印後的清除程式碼
}

void CmovingEllipseView::OnRButtonUp(UINT /* nFlags */, CPoint point)
{
	ClientToScreen(&point);
	OnContextMenu(this, point);
}

void CmovingEllipseView::OnContextMenu(CWnd* /* pWnd */, CPoint point)
{
#ifndef SHARED_HANDLERS
	theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
#endif
}


// CmovingEllipseView 診斷

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

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

CmovingEllipseDoc* CmovingEllipseView::GetDocument() const // 內嵌非偵錯版本
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CmovingEllipseDoc)));
	return (CmovingEllipseDoc*)m_pDocument;
}
#endif //_DEBUG


// CmovingEllipseView 訊息處理常式


int CmovingEllipseView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;

	// TODO:  在此加入特別建立的程式碼
	SetTimer(123, 300, NULL);

	return 0;
}


void CmovingEllipseView::OnTimer(UINT_PTR nIDEvent)
{
	// TODO: 在此加入您的訊息處理常式程式碼和 (或) 呼叫預設值
	if (nIDEvent==123)
	{
		CRect rect;
		GetClientRect(rect);
		m_x = (m_x + 15) % (rect.right-10) + 10;
		m_y = (m_y + 25) % (rect.bottom-10) + 10;
		TRACE("(%d,%d)", m_x, m_y);
		Invalidate();
	}

	CView::OnTimer(nIDEvent);
}
