// EditorChildWnd.cpp : implementation file
//

#include "stdafx.h"
#include "mw4gameed.h"
#include "EditorChildWnd.h"

/////////////////////////////////////////////////////////////////////////////
// CEditorChildWnd

IMPLEMENT_DYNCREATE(CEditorChildWnd, CMDIChildWnd)

CEditorChildWnd::CEditorChildWnd()
{
}

CEditorChildWnd::~CEditorChildWnd()
{
}


BEGIN_MESSAGE_MAP(CEditorChildWnd, CMDIChildWnd)
//{{AFX_MSG_MAP(CEditorChildWnd)
ON_WM_CLOSE()
ON_WM_DESTROY()
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEditorChildWnd message handlers

void CEditorChildWnd::OnClose() 
{
	ShowWindow(SW_HIDE);
	
	//	CMDIChildWnd::OnClose();
}

void CEditorChildWnd::ToggleVisible()
{
	if(IsWindowVisible())
		ShowWindow(SW_HIDE);
	else 
		ShowWindow(SW_SHOW);
}

void CEditorChildWnd::OnDestroy() 
{
	
	CMDIChildWnd::OnDestroy();
	
	// TODO: Add your message handler code here
	
}

int CEditorChildWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	return 0;
}

BOOL CEditorChildWnd::DestroyWindow() 
{
	return CMDIChildWnd::DestroyWindow();
}

void CEditorChildWnd::SaveState()
{
	CString winname,keyname;
	GetWindowText(winname);
	winname.Remove(' ');
	
	keyname=winname+"_Visible";
	BOOL vflag;
	vflag=IsWindowVisible();
	
	gos_SaveDataToRegistry((char *)(LPCSTR)keyname,&vflag,sizeof(vflag));

	WINDOWPLACEMENT wp;
	keyname=winname+"_Placement";
	GetWindowPlacement(&wp);
	gos_SaveDataToRegistry((char *)(LPCSTR)keyname,&wp,sizeof(wp));
}

void CEditorChildWnd::LoadState()
{
	CString winname,keyname;
	GetWindowText(winname);
	winname.Remove(' ');
	
	keyname=winname+"_Visible";
	BOOL vflag;
	DWORD size=sizeof(vflag);
	
	gos_LoadDataFromRegistry((char *)(LPCSTR)keyname,&vflag,&size);
	
	if(size==sizeof(vflag))
	{
		ShowWindow(vflag?SW_SHOW:SW_HIDE);
	}
	else
	{
		ShowWindow(SW_SHOW);
		
	}
	keyname=winname+"_Placement";
	WINDOWPLACEMENT wp;
	size=sizeof(wp);
	gos_LoadDataFromRegistry((char *)(LPCSTR)keyname,&wp,&size);
	if (size == sizeof(wp))
	{
		SetWindowPlacement(&wp);
	}
}
