// MainDlg.cpp : implementation of the CMainDlg class
//
/////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "MainDlg.h"	
	
CMainDlg::CMainDlg() : SHostWnd(_T("LAYOUT:XML_MAINWND"))
{
}

CMainDlg::~CMainDlg()
{
}

BOOL CMainDlg::OnInitDialog(HWND hWnd, LPARAM lParam)
{
	CRect rect;
	rect = GetClientRect();
	m_hWndChart = CreateSubChartWnd(m_hWnd, kTypeXY, L"CChart", rect.left+10, rect.top+40, rect.right-rect.left-20, rect.bottom-rect.top-50);

	int len=10;
	for(int i=0; i<len; i++)
	{
		GetChart(m_hWndChart)->AddPoint2D(i, i*i/(double)len/len);
	}
	GetChart(m_hWndChart)->SetTitle(L"测试子窗口");

	return 0;
}
//TODO:消息映射
void CMainDlg::OnClose()
{
	::DestroyWindow(m_hWndChart);
	SNativeWnd::DestroyWindow();
}

void CMainDlg::OnMaximize()
{
	SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE);
}
void CMainDlg::OnRestore()
{
	SendMessage(WM_SYSCOMMAND, SC_RESTORE);
}
void CMainDlg::OnMinimize()
{
	SendMessage(WM_SYSCOMMAND, SC_MINIMIZE);
}

void CMainDlg::OnSize(UINT nType, CSize size)
{
	SetMsgHandled(FALSE);	
	SWindow *pBtnMax = FindChildByName(L"btn_max");
	SWindow *pBtnRestore = FindChildByName(L"btn_restore");
	if(!pBtnMax || !pBtnRestore) return;
	
	if (nType == SIZE_MAXIMIZED)
	{
		pBtnRestore->SetVisible(TRUE);
		pBtnMax->SetVisible(FALSE);
	}
	else if (nType == SIZE_RESTORED)
	{
		pBtnRestore->SetVisible(FALSE);
		pBtnMax->SetVisible(TRUE);
	}

	CRect rect;
	rect = GetClientRect();
	::MoveWindow(m_hWndChart, rect.left+10, rect.top+40, rect.right-rect.left-20, rect.bottom-rect.top-50, TRUE);
}

