Click here to Skip to main content
15,891,657 members
Articles / Web Development / HTML

Creating Web-style GUI in MFC applications

Rate me:
Please Sign up or sign in to vote.
4.85/5 (41 votes)
13 Jul 20049 min read 279.5K   11.1K   247  
Creating Web-style GUI and easily managing it from MFC code. Creating dialogs based on DHTML, receiving events from DHTML to MFC, and calling JScript functions from MFC.
// DocHostSite.cpp: implementation of the CDocHostSite class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"

#if _MFC_VER >= 0x0700
#include <afxocc.h>
#else
#ifdef _AFXDLL
#undef AFX_DATA
#define AFX_DATA AFX_DATA_IMPORT
#endif
#include <..\src\occimpl.h>
#ifdef _AFXDLL
#undef AFX_DATA
#define AFX_DATA AFX_DATA_EXPORT
#endif
#endif

#include <mshtmhst.h>

#include "DocHostSite.h"
//#include "HtmlDialog.h"
#include "Html_Host_Handlers.h"

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

BEGIN_INTERFACE_MAP(CDocHostSite, COleControlSite)
	INTERFACE_PART(CDocHostSite, IID_IDocHostShowUI, DocHostShowUI)
	INTERFACE_PART(CDocHostSite, IID_IDocHostUIHandler, DocHostUIHandler)
#if (_WIN32_IE >= 0x0501) // IE 5.5 and higher
	INTERFACE_PART(CDocHostSite, IID_IDocHostUIHandler2, DocHostUIHandler2)
#endif
END_INTERFACE_MAP()

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CDocHostSite::CDocHostSite(COleControlContainer * pOcc)
	: COleControlSite( pOcc ),
	m_pView( NULL )
{
}

CDocHostSite::~CDocHostSite()
{
}

ULONG CDocHostSite::XDocHostShowUI::AddRef()
{
	METHOD_PROLOGUE(CDocHostSite, DocHostShowUI);

	return pThis->ExternalAddRef();
}

ULONG CDocHostSite::XDocHostShowUI::Release()
{
	METHOD_PROLOGUE(CDocHostSite, DocHostShowUI);

	return pThis->ExternalRelease();
}

HRESULT CDocHostSite::XDocHostShowUI::QueryInterface(REFIID riid, void ** ppvObj)
{
	METHOD_PROLOGUE(CDocHostSite, DocHostShowUI);

	return pThis->ExternalQueryInterface( &riid, ppvObj );
}

HRESULT CDocHostSite::XDocHostShowUI::ShowHelp(HWND hwnd,
											   LPOLESTR pszHelpFile,
											   UINT nCommand,
											   DWORD dwData,
											   POINT ptMouse,
											   IDispatch * pDispatchObjectHit)
{
	METHOD_PROLOGUE(CDocHostSite, DocHostShowUI);

	return pThis->m_pView->OnShowHelp( hwnd, pszHelpFile, nCommand, dwData, ptMouse,
		pDispatchObjectHit );
}

HRESULT CDocHostSite::XDocHostShowUI::ShowMessage(HWND hwnd,
												  LPOLESTR lpstrText,
												  LPOLESTR lpstrCaption,
												  DWORD dwType,
												  LPOLESTR lpstrHelpFile,
												  DWORD dwHelpContext,
												  LRESULT * plResult)
{
	METHOD_PROLOGUE(CDocHostSite, DocHostShowUI);

	return pThis->m_pView->OnShowMessage( hwnd, lpstrText, lpstrCaption, dwType,
		lpstrHelpFile, dwHelpContext, plResult );
}

ULONG CDocHostSite::XDocHostUIHandler::AddRef()
{
	METHOD_PROLOGUE(CDocHostSite, DocHostUIHandler);
	return pThis->ExternalAddRef();
}

ULONG CDocHostSite::XDocHostUIHandler::Release()
{
	METHOD_PROLOGUE(CDocHostSite, DocHostUIHandler);
	return pThis->ExternalRelease();
}

HRESULT CDocHostSite::XDocHostUIHandler::QueryInterface(REFIID riid, void ** ppvObj)
{
	METHOD_PROLOGUE(CDocHostSite, DocHostUIHandler);
	return pThis->ExternalQueryInterface( &riid, ppvObj );
}

HRESULT CDocHostSite::XDocHostUIHandler::GetHostInfo(DOCHOSTUIINFO * pInfo)
{
	METHOD_PROLOGUE(CDocHostSite, DocHostUIHandler);
	return pThis->m_pView->OnGetHostInfo( pInfo );
}

HRESULT CDocHostSite::XDocHostUIHandler::ShowUI(DWORD dwID,
											  IOleInPlaceActiveObject * pActiveObject,
											  IOleCommandTarget * pCommandTarget,
											  IOleInPlaceFrame * pFrame,
											  IOleInPlaceUIWindow * pDoc)
{
	METHOD_PROLOGUE(CDocHostSite, DocHostUIHandler);
	return pThis->m_pView->OnShowUI( dwID, pActiveObject, pCommandTarget,
		pFrame, pDoc );
}

HRESULT CDocHostSite::XDocHostUIHandler::HideUI()
{
	METHOD_PROLOGUE(CDocHostSite, DocHostUIHandler);
	return pThis->m_pView->OnHideUI();
}

HRESULT CDocHostSite::XDocHostUIHandler::UpdateUI()
{
	METHOD_PROLOGUE(CDocHostSite, DocHostUIHandler);
	return pThis->m_pView->OnUpdateUI();
}

HRESULT CDocHostSite::XDocHostUIHandler::EnableModeless(BOOL fEnable)
{
	METHOD_PROLOGUE(CDocHostSite, DocHostUIHandler);
	return pThis->m_pView->OnEnableModeless( fEnable );
}

HRESULT CDocHostSite::XDocHostUIHandler::OnDocWindowActivate(BOOL fEnable)
{
	METHOD_PROLOGUE(CDocHostSite, DocHostUIHandler);
	return pThis->m_pView->OnDocWindowActivate( fEnable );
}

HRESULT CDocHostSite::XDocHostUIHandler::OnFrameWindowActivate(BOOL fEnable)
{
	METHOD_PROLOGUE(CDocHostSite, DocHostUIHandler);
	return pThis->m_pView->OnFrameWindowActivate( fEnable );
}

HRESULT CDocHostSite::XDocHostUIHandler::ResizeBorder(LPCRECT prcBorder,
													IOleInPlaceUIWindow * pUIWindow,
													BOOL fFrameWindow)
{
	METHOD_PROLOGUE(CDocHostSite, DocHostUIHandler);
	return pThis->m_pView->OnResizeBorder( prcBorder, pUIWindow, fFrameWindow );
}

HRESULT CDocHostSite::XDocHostUIHandler::ShowContextMenu(DWORD dwID,
													   POINT * ppt,
													   IUnknown * pcmdtReserved,
													   IDispatch * pdispReserved)
{
	METHOD_PROLOGUE(CDocHostSite, DocHostUIHandler);
	return pThis->m_pView->OnShowContextMenu( dwID, ppt, pcmdtReserved,
		pdispReserved );
}

HRESULT CDocHostSite::XDocHostUIHandler::TranslateAccelerator(LPMSG lpMsg,
															const GUID * pguidCmdGroup,
															DWORD nCmdID)
{
	METHOD_PROLOGUE(CDocHostSite, DocHostUIHandler);
	return pThis->m_pView->OnTranslateAccelerator( lpMsg,
		pguidCmdGroup, nCmdID );
}

HRESULT CDocHostSite::XDocHostUIHandler::GetOptionKeyPath(LPOLESTR * pchKey,
														DWORD dw)
{
	METHOD_PROLOGUE(CDocHostSite, DocHostUIHandler);
	return pThis->m_pView->OnGetOptionKeyPath( pchKey, dw );
}

HRESULT CDocHostSite::XDocHostUIHandler::GetDropTarget(IDropTarget * pDropTarget,
													 IDropTarget ** ppDropTarget)
{
	METHOD_PROLOGUE(CDocHostSite, DocHostUIHandler);
	return pThis->m_pView->OnGetDropTarget( pDropTarget, ppDropTarget );
}

HRESULT CDocHostSite::XDocHostUIHandler::GetExternal(IDispatch ** ppDispatch)
{
	METHOD_PROLOGUE(CDocHostSite, DocHostUIHandler);
	return pThis->m_pView->OnGetExternal( ppDispatch );
}

HRESULT CDocHostSite::XDocHostUIHandler::TranslateUrl(DWORD dwTranslate,
													OLECHAR * pchURLIn,
													OLECHAR ** ppchURLOut)
{
	METHOD_PROLOGUE(CDocHostSite, DocHostUIHandler);
	return pThis->m_pView->OnTranslateUrl( dwTranslate, pchURLIn, ppchURLOut );
}

HRESULT CDocHostSite::XDocHostUIHandler::FilterDataObject(IDataObject * pDO,
														IDataObject ** ppDORet)
{
	METHOD_PROLOGUE(CDocHostSite, DocHostUIHandler);
	return pThis->m_pView->OnFilterDataObject( pDO, ppDORet );
}

#if (_WIN32_IE >= 0x0501) // IE 5.5 and higher

ULONG CDocHostSite::XDocHostUIHandler2::AddRef()
{
	METHOD_PROLOGUE(CDocHostSite, DocHostUIHandler2);

	return pThis->ExternalAddRef();
}

ULONG CDocHostSite::XDocHostUIHandler2::Release()
{
	METHOD_PROLOGUE(CDocHostSite, DocHostUIHandler2);

	return pThis->ExternalRelease();
}

HRESULT CDocHostSite::XDocHostUIHandler2::QueryInterface(REFIID riid, void ** ppvObj)
{
	METHOD_PROLOGUE(CDocHostSite, DocHostUIHandler2);

	return pThis->ExternalQueryInterface( &riid, ppvObj );
}

HRESULT CDocHostSite::XDocHostUIHandler2::GetHostInfo(DOCHOSTUIINFO *)
{
	ASSERT(FALSE);

	return S_FALSE;
}

HRESULT CDocHostSite::XDocHostUIHandler2::ShowUI(DWORD /*dwID*/, 
												 IOleInPlaceActiveObject * /*pActiveObject*/,
												 IOleCommandTarget * /*pCommandTarget*/,
												 IOleInPlaceFrame * /*pFrame*/,
												 IOleInPlaceUIWindow * /*pDoc*/)
{
	ASSERT(FALSE);

	return S_FALSE;
}

HRESULT CDocHostSite::XDocHostUIHandler2::HideUI()
{
	ASSERT(FALSE);

	return S_FALSE;
}

HRESULT CDocHostSite::XDocHostUIHandler2::UpdateUI()
{
	ASSERT(FALSE);

	return S_FALSE;
}

HRESULT CDocHostSite::XDocHostUIHandler2::EnableModeless(BOOL /*fEnable*/)
{
	ASSERT(FALSE);

	return S_FALSE;
}

HRESULT CDocHostSite::XDocHostUIHandler2::OnDocWindowActivate(BOOL /*fActivate*/)
{
	ASSERT(FALSE);

	return S_FALSE;
}

HRESULT CDocHostSite::XDocHostUIHandler2::OnFrameWindowActivate(BOOL /*fActivate*/)
{
	ASSERT(FALSE);

	return S_FALSE;
}

HRESULT CDocHostSite::XDocHostUIHandler2::ResizeBorder(LPCRECT /*prcBorder*/, 
													   IOleInPlaceUIWindow* /*pUIWindow*/,
													   BOOL /*fRameWindow*/)
{
	ASSERT(FALSE);

	return S_FALSE;
}

HRESULT CDocHostSite::XDocHostUIHandler2::ShowContextMenu(DWORD /*dwID*/, 
														  POINT* /*pptPosition*/,
														  IUnknown* /*pCommandTarget*/,
														  IDispatch* /*pDispatchObjectHit*/)
{
	ASSERT(FALSE);

	return S_FALSE;
}

HRESULT CDocHostSite::XDocHostUIHandler2::TranslateAccelerator(LPMSG /*lpMsg*/,
															   const GUID * /*pguidCmdGroup*/,
															   DWORD /*nCmdID*/)
{
	ASSERT(FALSE);

	return S_FALSE;
}

HRESULT CDocHostSite::XDocHostUIHandler2::GetOptionKeyPath(BSTR* /*pbstrKey*/, DWORD)
{
	ASSERT(FALSE);

	return S_FALSE;
}

HRESULT CDocHostSite::XDocHostUIHandler2::GetDropTarget(IDropTarget * /*pDropTarget*/,
														IDropTarget ** /*ppDropTarget*/)
{
	ASSERT(FALSE);

	return S_FALSE;
}

HRESULT CDocHostSite::XDocHostUIHandler2::GetExternal(IDispatch ** /*ppDispatch*/)
{
	ASSERT(FALSE);

	return S_FALSE;
}

HRESULT CDocHostSite::XDocHostUIHandler2::TranslateUrl(DWORD /*dwTranslate*/,
													   OLECHAR * /*pchURLIn*/,
													   OLECHAR ** /*ppchURLOut*/)
{
	ASSERT(FALSE);

	return S_FALSE;
}

HRESULT CDocHostSite::XDocHostUIHandler2::FilterDataObject(IDataObject * /*pDO*/,
														   IDataObject ** /*ppDORet*/)
{
	ASSERT(FALSE);

	return S_FALSE;
}

HRESULT CDocHostSite::XDocHostUIHandler2::GetOverrideKeyPath(LPOLESTR * pchKey, DWORD dw)
{
	METHOD_PROLOGUE(CDocHostSite, DocHostUIHandler2);

	return pThis->m_pView->OnGetOverrideKeyPath( pchKey, dw );
}

#endif

CDocHostOccManager::CDocHostOccManager()
	: m_pView( NULL ),
	m_pSite( NULL )
{
}

COleControlSite * CDocHostOccManager::CreateSite(COleControlContainer * pOcc)
{
	m_pSite = new CDocHostSite( pOcc );
	m_pSite->SetView( m_pView );
	return m_pSite;
}

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
Moldova (Republic of) Moldova (Republic of)
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions