// LessonA50.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <graphics.h>

#include "Chart.h"
#if defined(_UNICODE) || defined(UNICODE)
#	pragma comment(lib,"CChartu.lib")
#else
#	pragma comment(lib,"CChart.lib")
#endif
using namespace NsCChart;

#include <math.h>

CChart chart;

// 绘图函数
void	MyDraw()
{
	HDC hDC = GetImageHDC();
	
	RECT rt = {0, getheight()/2, getwidth(), getheight()};
	chart.OnDraw(hDC, rt);
}


int main(int argc, char* argv[])
{
	HWND hWnd = initgraph(640, 480, EW_DBLCLKS);
	
	double pi = 4.0*atan(1.0);
	int len=1080;
	for(int i=0; i<len; ++i)
	{
		chart.AddPoint2D(i, 1.4*sin(2.0*pi*i/360));
	}
	chart.SetTitle(_T("在EasyX中使用CChart"));
	chart.SetBkgndColor(RGB(0, 0, 0));
	chart.SetTitleColor(RGB(245, 245, 245));

	outtextxy(0, 0, _T("在EasyX窗口中绘图"));

	MyDraw();
	
// 	MOUSEMSG mm;
// 	while (true)
// 	{
// 		mm = GetMouseMsg();
// 		if(chart.OnEvent(hWnd, mm.uMsg, mm.mkCtrl, mm.x +(mm.y<<16)))
// 			MyDraw();
// 	}

	ExMessage em;
	WPARAM wParam;
	LPARAM lParam;
	bool loop = true;
	while(loop)
	{
		getmessage(&em, EM_MOUSE | EM_KEY);
		if(em.ch == 'c' || em.ch == 'C')loop = false;

		wParam = em.wParam;
		if(em.message == WM_MOUSEWHEEL)wParam = em.wheel;
		lParam = em.x + (em.y<<16);
		if(chart.OnEvent(hWnd, em.message, wParam, lParam))
			MyDraw();
	}
	
	closegraph();

	return 0;
}
