Click here to Skip to main content
15,892,298 members
Articles / Programming Languages / C++

Customized Visual Studio .NET package: your fully integrated document window inside the IDE

Rate me:
Please Sign up or sign in to vote.
4.72/5 (20 votes)
20 Dec 200313 min read 63.8K   1.1K   39  
Create a fully integrated document window inside the Visual Studio IDE.
/**********************************************************************
- File Name: Mediator.cpp
- Date: 12/9/2003 5:31:00 PM
- Author: Michael Sheinin
- Description : 
	Implementation of CMediator class
- Notes: 

**********************************************************************/
#include "StdAfx.h"
#include "mediator.h"
#include "docview.h"
#include "docdata.h"
#include "dbg.h"

#ifdef _BASIC_WINDOW_
#include "VsBasicWindow.h"
#else
#include "MyWindow.h"
#endif 

///============================================================
// Creation/initialization/destruction
///============================================================
CMediator::CMediator(void)
{
	m_uRefCnt = 0;
	m_pData = NULL;
	m_pView = NULL;
	m_pWnd = NULL;
}

CMediator::~CMediator(void)
{
	CDbg::Trace("CMediator destructor\n" );
}

void CMediator::AddRef(void)
{
	m_uRefCnt ++;
}

void CMediator::Release(void)
{
	m_uRefCnt --;
	if ( m_uRefCnt == 0 )
	{
		delete this;
	}
}

void CMediator::SetData(CDocumentData* pData)
{
	m_pData = pData;
	pData != NULL ? AddRef() : Release();
}

void CMediator::SetView( CDocumentView* pView )
{
	m_pView = pView;
	pView != NULL ? AddRef() : Release();
}

///============================================================
// DocumentView methods
///============================================================
HWND CMediator::CreateWnd( HWND hParent, int iX, int iY, int iCX, int iCY )
{
	m_pWnd = new 
#ifdef _BASIC_WINDOW_
		CVsBasicWnd();
#else
		CMyWindow();
#endif //_BASIC_WINDOW_

	if ( m_pWnd )
	{
		if ( m_pWnd->Create( hParent, iX, iY, iCX, iCY ) )
		{
			return m_pWnd->GetHandle();
		}
		delete m_pWnd;
		m_pWnd = NULL;
	}
	return NULL;
}

void CMediator::CloseWindow()
{
	if ( m_pWnd )
	{
		m_pWnd->Close();
		delete m_pWnd;
		m_pWnd = NULL;
	}
}

DWORD	CMediator::QueryCommandsState()
{
	if ( m_pData )
	{
		return m_pData->QueryCommandsState();
	}
	return DWORD(-1); // all enabled
}

HRESULT	CMediator::ExecCommand(ULONG uCmdID)
{
	if ( m_pData )
	{
		return m_pData->ExecCommand(uCmdID);
	}
	return OLECMDERR_E_DISABLED; // must return smth
}

///============================================================
// DocumentData methods
///============================================================
void CMediator::AddGraphicObject( CGraphicObject* pObj )
{
	if ( m_pWnd )
	{
#ifndef _BASIC_WINDOW_
		m_pWnd->AddObject( pObj );
#endif // _BASIC_WINDOW_
	}
}

void CMediator::UpdateView()
{
	if ( m_pWnd )
	{
#ifndef _BASIC_WINDOW_
		m_pWnd->Invalidate();
#endif //_BASIC_WINDOW_
	}
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
For the last 7 years I have developed software in real-time/embedded and MS-Windows environments for military and civil markets. I hold B.Sc. degree in computer engineering. Living in Ontario, Canada, I like hiking and traveling in general. Currently, I'm looking for employment opportunity inside the GTA.

Comments and Discussions