// LessonA17View.cpp : implementation of the CLessonA17View class
//

#include "stdafx.h"
#include "LessonA17.h"

#include "LessonA17Doc.h"
#include "LessonA17View.h"

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

/////////////////////////////////////////////////////////////////////////////
// CLessonA17View

IMPLEMENT_DYNCREATE(CLessonA17View, CView)

BEGIN_MESSAGE_MAP(CLessonA17View, CView)
	//{{AFX_MSG_MAP(CLessonA17View)
	ON_WM_CREATE()
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CLessonA17View construction/destruction

CLessonA17View::CLessonA17View()
{
	// TODO: add construction code here

}

CLessonA17View::~CLessonA17View()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CLessonA17View drawing

void CLessonA17View::OnDraw(CDC* pDC)
{
	CLessonA17Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CLessonA17View printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CLessonA17View diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CLessonA17View message handlers

void MyDefScreen( void *plot, HDC hDC, RECT plotRect, void *pPara )
{
	CChart *pChart = (CChart *)pPara;

	HPEN hPen, hOldPen;
	hPen = CreatePen(PS_SOLID, 3, RGB(255,255, 0));
	hOldPen = (HPEN)SelectObject(hDC, hPen);
	MoveToEx(hDC, plotRect.left, plotRect.top, NULL);
	LineTo(hDC, plotRect.right, plotRect.bottom);
	MoveToEx(hDC, plotRect.left, plotRect.bottom, NULL);
	LineTo(hDC, plotRect.right, plotRect.top);
	SelectObject(hDC, hOldPen);
	DeleteObject(hPen);
}

int CLessonA17View::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	m_ChartWnd.Attach(m_hWnd, kTypeXY);

	//1
	//m_ChartWnd.GetChart()->SetDefScreen(NULL, NULL);
	
	//2
	m_ChartWnd.GetChart()->SetDefMainString(_T("《弹琴》作者：刘长卿"));
	m_ChartWnd.GetChart()->SetDefSubString(_T("泠泠七弦上，静听松风寒。\n古调虽自爱，今人多不弹。"));
	m_ChartWnd.GetChart()->SetDrawBasicAnyway(true);
	m_ChartWnd.GetChart()->SetGridLine(true, true);
	m_ChartWnd.GetChart()->SetTitle(_T("唐诗赏析"));
/*
	//3
	HBITMAP hb;
	hb = (HBITMAP)LoadImage(GetModuleHandle(NULL), _T("DefScreen.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
	if(hb)
	{
		m_ChartWnd.GetChart()->SetDefImage(hb);
		DeleteObject(hb);
	}
	//4
	m_ChartWnd.GetChart()->SetDefScreen(MyDefScreen, m_ChartWnd.GetChart());
*/	
	return 0;
}
