///////////////////////////////////
// main.cpp

// Note:
//  * Add the Win32++\include  directory to project's additional include directories

#include "wxx_wincore.h"

#pragma comment(lib, "comctl32.lib")

#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>


//////////////////////////////////////////
// CView is the application's main window.
class CView : public CWnd
{
public:
    CView() {}
    virtual void OnDestroy() { PostQuitMessage(0); } // Ends the program
    virtual ~CView() {}

	CChartWnd chartWnd;
	virtual int OnCreate(CREATESTRUCT& cs);
	virtual void PreRegisterClass(WNDCLASS& wc){wc.style |= CS_DBLCLKS;}
	LRESULT WndProc(UINT msg, WPARAM wparam, LPARAM lparam);
};

int	CView::OnCreate(CREATESTRUCT& cs)
{
	chartWnd.Attach(GetHwnd());
	double pi = 4.0*atan(1.0);
	for(int i=0; i<360; ++i)
	{
		chartWnd.GetChart()->AddPoint2D(i, 1.3*sin(i*2.0*pi/360.0));
	}
	chartWnd.GetChart()->SetTitle(_T("CChartºÍWin32++"));
	return 0;
}

LRESULT CView::WndProc(UINT msg, WPARAM wparam, LPARAM lparam)
{
	if(msg == WM_SIZE)
	{
		chartWnd.ReDraw();
	}
	return CWnd::WndProc(msg, wparam, lparam);
}


////////////////////////////////////////////////////
// A class that inherits from CWinApp.
// It is used to run the application's message loop.
class CSimpleApp : public CWinApp
{
public:
    CSimpleApp() {}
    virtual ~CSimpleApp() {}
    virtual BOOL InitInstance();

private:
    CView m_view;
};

// Called when the application starts.
BOOL CSimpleApp::InitInstance()
{
    // Create the Window
    m_view.Create();

    return TRUE;
}


// WinMain is the program's entry point. The program starts here.
int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
    // Start Win32++
    CSimpleApp theApp;

    // Run the application
    return theApp.Run();
}
