Web Browser 的扩展



	CComPtr<IUnknown> spUnk;
	HRESULT hr = CExternalUIHandler::_CreatorClass::CreateInstance(NULL, IID_IUnknown, (void**)&spUnk);
	ATLASSERT(SUCCEEDED(hr));
	CComQIPtr<IDocHostUIHandlerDispatch> spUI = spUnk;
	m_wtlBrowserView.SetExternalUIHandler(spUI);



#ifndef _EXTERNALUIHANDLER_H_
#define _EXTERNALUIHANDLER_H_
#pragma once
class CExternalDisp:
	public CComObjectRoot,
	public IDispatch
{
public:
	CExternalDisp(void);
	~CExternalDisp(void);
	BEGIN_COM_MAP(CExternalDisp)
		COM_INTERFACE_ENTRY(IDispatch)
	END_COM_MAP()

	virtual HRESULT STDMETHODCALLTYPE GetTypeInfoCount( 
	/* [out] */ UINT *pctinfo);

	virtual HRESULT STDMETHODCALLTYPE GetTypeInfo( 
	/* [in] */ UINT iTInfo,
	/* [in] */ LCID lcid,
	/* [out] */ ITypeInfo **ppTInfo);

	virtual HRESULT STDMETHODCALLTYPE GetIDsOfNames( 
	/* [in] */ REFIID riid,
	/* [size_is][in] */ LPOLESTR *rgszNames,
	/* [in] */ UINT cNames,
	/* [in] */ LCID lcid,
	/* [size_is][out] */ DISPID *rgDispId);

	virtual /* [local] */ HRESULT STDMETHODCALLTYPE Invoke( 
	/* [in] */ DISPID dispIdMember,
	/* [in] */ REFIID riid,
	/* [in] */ LCID lcid,
	/* [in] */ WORD wFlags,
	/* [out][in] */ DISPPARAMS *pDispParams,
	/* [out] */ VARIANT *pVarResult,
	/* [out] */ EXCEPINFO *pExcepInfo,
	/* [out] */ UINT *puArgErr) ;

};


class ATL_NO_VTABLE CExternalUIHandler : 
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CExternalUIHandler>,
	public IDispatchImpl<IDocHostUIHandlerDispatch, &__uuidof(IDocHostUIHandlerDispatch)>
{
public:
	CComQIPtr<IDispatch> m_spExtDispatch;

public:
	CExternalUIHandler();

	DECLARE_PROTECT_FINAL_CONSTRUCT()

	BEGIN_COM_MAP(CExternalUIHandler)
		COM_INTERFACE_ENTRY(IDocHostUIHandlerDispatch)
		COM_INTERFACE_ENTRY(IDispatch)
	END_COM_MAP()

	// IXmnWrapperUIHandler
public:
	// Do not show the context menu
	STDMETHOD (ShowContextMenu) ( 
		/* [in] */ DWORD dwID,
		/* [in] */ DWORD x,
		/* [in] */ DWORD y,
		/* [in] */ IUnknown  *pcmdtReserved,
		/* [in] */ IDispatch *pdispReserved,
		/* [retval][out] */ HRESULT  *dwRetVal);
	// Mark all the other methods as not implemented

	STDMETHOD (GetHostInfo) ( 
		/* [out][in] */ DWORD  *pdwFlags,
		/* [out][in] */ DWORD  *pdwDoubleClick);


	STDMETHOD (ShowUI) ( 
		/* [in] */ DWORD dwID,
		/* [in] */ IUnknown  *pActiveObject,
		/* [in] */ IUnknown  *pCommandTarget,
		/* [in] */ IUnknown  *pFrame,
		/* [in] */ IUnknown  *pDoc,
		/* [retval][out] */ HRESULT  *dwRetVal);


	STDMETHOD (HideUI) (void);


	STDMETHOD (UpdateUI) (void);

	STDMETHOD (EnableModeless) ( 
		/* [in] */ VARIANT_BOOL fEnable);


	STDMETHOD (OnDocWindowActivate) ( 
		/* [in] */ VARIANT_BOOL fActivate);


	STDMETHOD (OnFrameWindowActivate) ( 
		/* [in] */ VARIANT_BOOL fActivate);

	STDMETHOD (ResizeBorder) ( 
		/* [in] */ long left,
		/* [in] */ long top,
		/* [in] */ long right,
		/* [in] */ long bottom,
		/* [in] */ IUnknown  *pUIWindow,
		/* [in] */ VARIANT_BOOL fFrameWindow);

	STDMETHOD (TranslateAccelerator) ( 
		/* [in] */ DWORD hWnd,
		/* [in] */ DWORD nMessage,
		/* [in] */ DWORD wParam,
		/* [in] */ DWORD lParam,
		/* [in] */ BSTR bstrGuidCmdGroup,
		/* [in] */ DWORD nCmdID,
		/* [retval][out] */ HRESULT  *dwRetVal);


	STDMETHOD (GetOptionKeyPath) ( 
		/* [out] */ BSTR  *pbstrKey,
		/* [in] */ DWORD dw);

	STDMETHOD (GetDropTarget) ( 
		/* [in] */ IUnknown  *pDropTarget,
		/* [out] */ IUnknown  **ppDropTarget);

	STDMETHOD (GetExternal) ( 
		/* [out] */ IDispatch  **ppDispatch);


	STDMETHOD (TranslateUrl) ( 
		/* [in] */ DWORD dwTranslate,
		/* [in] */ BSTR bstrURLIn,
		/* [out] */ BSTR  *pbstrURLOut);


	STDMETHOD (FilterDataObject) ( 
		/* [in] */ IUnknown  *pDO,
		/* [out] */ IUnknown  **ppDORet);
};
#endif //_EXTERNALUIHANDLER_H_



#include "stdafx.h"
#include "ExternalUIHandler.h"
#include "DBPrivateHistory.h"
CExternalDisp::CExternalDisp(void){};
CExternalDisp::~CExternalDisp(void){};

HRESULT STDMETHODCALLTYPE CExternalDisp::GetTypeInfoCount( 
	/* [out] */ UINT *pctinfo) 
{
	return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE CExternalDisp::GetTypeInfo( 
									  /* [in] */ UINT iTInfo,
									  /* [in] */ LCID lcid,
									  /* [out] */ ITypeInfo **ppTInfo)
{
	return E_NOTIMPL;
}

HRESULT STDMETHODCALLTYPE CExternalDisp::GetIDsOfNames( 
	/* [in] */ REFIID riid,
	/* [size_is][in] */ LPOLESTR *rgszNames,
	/* [in] */ UINT cNames,
	/* [in] */ LCID lcid,
	/* [size_is][out] */ DISPID *rgDispId)
{
	CComBSTR bsName(*rgszNames);
	if (bsName == OLESTR("DeleteRowID"))
	{
		*rgDispId = 2535;
		return S_OK;
	} else if (bsName == OLESTR("DeleteMsgID"))
	{
		*rgDispId = 2537;
		return S_OK;
	}
	return E_NOTIMPL;

}

HRESULT STDMETHODCALLTYPE CExternalDisp::Invoke( 
	/* [in] */ DISPID dispIdMember,
	/* [in] */ REFIID riid,
	/* [in] */ LCID lcid,
	/* [in] */ WORD wFlags,
	/* [out][in] */ DISPPARAMS *pDispParams,
	/* [out] */ VARIANT *pVarResult,
	/* [out] */ EXCEPINFO *pExcepInfo,
	/* [out] */ UINT *puArgErr) 
{
	//参数顺序为从右向左
	if (dispIdMember == 2535)
	{
		if (pDispParams->cArgs != 1) return E_NOTIMPL;
		if( pDispParams->rgvarg[0].vt != VT_I4) return E_NOTIMPL;
		int nRowID=pDispParams->rgvarg[0].intVal;
		return S_OK;
	}else if (dispIdMember == 2537)
	{
		if (pDispParams->cArgs != 1) return E_NOTIMPL;
		if( pDispParams->rgvarg[0].vt != VT_BSTR) return E_NOTIMPL;
		//pDispParams->rgvarg[1].bstrVal

		return S_OK;
	}
	return E_NOTIMPL;
}



//

CExternalUIHandler::CExternalUIHandler()
{
	CComObject<CExternalDisp> *obj;
	CComObject<CExternalDisp>::CreateInstance(&obj);
	obj->QueryInterface(IID_IDispatch, (void**)&m_spExtDispatch);
}

// Do not show the context menu
HRESULT STDMETHODCALLTYPE CExternalUIHandler::ShowContextMenu( 
							 /* [in] */ DWORD dwID,
							 /* [in] */ DWORD x,
							 /* [in] */ DWORD y,
							 /* [in] */ IUnknown  *pcmdtReserved,
							 /* [in] */ IDispatch *pdispReserved,
							 /* [retval][out] */ HRESULT  *dwRetVal)
{
	*dwRetVal = S_OK;
	return S_OK;
}

HRESULT STDMETHODCALLTYPE CExternalUIHandler::GetHostInfo ( 
						 /* [out][in] */ DWORD  *pdwFlags,
						 /* [out][in] */ DWORD  *pdwDoubleClick)
{
	return E_NOTIMPL;
}



HRESULT STDMETHODCALLTYPE CExternalUIHandler::ShowUI( 
					/* [in] */ DWORD dwID,
					/* [in] */ IUnknown  *pActiveObject,
					/* [in] */ IUnknown  *pCommandTarget,
					/* [in] */ IUnknown  *pFrame,
					/* [in] */ IUnknown  *pDoc,
					/* [retval][out] */ HRESULT  *dwRetVal)
{
	return E_NOTIMPL;
}


HRESULT STDMETHODCALLTYPE CExternalUIHandler::HideUI(void)
{
	return E_NOTIMPL;
}


HRESULT STDMETHODCALLTYPE CExternalUIHandler::UpdateUI(void)
{
	return E_NOTIMPL;
}

HRESULT STDMETHODCALLTYPE CExternalUIHandler::EnableModeless( 
							/* [in] */ VARIANT_BOOL fEnable)
{
	return E_NOTIMPL;
}


HRESULT STDMETHODCALLTYPE CExternalUIHandler::OnDocWindowActivate( 
								 /* [in] */ VARIANT_BOOL fActivate)
{
	return E_NOTIMPL;
}


HRESULT STDMETHODCALLTYPE CExternalUIHandler::OnFrameWindowActivate( 
								   /* [in] */ VARIANT_BOOL fActivate)
{
	return E_NOTIMPL;
}


HRESULT STDMETHODCALLTYPE CExternalUIHandler::ResizeBorder( 
						  /* [in] */ long left,
						  /* [in] */ long top,
						  /* [in] */ long right,
						  /* [in] */ long bottom,
						  /* [in] */ IUnknown  *pUIWindow,
						  /* [in] */ VARIANT_BOOL fFrameWindow)
{
	return E_NOTIMPL;
}


HRESULT STDMETHODCALLTYPE CExternalUIHandler::TranslateAccelerator( 
								  /* [in] */ DWORD hWnd,
								  /* [in] */ DWORD nMessage,
								  /* [in] */ DWORD wParam,
								  /* [in] */ DWORD lParam,
								  /* [in] */ BSTR bstrGuidCmdGroup,
								  /* [in] */ DWORD nCmdID,
								  /* [retval][out] */ HRESULT  *dwRetVal)
{
	return E_NOTIMPL;
}


HRESULT STDMETHODCALLTYPE CExternalUIHandler::GetOptionKeyPath( 
							  /* [out] */ BSTR  *pbstrKey,
							  /* [in] */ DWORD dw)
{
	return E_NOTIMPL;
}


HRESULT STDMETHODCALLTYPE CExternalUIHandler::GetDropTarget( 
						   /* [in] */ IUnknown  *pDropTarget,
						   /* [out] */ IUnknown  **ppDropTarget)
{
	return E_NOTIMPL;
}


HRESULT STDMETHODCALLTYPE CExternalUIHandler::GetExternal( 
						 /* [out] */ IDispatch  **ppDispatch)
{
	return m_spExtDispatch.CopyTo(ppDispatch);
}


HRESULT STDMETHODCALLTYPE CExternalUIHandler::TranslateUrl( 
						  /* [in] */ DWORD dwTranslate,
						  /* [in] */ BSTR bstrURLIn,
						  /* [out] */ BSTR  *pbstrURLOut)
{
	return E_NOTIMPL;
}


HRESULT STDMETHODCALLTYPE CExternalUIHandler::FilterDataObject( 
							  /* [in] */ IUnknown  *pDO,
							  /* [out] */ IUnknown  **ppDORet)
{
	return E_NOTIMPL;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值