如果监控网页点击事件?
怎样用c 调用windows api, 完成以下功能:
用户点击网页里的某个特殊标签,那么该程序能够自动运行,并把该标签的值以及属性显示出来。
谢谢
问题点数:100、回复次数:6Top
1 楼jiangsheng(蒋晟.Net[MVP])回复于 2005-06-03 13:17:41 得分 97
http://msdn.microsoft.com/workshop/browser/mshtml/tutorials/sink.aspTop
2 楼mccxj(老鼠不逛街)回复于 2005-06-03 13:30:59 得分 2
Accessing an Element on the Page
Using the IHTMLDocument2 interface pointer, you can request a collection of all elements in the HTML document through the IHTMLDocument2::all property.
Hide Example
void CMyClass::ProcessDocument(IHTMLDocument2* pDoc)
{
IHTMLElementCollection* pElemColl = NULL;
hr = pDoc->get_all(&pElemColl);
if (SUCCEEDED(hr))
{
// Obtained element collection.
ProcessElementCollection(pElemColl);
pElemColl->Release();
}
}
Top
3 楼mccxj(老鼠不逛街)回复于 2005-06-03 13:31:57 得分 0
Receiving Element Events
Each element in the DHTML Object Model supports an outgoing HTMLElementEvents2 interface. This interface defines the events that an HTML element can fire. You implement this interface to provide an event sink, which is a Component Object Model (COM) object that implements an outgoing interface and is used as the mechanism for firing events.
Note Interfaces implemented by a server usually have their methods called by the client, but to fire an event, the server calls the respective method on the client event sink. These interface are called outgoing interfaces. A COM object that implements an outgoing interface is also known as a connectable object.
The following steps are required to receive events from an outgoing interface:
Implement the event sink.
The event sink implements the appropriate outgoing interface and methods. Internet Explorer event interfaces are dispinterfaces, so calls to event methods are made through IDispatch::Invoke. This means that you only need to implement the IDispatch interface to handle events.
Determine if the server is a connectable object.
Call QueryInterface to retrieve a pointer to the IConnectionPointContainer interface.
Find the appropriate connection point.
Call the IConnectionPointContainer::FindConnectionPoint method to find the connection point you need. For Internet Explorer WebBrowser Control events, such as DWebBrowserEvents2::DocumentComplete, this is DWebBrowserEvents2. For element events, this is HTMLElementEvents2. You can also call the IConnectionPointContainer::EnumConnectionPoints to enumerate through all the connection points a server supports.
Advise the connection point that you want to receive events.
Using the IConnectionPoint interface pointer returned in the previous step, call IConnectionPoint::Advise, passing the IUnknown interface pointer of your event sink.
Note The connectable object will use the IUnknown interface pointer to query the client for the event sink interface. If the event sink does not support the outgoing interface, Internet Explorer will query the client for the IDispatch interface.
When you no longer want to receive events, you can call the IConnectionPoint::Unadvise method, passing the cookie you received from the call to IConnectionPoint::Advise.
The following sample code demonstrates how to begin receiving HTML element events for an element on an HTML page.
Hide Example
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();
}
}
The following sample code demonstrates how you would detect the firing of an HTMLElementEvents2::onclick event in your implementation of IDispatch::Invoke.
Hide Example
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;
}
。。msdn上的实例。。Top
4 楼hzh_net(_风云_)回复于 2005-06-03 13:37:11 得分 1
http://msdn.microsoft.com/workshop/browser/mshtml/tutorials/sink.asp
这上面有,楼主自己去看
---------------------------------
呵呵
^_^
Top
5 楼hzh_net(_风云_)回复于 2005-06-03 13:37:51 得分 0
Receiving Element Events
Each element in the DHTML Object Model supports an outgoing HTMLElementEvents2 interface. This interface defines the events that an HTML element can fire. You implement this interface to provide an event sink, which is a Component Object Model (COM) object that implements an outgoing interface and is used as the mechanism for firing events.
Note Interfaces implemented by a server usually have their methods called by the client, but to fire an event, the server calls the respective method on the client event sink. These interface are called outgoing interfaces. A COM object that implements an outgoing interface is also known as a connectable object.
The following steps are required to receive events from an outgoing interface:
Implement the event sink.
The event sink implements the appropriate outgoing interface and methods. Internet Explorer event interfaces are dispinterfaces, so calls to event methods are made through IDispatch::Invoke. This means that you only need to implement the IDispatch interface to handle events.
Determine if the server is a connectable object.
Call QueryInterface to retrieve a pointer to the IConnectionPointContainer interface.
Find the appropriate connection point.
Call the IConnectionPointContainer::FindConnectionPoint method to find the connection point you need. For Internet Explorer WebBrowser Control events, such as DWebBrowserEvents2::DocumentComplete, this is DWebBrowserEvents2. For element events, this is HTMLElementEvents2. You can also call the IConnectionPointContainer::EnumConnectionPoints to enumerate through all the connection points a server supports.
Advise the connection point that you want to receive events.
Using the IConnectionPoint interface pointer returned in the previous step, call IConnectionPoint::Advise, passing the IUnknown interface pointer of your event sink.
Note The connectable object will use the IUnknown interface pointer to query the client for the event sink interface. If the event sink does not support the outgoing interface, Internet Explorer will query the client for the IDispatch interface.
When you no longer want to receive events, you can call the IConnectionPoint::Unadvise method, passing the cookie you received from the call to IConnectionPoint::Advise.
The following sample code demonstrates how to begin receiving HTML element events for an element on an HTML page.
Hide Example
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();
}
}
The following sample code demonstrates how you would detect the firing of an HTMLElementEvents2::onclick event in your implementation of IDispatch::Invoke.
Hide Example
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;
}
Top
6 楼mostideal(三甲)回复于 2005-06-03 14:19:13 得分 0
学习。。。Top




