// ChildView.cpp : implementation of the CChildView class
//

#include "stdafx.h"
#include "WinMosh.h"
#include "ChildView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CChildView

CChildView::CChildView()
{
}

CChildView::~CChildView()
{
}


BEGIN_MESSAGE_MAP(CChildView,CWnd )
	//{{AFX_MSG_MAP(CChildView)
	ON_WM_PAINT()
	ON_WM_SIZE()
	ON_WM_SETFOCUS()
	//}}AFX_MSG_MAP
	ON_COMMAND(ID_FILE_LOADMODEL, OnLoadModel)
	ON_COMMAND(ID_FILE_LOADLIB, OnLoadLib)
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CChildView message handlers

BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs) 
{
	if (!CWnd::PreCreateWindow(cs))
		return FALSE;

	cs.dwExStyle |= WS_EX_CLIENTEDGE;
	cs.style &= ~WS_BORDER;
	cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, 
		::LoadCursor(NULL, IDC_ARROW), HBRUSH(COLOR_WINDOW+1), NULL);

	return TRUE;
}

void CChildView::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
}


BOOL CChildView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
{
	BOOL res = CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
	if (res != 0) {
		res = m_Text.Create(dwStyle|ES_MULTILINE|ES_WANTRETURN|WS_VSCROLL,rect,this,1);
		m_Text.SetWindowText(">> ");
		m_Text.SetSel(3,3);
		if (res==0) return res;
		res = m_ErrorText.Create(dwStyle|ES_MULTILINE|ES_WANTRETURN|WS_VSCROLL,rect,this,2);
		m_ErrorText.SetReadOnly();
		m_ErrorText.SetLimitText(0);
		m_Text.SetErrorWindow(&m_ErrorText);
	}
	return res;
}

void CChildView::OnSize(UINT nType, int cx, int cy) 
{
	CWnd ::OnSize(nType, cx, cy);

	if (IsWindow(m_Text.GetSafeHwnd())) {
		m_Text.MoveWindow(0,0,cx,cy-100);	
		m_ErrorText.MoveWindow(0,cy-95,cx,95);	
	}
}


void CChildView::OnSetFocus(CWnd* pOldWnd) 
{
	CWnd ::OnSetFocus(pOldWnd);

	m_Text.SetFocus();	
}
