请问利用IWebBrowser2的IWebBrowser2::get_Document怎样取得doc对象?

lide19 2002-12-30 03:05:28
我想分析IWebBrowser2返回的网页,可是他返回的是 LPDISPATCH !这是什么数据机构?怎样才能得到HTML文本供我分析?
LPDISPATCH CWebBrowser2::GetDocument()
有谁做过类似程序吗? 请各位大侠支招!
...全文
804 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
蒋晟 2003-01-09
  • 打赏
  • 举报
回复
see Programming and Reusing the Browser Overviews and Tutorials
in Platform SDK
lide19 2003-01-09
  • 打赏
  • 举报
回复
对不起,我说的是整个一个VC工程文件.这样,我可以直接在VC中慢慢看(向高手学习嘛),是不是有点懒? 大侠原谅! :-D
蒋晟 2003-01-08
  • 打赏
  • 举报
回复
上面不就是示例代码?
lide19 2003-01-08
  • 打赏
  • 举报
回复
多谢: jiangsheng(蒋晟.Net) !看样子是需要慢慢啃了.如果可以,能否把示例代码发到我的信箱: lidequan@hotmail.com
lide19 2003-01-02
  • 打赏
  • 举报
回复
好像还是不懂,第2种方法能更详细些吗?IID_IHTMLDocument2是表示什么类型的ID号,m_phtmlDoc又是怎样的数据,如何调用分析?
蒋晟 2003-01-02
  • 打赏
  • 举报
回复
void CSRWOnlineView::DocumentComplete(LPDISPATCH pDisp, VARIANT* URL)
{
//UNUSED_ALWAYS(pDisp);
ASSERT(V_VT(URL) == VT_BSTR);

CString str(V_BSTR(URL));
OnDocumentComplete(pDisp, str);
}

void CSRWOnlineView::OnDocumentComplete(LPDISPATCH pDisp, LPCTSTR lpszUrl)
{
// make sure the main frame has the new URL. This call also stops the animation
((CChildFrame*)GetParentFrame())->SetAddress(lpszUrl);
CString strURL(lpszUrl);
CComQIPtr<IWebBrowser2> pWebBrowser2(pDisp);
CHTMLCodeDlg HTMLCodeDlg;
if(pWebBrowser2){
CComQIPtr<IDispatch> pqiDisp;
pWebBrowser2->get_Document(&pqiDisp);
HTMLCodeDlg.m_pdocument=pqiDisp;
}
HTMLCodeDlg.DoModal();
}
BOOL CHTMLCodeDlg::OnInitDialog()
{
CDialog::OnInitDialog();
USES_CONVERSION;
if (m_pdocument){
CComQIPtr<IHTMLElement> pBody;
HRESULT hr = m_pdocument->get_body(&pBody);
if (FAILED(hr))
return FALSE;
CComBSTR bstrHTMLText;
hr = pBody->get_outerHTML(&bstrHTMLText);
if (FAILED(hr))
return FALSE;
// Convert the text from Unicode to ANSI
m_strText=OLE2T(bstrHTMLText);
}

UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CHTMLCodeDlg::OnApply()
{
if(!UpdateData())return;
USES_CONVERSION;
if (m_pdocument){
CComQIPtr<IHTMLElement> pBody;
HRESULT hr = m_pdocument->get_body(&pBody);
if (FAILED(hr))
return ;
CComBSTR bstrHTMLText((LPCTSTR)m_strText);
pBody->put_innerHTML(bstrHTMLText);
// Convert the text from Unicode to ANSI
}
OnOK();
}
去找本COM书啃啃先
蒋晟 2003-01-02
  • 打赏
  • 举报
回复
void CSRWOnlineView::DocumentComplete(LPDISPATCH pDisp, VARIANT* URL)
{
//UNUSED_ALWAYS(pDisp);
ASSERT(V_VT(URL) == VT_BSTR);

CString str(V_BSTR(URL));
OnDocumentComplete(pDisp, str);
}

void CSRWOnlineView::OnDocumentComplete(LPDISPATCH pDisp, LPCTSTR lpszUrl)
{
// make sure the main frame has the new URL. This call also stops the animation
((CChildFrame*)GetParentFrame())->SetAddress(lpszUrl);
CString strURL(lpszUrl);
CComQIPtr<IWebBrowser2> pWebBrowser2(pDisp);
CHTMLCodeDlg HTMLCodeDlg;
if(pWebBrowser2){
CComQIPtr<IDispatch> pqiDisp;
pWebBrowser2->get_Document(&pqiDisp);
HTMLCodeDlg.m_pdocument=pqiDisp;
}
HTMLCodeDlg.DoModal();
}
BOOL CHTMLCodeDlg::OnInitDialog()
{
CDialog::OnInitDialog();
USES_CONVERSION;
if (m_pdocument){
CComQIPtr<IHTMLElement> pBody;
HRESULT hr = m_pdocument->get_body(&pBody);
if (FAILED(hr))
return FALSE;
CComBSTR bstrHTMLText;
hr = pBody->get_outerHTML(&bstrHTMLText);
if (FAILED(hr))
return FALSE;
// Convert the text from Unicode to ANSI
m_strText=OLE2T(bstrHTMLText);
}

UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CHTMLCodeDlg::OnApply()
{
if(!UpdateData())return;
USES_CONVERSION;
if (m_pdocument){
CComQIPtr<IHTMLElement> pBody;
HRESULT hr = m_pdocument->get_body(&pBody);
if (FAILED(hr))
return ;
CComBSTR bstrHTMLText((LPCTSTR)m_strText);
pBody->put_innerHTML(bstrHTMLText);
// Convert the text from Unicode to ANSI
}
OnOK();
}
蒋晟 2003-01-02
  • 打赏
  • 举报
回复
void CSRWOnlineView::DocumentComplete(LPDISPATCH pDisp, VARIANT* URL)
{
//UNUSED_ALWAYS(pDisp);
ASSERT(V_VT(URL) == VT_BSTR);

CString str(V_BSTR(URL));
OnDocumentComplete(pDisp, str);
}

void CSRWOnlineView::OnDocumentComplete(LPDISPATCH pDisp, LPCTSTR lpszUrl)
{
// make sure the main frame has the new URL. This call also stops the animation
((CChildFrame*)GetParentFrame())->SetAddress(lpszUrl);
CString strURL(lpszUrl);
CComQIPtr<IWebBrowser2> pWebBrowser2(pDisp);
CHTMLCodeDlg HTMLCodeDlg;
if(pWebBrowser2){
CComQIPtr<IDispatch> pqiDisp;
pWebBrowser2->get_Document(&pqiDisp);
HTMLCodeDlg.m_pdocument=pqiDisp;
}
HTMLCodeDlg.DoModal();
}
BOOL CHTMLCodeDlg::OnInitDialog()
{
CDialog::OnInitDialog();
USES_CONVERSION;
if (m_pdocument){
CComQIPtr<IHTMLElement> pBody;
HRESULT hr = m_pdocument->get_body(&pBody);
if (FAILED(hr))
return FALSE;
CComBSTR bstrHTMLText;
hr = pBody->get_outerHTML(&bstrHTMLText);
if (FAILED(hr))
return FALSE;
// Convert the text from Unicode to ANSI
m_strText=OLE2T(bstrHTMLText);
}

UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CHTMLCodeDlg::OnApply()
{
if(!UpdateData())return;
USES_CONVERSION;
if (m_pdocument){
CComQIPtr<IHTMLElement> pBody;
HRESULT hr = m_pdocument->get_body(&pBody);
if (FAILED(hr))
return ;
CComBSTR bstrHTMLText((LPCTSTR)m_strText);
pBody->put_innerHTML(bstrHTMLText);
// Convert the text from Unicode to ANSI
}
OnOK();
}
蒋晟 2002-12-30
  • 打赏
  • 举报
回复
居然用错马甲……
mark again
jiangshengMKII 2002-12-30
  • 打赏
  • 举报
回复
mark
jiangshengMKII 2002-12-30
  • 打赏
  • 举报
回复
two way to get HTML interfaces
1 call CWnd::GetControlUnknown to get IWebbrowser2 Interface
LPUNKNOWN lpUnk = m_wndBrowser.GetControlUnknown();
HRESULT hr = lpUnk->QueryInterface(IID_IWebBrowser2, (void**) &m_pBrowserApp);

2 call CHtmlView::GetHtmlDocument() or CWebBrowser2::GetDocument()
LPDISPATCH lpDisp = m_wndBrowser.GetDocument();
HRESULT hr = lpDisp->QueryInterface(IID_IHTMLDocument2, (void**) &m_phtmlDoc);

note:objects which support IHTMLDocument2 may or may not support other interfaces,such as IHTMLDocument5 ,ICustomDoc or IXMLDOMDocument.

3,055

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC HTML/XML
社区管理员
  • HTML/XML社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧