www.pudn.com > holder.zip > MySite.cpp
#include "stdafx.h"
#include "MySite.h"
#include "HolderView.h"
//SAMPLE: Here, we just implement a constructor. We have no interesting
// data of our own, so we just call the base class constructor.
CMySite::CMySite(COleControlContainer* pCtrlCont)
: COleControlSite(pCtrlCont)
{
}
//SAMPLE: Since MFC doesn't export the definition for the COleControlSite
// map, we have to override GetInterfaceHook() to look for queries about
// IDocHostUIHandler. When we receive it, we'll return an address of the
// implementation we have in our class--otherwise, return NULL. We
// do _not_ have DECLARE_INTERFACE_MAP() or the related implementation
// macros in place because of this mechanism.
LPUNKNOWN CMySite::GetInterfaceHook(const void* piid)
{
ASSERT_POINTER(piid, IID);
const IID* pIID = (const IID*) piid;
if (*pIID == IID_IDocHostUIHandler)
return &m_xDocHostUIHandler;
return NULL;
}
//SAMPLE: Finally! Here, we implement GetExternal() to return an interface
// pointer back to the view.
STDMETHODIMP CMySite::XDocHostUIHandler::GetExternal(LPDISPATCH *lppDispatch)
{
METHOD_PROLOGUE_EX_(CMySite, DocHostUIHandler)
TRACE("Get external!!\n");
*lppDispatch = pThis->m_pCtrlCont->m_pWnd->GetIDispatch(TRUE);
return (lppDispatch == NULL) ? S_FALSE : S_OK;
}
//SAMPLE: we'll check the setting of the view's m_bAllowContextMenu
// member to see if we're to display the context menu or not.
STDMETHODIMP CMySite::XDocHostUIHandler::ShowContextMenu(
DWORD dwID, LPPOINT ppt, LPUNKNOWN /*pReserved*/, LPDISPATCH /* pReserved*/)
{
METHOD_PROLOGUE_EX_(CMySite, DocHostUIHandler)
CWnd* pParent = pThis->m_pCtrlCont->m_pWnd;
CHolderView* pHolderView = DYNAMIC_DOWNCAST(CHolderView, pParent);
// S_FALSE means we won't display it and we want IE to do it for us
HRESULT result = S_FALSE;
if (pHolderView == NULL || !pHolderView->m_bAllowContextMenu)
{
// S_OK means we displayed one, don't bother
result = S_OK;
CString str;
str.Format("IE would normally display context menu #%d at point (%d, %d), "
"but this sample has disabled the context menu. You can"
"review the code in CMySite::XDocHostUIHandler::ShowContextMenu() to "
"see how the context menu override was handled. You can renabled the"
"context menu using the \"allow context menu\" command in the View menu.",
dwID, ppt->x, ppt->y);
AfxMessageBox(str);
}
return result;
}
//SAMPLE: all methods after this comment just returns the default "do nothing"
// code to the HTML Control. You could override any of these if your app
// was interested in doing so, but we're not. So, we just pass on the
// invitation to react to the contained HTML page. At the very end are the
// stock AddRef(), Release(), and QueryInterface() implementations.
STDMETHODIMP CMySite::XDocHostUIHandler::GetHostInfo(struct _DOCHOSTUIINFO *)
{
return S_OK;
}
STDMETHODIMP CMySite::XDocHostUIHandler::ShowUI(unsigned long, LPOLEINPLACEACTIVEOBJECT,
LPOLECOMMANDTARGET, LPOLEINPLACEFRAME, LPOLEINPLACEUIWINDOW)
{
return S_FALSE;
}
STDMETHODIMP CMySite::XDocHostUIHandler::HideUI(void)
{
return S_OK;
}
STDMETHODIMP CMySite::XDocHostUIHandler::UpdateUI(void)
{
return S_OK;
}
STDMETHODIMP CMySite::XDocHostUIHandler::EnableModeless(int)
{
return S_OK;
}
STDMETHODIMP CMySite::XDocHostUIHandler::OnDocWindowActivate(int)
{
return S_OK;
}
STDMETHODIMP CMySite::XDocHostUIHandler::OnFrameWindowActivate(int)
{
return S_OK;
}
STDMETHODIMP CMySite::XDocHostUIHandler::ResizeBorder(LPCRECT, LPOLEINPLACEUIWINDOW, int)
{
return S_OK;
}
STDMETHODIMP CMySite::XDocHostUIHandler::TranslateAccelerator(LPMSG, const struct _GUID *,
unsigned long)
{
return S_FALSE;
}
STDMETHODIMP CMySite::XDocHostUIHandler::GetOptionKeyPath(unsigned short **, unsigned long)
{
return S_FALSE;
}
STDMETHODIMP CMySite::XDocHostUIHandler::GetDropTarget(LPDROPTARGET, LPDROPTARGET*)
{
return S_FALSE;
}
STDMETHODIMP CMySite::XDocHostUIHandler::TranslateUrl(unsigned long, OLECHAR* pchURLIn,
OLECHAR** ppchURLOut)
{
return S_FALSE;
}
STDMETHODIMP CMySite::XDocHostUIHandler::FilterDataObject(LPDATAOBJECT , LPDATAOBJECT*)
{
return S_FALSE;
}
STDMETHODIMP_(ULONG) CMySite::XDocHostUIHandler::AddRef()
{
METHOD_PROLOGUE_EX_(CMySite, DocHostUIHandler)
return pThis->ExternalAddRef();
}
STDMETHODIMP_(ULONG) CMySite::XDocHostUIHandler::Release()
{
METHOD_PROLOGUE_EX_(CMySite, DocHostUIHandler)
return pThis->ExternalRelease();
}
STDMETHODIMP CMySite::XDocHostUIHandler::QueryInterface(
REFIID iid, LPVOID far* ppvObj)
{
METHOD_PROLOGUE_EX_(CMySite, DocHostUIHandler)
return pThis->ExternalQueryInterface(&iid, ppvObj);
}