// This is a part of the Microsoft Foundation Classes C++ library.
// Copyright (C) 1992 Microsoft Corporation
// All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Foundation Classes Reference and Microsoft
// WinHelp documentation provided with the library.
// See these sources for detailed information regarding the
// Microsoft Foundation Classes product.

#include "stdafx.h"
#include "minsvr.h"

/////////////////////////////////////////////////////////////////////////////

BEGIN_MESSAGE_MAP(CMainWnd, CFrameWnd)
	//{{AFX_MSG_MAP(CMainWnd)
	ON_WM_CLOSE()
	ON_COMMAND(IDM_UPDATE, OnUpdateClient)
	ON_COMMAND(IDM_CHANGESTRING, OnChangeString)
	ON_COMMAND(IDM_ABOUT, OnAbout)
	ON_COMMAND(IDM_EXIT, OnExit)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// Basic creation etc

// Disable excessive compiler warning
#pragma warning(disable:4355)   // this used in constructor

CMainWnd::CMainWnd() : m_server(this)
{
	CRect rect(0, 200, 200, 400);

	Create(NULL, SERVER_LOCAL_NAME,
		WS_OVERLAPPEDWINDOW, rect, NULL, "MainMenu");
}

/////////////////////////////////////////////////////////////////////////////

void CMainWnd::OnClose()
{
	// just invoke the exit command - OLE will terminate the app
	OnExit();
}

void CMainWnd::OnExit()
{
	// to shut-down, just revoke the server, OLE will terminate the app
	m_server.BeginRevoke();
}

/////////////////////////////////////////////////////////////////////////////
// Edit menu commands

void CMainWnd::OnChangeString()
{
	if (m_server.m_doc.m_item.PromptChangeString())
	{
		// example of immediately updating client doc if open
		// for more complicated data you shouldn't update until
		//  the user selects the update menu
		if (m_server.m_doc.IsOpenServerDoc())
			OnUpdateClient();
	}
}

// Help menu commands
void CMainWnd::OnAbout()
{
	CDialog(IDD_ABOUTBOX).DoModal();
}


/////////////////////////////////////////////////////////////////////////////
// Update Client

void CMainWnd::OnUpdateClient()
{
	TRY
	{
		m_server.m_doc.NotifySaved();
	}
	CATCH (CException, e)
	{
		MessageBox("Could not update client");
	}
	END_CATCH
}

/////////////////////////////////////////////////////////////////////////////
