基于网页的元素消息传递,并不是按照传统的Windows消息驱动来实现的,即便是这样,微软在实现这种DHTML机制的同时隐藏了实现的细节. 微软在BHO实现机制中通过插件和事件连接点机制实现了用户代码的回调,只要你编写的组件实现了BHO,就可以拦截这些事件,执行你提供的事件代码.BHO相当于网页中"钩子". 如果你只是对网页中的网址感兴趣,也可以不采用BHO,比如可以采用多线程. 下面的代码可供参考.In C++, a connection can be accomplished in roughly the same way. Visual C++ Native Com Support is used here for the sake of brevity. Add references to Shdocvw.dll and Mshtml.dll to the project: #import <mshtml.dll> // Internet Explorer 4.0x #import <mshtml.tlb> // Internet Explorer 5 #import <shdocvw.dll> Declare an instance of an IShellWindows pointer in your view class: SHDocVw::IShellWindowsPtr m_spSHWinds; Create an instance of a ShellWindows object in your view's constructor: m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows)); Use the ShellWindows object in your view's OnInitialUpdate function: void CConnectIEView::OnInitialUpdate() { CFormView::OnInitialUpdate(); ASSERT(m_spSHWinds != NULL); CString strCount; long nCount = m_spSHWinds->GetCount(); strCount.Format("%i", nCount); m_strWinCount = strCount; UpdateData(FALSE); IDispatchPtr spDisp; for (long i = 0; i < nCount; i++) { _variant_t va(i, VT_I4); spDisp = m_spSHWinds->Item(va); SHDocVw::IWebBrowser2Ptr spBrowser(spDisp); if (spBrowser != NULL) { m_ctlListLoc.AddString(spBrowser->GetLocationName()); MSHTML::IHTMLDocument2Ptr spDoc(spBrowser->GetDocument()); if (spDoc != NULL) { m_ctlListTitle.AddString(spDoc->Gettitle()); } } } }
当我们在网页中,用鼠标左键点击链接的时候,是由系统扑获这样一个消息,然后调用IE去打开这个URL?
如果是这样的话,我想当系统调用IE去打开这个URL之前,先将这个消息扑获?不知道是否由这样一个函数?麻烦了!
微软在BHO实现机制中通过插件和事件连接点机制实现了用户代码的回调,只要你编写的组件实现了BHO,就可以拦截这些事件,执行你提供的事件代码.BHO相当于网页中"钩子".
如果你只是对网页中的网址感兴趣,也可以不采用BHO,比如可以采用多线程.
下面的代码可供参考.In C++, a connection can be accomplished in roughly the same way. Visual C++ Native Com Support is used here for the sake of brevity. Add references to Shdocvw.dll and Mshtml.dll to the project:
#import <mshtml.dll> // Internet Explorer 4.0x
#import <mshtml.tlb> // Internet Explorer 5
#import <shdocvw.dll>
Declare an instance of an IShellWindows pointer in your view class:
SHDocVw::IShellWindowsPtr m_spSHWinds;
Create an instance of a ShellWindows object in your view's constructor:
m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows));
Use the ShellWindows object in your view's OnInitialUpdate function:
void CConnectIEView::OnInitialUpdate()
{
CFormView::OnInitialUpdate(); ASSERT(m_spSHWinds != NULL); CString strCount;
long nCount = m_spSHWinds->GetCount(); strCount.Format("%i", nCount);
m_strWinCount = strCount; UpdateData(FALSE); IDispatchPtr spDisp;
for (long i = 0; i < nCount; i++)
{
_variant_t va(i, VT_I4);
spDisp = m_spSHWinds->Item(va); SHDocVw::IWebBrowser2Ptr spBrowser(spDisp);
if (spBrowser != NULL)
{
m_ctlListLoc.AddString(spBrowser->GetLocationName()); MSHTML::IHTMLDocument2Ptr spDoc(spBrowser->GetDocument());
if (spDoc != NULL)
{
m_ctlListTitle.AddString(spDoc->Gettitle());
}
}
}
}
我对这一方面也十分有兴趣,麻烦你给我一份,谢啦!
[email protected]
麻烦也给我一份!谢谢![email protected]
我也要一份,谢谢
[email protected]
go up
go to up
go to up
这个东西实在太好用了。
大家都狂顶吧。