我的代码如下#include <exdispid.h>
#include "browser.h"
/**
* @brief Html显示视
*/
class CHtmlShowView:
public CWindowImpl<CHtmlShowView, CAxWindow>,
public CWebBrowser2<CHtmlShowView>
{
public:
HWND m_parentWnd;
CEdit *m_URL;
CMultiPaneStatusBarCtrl *m_StatusBar;
CListViewCtrl *m_PostListView;
CListViewCtrl *m_HeaderListView;
CRichEditCtrl *m_PostRowDataShow;
BOOL m_isAnalyer;
_bstr_t m_requestURL; //请求URL
string m_domain; //请求域
DECLARE_WND_SUPERCLASS(NULL, CAxWindow::GetWndClassName())
CHtmlShowView(void):m_parentWnd(NULL),m_URL(NULL),m_StatusBar(NULL),m_isAnalyer(FALSE)
{
AtlAxWinInit();
m_requestURL = "";
m_domain = "";
}
~CHtmlShowView(void){} BOOL PreTranslateMessage(MSG* pMsg)
{
if((pMsg->message < WM_KEYFIRST || pMsg->message > WM_KEYLAST) &&
(pMsg->message < WM_MOUSEFIRST || pMsg->message > WM_MOUSELAST))
return FALSE;
return (BOOL)SendMessage(WM_FORWARDMSG, 0, (LPARAM)pMsg);
} BEGIN_MSG_MAP(CHtmlShowView)
CHAIN_MSG_MAP(CWebBrowser2<CHtmlShowView>)
END_MSG_MAP() BOOL StartHtml(LPCTSTR url)
{
Stop();
m_isAnalyer = TRUE;
CComPtr<IWebBrowser2> webBrowser2;
m_requestURL = "";
m_domain = "";
HRESULT hr=this->QueryControl(__uuidof(IWebBrowser2),(void **)&webBrowser2);
if(SUCCEEDED(hr))
webBrowser2->Navigate(_bstr_t(url),NULL,NULL,NULL,NULL);
return SUCCEEDED(hr);
} //重载IE事件
BOOL OnNewWindow2(IDispatch** ppDisp)
{
return TRUE;
} void OnDocumentComplete(IDispatch* pDisp, const CComBSTR& szURL)
{
IUnknown *pUnk = NULL;
HRESULT hr=this->QueryControl(__uuidof(IUnknown),(void **)&pUnk);
ATLASSERT(pUnk); LPDISPATCH lpWBDisp = NULL;
hr = pUnk->QueryInterface(IID_IDispatch, (void**)&lpWBDisp);
ATLASSERT(SUCCEEDED(hr));
if (pDisp == lpWBDisp )
{
m_requestURL = "";
m_domain = "";
::PostMessage(m_parentWnd,MSG_SHOWTREE,(WPARAM)pDisp,(LPARAM)&szURL);
if(m_isAnalyer)
{
m_isAnalyer = FALSE;
::PostMessage(m_parentWnd,MSG_ANALYSER,(WPARAM)pDisp,(LPARAM)&szURL);
}
}
lpWBDisp->Release();
} string GetDomainUrl(LPCSTR lpUrl)
{
string domain;
LPCSTR lpStart = ::StrStrI(lpUrl,"http://");
if(lpStart!=NULL)
{
lpStart+=7;
LPCSTR lpEnd = ::StrStrI(lpStart,"/");
if(lpEnd != NULL)
{
lpStart = ::StrStrI(lpStart,".");
if(lpStart != NULL && lpEnd != NULL)
{
if(lpStart < lpEnd)
{
domain.append((char *)lpStart,lpEnd-lpStart);
}
}
}
}
return domain;
} BOOL OnBeforeNavigate2(IDispatch* pDisp, const CComBSTR& szURL, DWORD dwFlags, const CComBSTR& szTargetFrameName, string &postedData, const CComBSTR& szHeaders)
{
return FALSE;
} void OnNavigateComplete2(IDispatch* pDisp, const CComBSTR& szURL)
{
ATLASSERT(m_URL!=NULL);
m_requestURL = _bstr_t(GetLocationURL());
m_URL->SetWindowText(m_requestURL.operator char *());
} void OnStatusTextChange(const CComBSTR szText)
{
ATLASSERT(m_StatusBar!=NULL);
m_StatusBar->SetPaneText(ID_DEFAULT_PANE,_bstr_t(szText));
} void OnProgressChange(long nProgress, long nProgressMax)
{
ATLASSERT(m_StatusBar!=NULL);
CString szText;
if (nProgressMax>0 && nProgress >0)
{
int percentage=(nProgress*100)/nProgressMax;
if(percentage >100)
percentage=100;
else if(percentage<0)
percentage=0;
szText.Format(_T("%d%%"),percentage);
}
m_StatusBar->SetPaneText(IDR_PROGRESS,szText);
}
};主要就是OnDocumentComplete回调,回调后对文档进行解决后DOM树不完整
我想知道大家是如何处理一个页面什么时后完成.
#include "browser.h"
/**
* @brief Html显示视
*/
class CHtmlShowView:
public CWindowImpl<CHtmlShowView, CAxWindow>,
public CWebBrowser2<CHtmlShowView>
{
public:
HWND m_parentWnd;
CEdit *m_URL;
CMultiPaneStatusBarCtrl *m_StatusBar;
CListViewCtrl *m_PostListView;
CListViewCtrl *m_HeaderListView;
CRichEditCtrl *m_PostRowDataShow;
BOOL m_isAnalyer;
_bstr_t m_requestURL; //请求URL
string m_domain; //请求域
DECLARE_WND_SUPERCLASS(NULL, CAxWindow::GetWndClassName())
CHtmlShowView(void):m_parentWnd(NULL),m_URL(NULL),m_StatusBar(NULL),m_isAnalyer(FALSE)
{
AtlAxWinInit();
m_requestURL = "";
m_domain = "";
}
~CHtmlShowView(void){} BOOL PreTranslateMessage(MSG* pMsg)
{
if((pMsg->message < WM_KEYFIRST || pMsg->message > WM_KEYLAST) &&
(pMsg->message < WM_MOUSEFIRST || pMsg->message > WM_MOUSELAST))
return FALSE;
return (BOOL)SendMessage(WM_FORWARDMSG, 0, (LPARAM)pMsg);
} BEGIN_MSG_MAP(CHtmlShowView)
CHAIN_MSG_MAP(CWebBrowser2<CHtmlShowView>)
END_MSG_MAP() BOOL StartHtml(LPCTSTR url)
{
Stop();
m_isAnalyer = TRUE;
CComPtr<IWebBrowser2> webBrowser2;
m_requestURL = "";
m_domain = "";
HRESULT hr=this->QueryControl(__uuidof(IWebBrowser2),(void **)&webBrowser2);
if(SUCCEEDED(hr))
webBrowser2->Navigate(_bstr_t(url),NULL,NULL,NULL,NULL);
return SUCCEEDED(hr);
} //重载IE事件
BOOL OnNewWindow2(IDispatch** ppDisp)
{
return TRUE;
} void OnDocumentComplete(IDispatch* pDisp, const CComBSTR& szURL)
{
IUnknown *pUnk = NULL;
HRESULT hr=this->QueryControl(__uuidof(IUnknown),(void **)&pUnk);
ATLASSERT(pUnk); LPDISPATCH lpWBDisp = NULL;
hr = pUnk->QueryInterface(IID_IDispatch, (void**)&lpWBDisp);
ATLASSERT(SUCCEEDED(hr));
if (pDisp == lpWBDisp )
{
m_requestURL = "";
m_domain = "";
::PostMessage(m_parentWnd,MSG_SHOWTREE,(WPARAM)pDisp,(LPARAM)&szURL);
if(m_isAnalyer)
{
m_isAnalyer = FALSE;
::PostMessage(m_parentWnd,MSG_ANALYSER,(WPARAM)pDisp,(LPARAM)&szURL);
}
}
lpWBDisp->Release();
} string GetDomainUrl(LPCSTR lpUrl)
{
string domain;
LPCSTR lpStart = ::StrStrI(lpUrl,"http://");
if(lpStart!=NULL)
{
lpStart+=7;
LPCSTR lpEnd = ::StrStrI(lpStart,"/");
if(lpEnd != NULL)
{
lpStart = ::StrStrI(lpStart,".");
if(lpStart != NULL && lpEnd != NULL)
{
if(lpStart < lpEnd)
{
domain.append((char *)lpStart,lpEnd-lpStart);
}
}
}
}
return domain;
} BOOL OnBeforeNavigate2(IDispatch* pDisp, const CComBSTR& szURL, DWORD dwFlags, const CComBSTR& szTargetFrameName, string &postedData, const CComBSTR& szHeaders)
{
return FALSE;
} void OnNavigateComplete2(IDispatch* pDisp, const CComBSTR& szURL)
{
ATLASSERT(m_URL!=NULL);
m_requestURL = _bstr_t(GetLocationURL());
m_URL->SetWindowText(m_requestURL.operator char *());
} void OnStatusTextChange(const CComBSTR szText)
{
ATLASSERT(m_StatusBar!=NULL);
m_StatusBar->SetPaneText(ID_DEFAULT_PANE,_bstr_t(szText));
} void OnProgressChange(long nProgress, long nProgressMax)
{
ATLASSERT(m_StatusBar!=NULL);
CString szText;
if (nProgressMax>0 && nProgress >0)
{
int percentage=(nProgress*100)/nProgressMax;
if(percentage >100)
percentage=100;
else if(percentage<0)
percentage=0;
szText.Format(_T("%d%%"),percentage);
}
m_StatusBar->SetPaneText(IDR_PROGRESS,szText);
}
};主要就是OnDocumentComplete回调,回调后对文档进行解决后DOM树不完整
我想知道大家是如何处理一个页面什么时后完成.
解决方案 »
- 通过creat动态创建静态文本框 为什么不放松WM_CTLCOLOR消息(急疯了)
- 来者有分!!!!!!!!!!!!!!
- 用vc++来生成一个xml文档,重谢!!!
- 郁闷!Not all windows in worksapce could be opened?
- 请问谁有费尔防火墙的源代码?
- 如何改变状态条的里面的字体和背景颜色
- 不再沉默中爆发,就在沉默中灭亡,我不想“死”,请大家帮帮我!!!在线
- 我想得到OLEVIEW的核心代码,用来实现以下功能:
- 非常问题,动机是送分,我只是菜鸟!!!
- 请问CTreeCtrl中如何设置label中的text的字体大小和粗细?谢谢
- WebBrowser的Navigate方法能不能连续使用?
- 有关广域网模拟软件WANem的问题
get_busy() 等
get_busy() 为 0
状态为完成状态
解释角本,DOM树不完整,是否对于一些角本还没有运行完成
OnDocumentComplete2()都可以.
get_busy()==0判断为完成状态
另外,你的网页如果有几个框架的话,会调用多次这个OnDocumentComplete()事件的,这时可能要作一下计数,例如你有3个框架,那就每OnDocumentComplete()一次就times++,当times==3时,才是三个框架全部载入完成,利用你打开CSDN论坛的贴子看看,有N个框架的.
正在用ZedGraph控件,也正在想办法确定图片是否已经加载完呢,
void CXXHtmlView::OnDocumentComplete(LPCTSTR lpszURL)
{
CHtmlView::OnDocumentComplete(lpszURL);
// The document is not complete until all of its data has been retrieved
if(GetReadyState() != READYSTATE_COMPLETE) return;
// Do something useful
}