// mfchelloausvDoc.cpp : implementation of the CMfchelloausvDoc class
//

#include "stdafx.h"
#include "mfchelloausv.h"

#include "mfchelloausvDoc.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMfchelloausvDoc

IMPLEMENT_DYNCREATE(CMfchelloausvDoc, CDocument)

BEGIN_MESSAGE_MAP(CMfchelloausvDoc, CDocument)
	//{{AFX_MSG_MAP(CMfchelloausvDoc)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

BEGIN_DISPATCH_MAP(CMfchelloausvDoc, CDocument)
	//{{AFX_DISPATCH_MAP(CMfchelloausvDoc)
	DISP_PROPERTY_EX(CMfchelloausvDoc, "HelloMessage", GetHelloMessage, SetHelloMessage, VT_BSTR)
	DISP_FUNCTION(CMfchelloausvDoc, "SayHello", SayHello, VT_EMPTY, VTS_NONE)
	//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()

// Note: we add support for IID_IMfchel to support typesafe binding
//  from VBA.  This IID must match the GUID that is attached to the 
//  dispinterface in the .ODL file.

// {79B3AC82-92C6-11CF-8A22-00AA00A58097}
static const IID IID_IMfchel =
{ 0x79b3ac82, 0x92c6, 0x11cf, { 0x8a, 0x22, 0x0, 0xaa, 0x0, 0xa5, 0x80, 0x97 } };

BEGIN_INTERFACE_MAP(CMfchelloausvDoc, CDocument)
	INTERFACE_PART(CMfchelloausvDoc, IID_IMfchel, Dispatch)
END_INTERFACE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMfchelloausvDoc construction/destruction

CMfchelloausvDoc::CMfchelloausvDoc()
{
	m_HelloMessage = "Hello, World" ;

	EnableAutomation();
	AfxOleLockApp();
}

CMfchelloausvDoc::~CMfchelloausvDoc()
{
	AfxOleUnlockApp();
}

BOOL CMfchelloausvDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMfchelloausvDoc serialization

void CMfchelloausvDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

/////////////////////////////////////////////////////////////////////////////
// CMfchelloausvDoc diagnostics

#ifdef _DEBUG
void CMfchelloausvDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CMfchelloausvDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMfchelloausvDoc commands

void CMfchelloausvDoc::SayHello() 
{
	MessageBeep (0) ;
	UpdateAllViews (NULL) ;
}

BSTR CMfchelloausvDoc::GetHelloMessage() 
{
	CString strResult;

	strResult = m_HelloMessage ;
	return strResult.AllocSysString();
}

void CMfchelloausvDoc::SetHelloMessage(LPCTSTR lpszNewValue) 
{
	if (strstr (lpszNewValue, "bad"))
	{
		AfxThrowOleDispatchException (1, "I can't take bad news",
			1) ;
	}

	m_HelloMessage = lpszNewValue ;
}
