Click here to Skip to main content
15,881,173 members
Articles / Desktop Programming / MFC

Notifying the Document

Rate me:
Please Sign up or sign in to vote.
4.36/5 (11 votes)
12 Jul 2006CPOL6 min read 63.3K   1.2K   35  
An article on delivering objects to the document in a document/view architecture, using the WM_NOTIFY message.
#include "StdAfx.h"
#include "NotifyObject.h"
#include "NotifyObjects.h"



NotifyObjectType::NotifyObjectType( CNotifyObject * pObject ) 
{
	m_Type = NOTIFY_INVALID_OBJECT ;
	if ( pObject != NULL )
	{
		if ( pObject->IsKindOf( RUNTIME_CLASS( CErrorObject ) ) != FALSE )
		{
			m_Type = NOTIFY_ERROR_OBJECT ;
		}
		if ( pObject->IsKindOf( RUNTIME_CLASS( CInformationObject ) ) != FALSE )
		{
			m_Type = NOTIFY_INFORMATION_OBJECT ;
		}
	}
}

NotifyObjectType::operator long()
{
	return m_Type ;
}

IMPLEMENT_SERIAL(CErrorObject, CNotifyObject, NOTIFY_ERROR_SCHEMA) 

CErrorObject::CErrorObject( UINT Message, LPCTSTR ErrorMessage, NMHDR & Hdr ) : CNotifyObject( Hdr ) 
{
	m_Message = Message ;
	m_ErrorMessage = ErrorMessage ;
}

CErrorObject::CErrorObject( const CErrorObject & Object ) : CNotifyObject( Object ) 
{
	Copy( Object ) ; 
}

CErrorObject::~CErrorObject(void)
{
	m_Message = 0 ;
	m_ErrorMessage = _T("") ;
}

CErrorObject & CErrorObject::operator = ( const CErrorObject & Object )
{
	Copy( Object ) ; 
	return *this ;
}

LPCTSTR CErrorObject::get_ErrorMessage()
{
	return m_ErrorMessage ; 
}

void CErrorObject::Copy( const CErrorObject & Object )
{
	m_ErrorMessage = const_cast<CErrorObject&>(Object).m_ErrorMessage ;
	CNotifyObject::Copy(Object) ; 
}

IMPLEMENT_SERIAL(CInformationObject, CNotifyObject, NOTIFY_INFORMATION_SCHEMA) 


CInformationObject::CInformationObject( UINT Message, LPCTSTR InformationMessage, NMHDR & Hdr ) : CNotifyObject( Hdr ) 
{
	m_Message = Message ;
	m_InformationMessage = InformationMessage ;
}

CInformationObject::CInformationObject( const CInformationObject & Object ) : CNotifyObject( Object ) 
{
	Copy( Object ) ; 
}

CInformationObject::~CInformationObject(void)
{
	m_Message = 0 ;
	m_InformationMessage = _T("") ;
}

CInformationObject & CInformationObject::operator = ( const CInformationObject & Object )
{
	Copy( Object ) ; 
	return *this ;
}

LPCTSTR CInformationObject::get_InformationMessage()
{
	return m_InformationMessage ; 
}

void CInformationObject::Copy( const CInformationObject & Object )
{
	m_InformationMessage = const_cast<CInformationObject&>(Object).m_InformationMessage ;
	CNotifyObject::Copy(Object) ; 
}



By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions