#include <afxocc.h>
#include <afxhtml.h>
class CHtmlControlSite : public COleControlSite
{
public:
CHtmlControlSite(COleControlContainer* pParentWnd);
~CHtmlControlSite();
CHtmlView* GetView() const;
BEGIN_INTERFACE_PART(DocHostUIHandler, IDocHostUIHandler)
STDMETHOD(ShowContextMenu)(DWORD, LPPOINT, LPUNKNOWN, LPDISPATCH);
STDMETHOD(GetHostInfo)(DOCHOSTUIINFO*);
STDMETHOD(ShowUI)(DWORD, LPOLEINPLACEACTIVEOBJECT,
LPOLECOMMANDTARGET, LPOLEINPLACEFRAME, LPOLEINPLACEUIWINDOW);
STDMETHOD(HideUI)(void);
STDMETHOD(UpdateUI)(void);
STDMETHOD(EnableModeless)(BOOL);
STDMETHOD(OnDocWindowActivate)(BOOL);
STDMETHOD(OnFrameWindowActivate)(BOOL);
STDMETHOD(ResizeBorder)(LPCRECT, LPOLEINPLACEUIWINDOW, BOOL);
STDMETHOD(TranslateAccelerator)(LPMSG, const GUID*, DWORD);
STDMETHOD(GetOptionKeyPath)(OLECHAR **, DWORD);
STDMETHOD(GetDropTarget)(LPDROPTARGET, LPDROPTARGET*);
STDMETHOD(GetExternal)(LPDISPATCH*);
STDMETHOD(TranslateUrl)(DWORD, OLECHAR*, OLECHAR **);
STDMETHOD(FilterDataObject)(LPDATAOBJECT , LPDATAOBJECT*);
END_INTERFACE_PART(DocHostUIHandler)
DECLARE_INTERFACE_MAP()
};
class CMyOleControlSite : public CHtmlControlSite
{
public:
CMyOleControlSite(COleControlContainer *pCnt = NULL):CHtmlControlSite(pCnt) {}
BEGIN_INTERFACE_PART(Authenticate, IAuthenticate)
STDMETHODIMP Authenticate(
HWND __RPC_FAR *phwnd,
LPWSTR __RPC_FAR *pszUsername,
LPWSTR __RPC_FAR *pszPassword);
END_INTERFACE_PART(Authenticate)
BEGIN_INTERFACE_PART(ServiceProvider, IServiceProvider)
STDMETHODIMP QueryService(REFGUID guid, REFIID iid, LPVOID * ppv);
END_INTERFACE_PART(ServiceProvider)
DECLARE_INTERFACE_MAP();
};
MyOleControlSite.cpp #include "stdafx.h"
#include "MyOleControlSite.h"
BEGIN_INTERFACE_MAP(CMyOleControlSite, CHtmlControlSite)
INTERFACE_PART(CMyOleControlSite, IID_IAuthenticate, Authenticate)
INTERFACE_PART(CMyOleControlSite, IID_IServiceProvider, ServiceProvider)
END_INTERFACE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyOleControlSite: IAthenticate::IUnknown methods
ULONG CMyOleControlSite::XAuthenticate::AddRef()
{
METHOD_PROLOGUE(CMyOleControlSite, Authenticate)
return pThis->ExternalAddRef();
}
ULONG CMyOleControlSite::XAuthenticate::Release()
{
METHOD_PROLOGUE(CMyOleControlSite, Authenticate)
return pThis->ExternalRelease();
}
HRESULT CMyOleControlSite::XAuthenticate::QueryInterface(REFIID riid, void **ppvObj)
{
METHOD_PROLOGUE(CMyOleControlSite, Authenticate)
HRESULT hr = (HRESULT)pThis->ExternalQueryInterface(&riid, ppvObj);
return hr;
}
/////////////////////////////////////////////////////////////////////////////
// CMyOleControlSite: Authenticate methods
STDMETHODIMP CMyOleControlSite::XAuthenticate::Authenticate(
HWND __RPC_FAR *phwnd,
LPWSTR __RPC_FAR *pszUsername,
LPWSTR __RPC_FAR *pszPassword)
{
METHOD_PROLOGUE(CMyOleControlSite, Authenticate)
// add code from next step
return S_OK;
}
//
// IServiceProvider
//
ULONG CMyOleControlSite::XServiceProvider::AddRef()
{
METHOD_PROLOGUE(CMyOleControlSite, ServiceProvider)
return pThis->ExternalAddRef();
}
ULONG CMyOleControlSite::XServiceProvider::Release()
{
METHOD_PROLOGUE(CMyOleControlSite, ServiceProvider)
return pThis->ExternalRelease();
}
HRESULT CMyOleControlSite::XServiceProvider::QueryInterface(REFIID riid, void **ppvObj)
{
METHOD_PROLOGUE(CMyOleControlSite, ServiceProvider)
HRESULT hr = (HRESULT)pThis->ExternalQueryInterface(&riid, ppvObj);
return hr;
}
STDMETHODIMP CMyOleControlSite::XServiceProvider::QueryService(REFGUID sid, REFIID iid, LPVOID * ppv)
{
METHOD_PROLOGUE(CMyOleControlSite, ServiceProvider)
if (sid == IID_IAuthenticate || iid == IID_IAuthenticate) {
return (HRESULT)pThis->ExternalQueryInterface(&iid, ppv);
} else {
*ppv = NULL;
}
return E_NOINTERFACE;
}
ProxyTestView.h class CProxyTestView : public CHtmlView
{
...
BOOL CreateControlSite(COleControlContainer* pContainer,
COleControlSite** ppSite, UINT nID, REFCLSID clsid);
ProxyTestView.cpp BOOL CProxyTestView::CreateControlSite(COleControlContainer* pContainer,
COleControlSite** ppSite, UINT nID, REFCLSID clsid)
{
ASSERT(ppSite != NULL);
*ppSite = new CMyOleControlSite(pContainer);
return TRUE;
}