我也正在试,有结果告诉你。不过你可以参考一些这个,虽然是c,但是转成delphi应该不难
void CMyClass::ConnectEvents(IHTMLElement* pElem)
{
HRESULT hr;
IConnectionPointContainer* pCPC = NULL;
IConnectionPoint* pCP = NULL;
DWORD dwCookie;
// Check that this is a connectable object.
hr = pElem->QueryInterface( IID_IConnectionPointContainer, (void**)&pCPC );
if ( SUCCEEDED(hr) )
{
// Find the connection point.
hr = pCPC->FindConnectionPoint( DIID_HTMLElementEvents2, &pCP );
if ( SUCCEEDED(hr) )
{
// Advise the connection point.
// pUnk is the IUnknown interface pointer for your event sink
hr = pCP->Advise( pUnk, &dwCookie );
if ( SUCCEEDED(hr) )
{
// Successfully advised
}
pCP->Release();
}
pCPC->Release();
}
}
STDMETHODIMP CEventSink::Invoke(
DISPID dispidMember,
REFIID riid,
LCID lcid,
WORD wFlags,
DISPPARAMS* pdispparams,
VARIANT* pvarResult,
EXCEPINFO* pexcepinfo,
UINT* puArgErr)
{
switch ( dispidMember )
{
case DISPID_HTMLELEMENTEVENTS2_ONCLICK:
OnClick();
break;
default:
break;
}
return S_OK;
}