to jiangsheng(蒋晟):
IE版本是:5.00.3315.1000
IE版本是:5.00.3315.1000
解决方案 »
- 一个VC和Flash通信的问题
- 有多少人投诉过上面这个《诚聘帖》?
- DoModal()对话框后在桌面上移动不移出父对话框的界面呢
- 请教大位大哥,哪有vs.net2005下载???
- 请问如何建立一个基类是CRichEditView的类?
- CString如何转换成CTime,用什么函数?
- 报表应满足什么条件?
- 请问m_pfile=new CSocketFile(this)和m_pfile=new CSocketFile()的意思和作用都一样的吗?
- Win32 Console Application 程序能不能使用CAsyncSocket?
- 远程控制的源码修改项目。有兴趣的来看看。
- Win2000下可以通过将自己作为一个线程诸如到系统进程中来实现
- 如何在CMainFrame中却得CDialogBar(从对话框资源模板)创建的对话框的HWND?
{
HRESULT hr;
IDispatch* pHtmlDoc = NULL;
IPersistStreamInit* pPersistStreamInit = NULL; // Retrieve the document object.
hr = pWebBrowser->get_Document( &pHtmlDoc );
if ( SUCCEEDED(hr) )
{
// Query for IPersistStreamInit.
hr = pHtmlDoc->QueryInterface( IID_IPersistStreamInit, (void**)&pPersistStreamInit );
if ( SUCCEEDED(hr) )
{
// Initialize the document.
hr = pPersistStreamInit->InitNew();
if ( SUCCEEDED(hr) )
{
// Load the contents of the stream.
hr = pPersistStreamInit->Load( pStream );
}
pPersistStreamInit->Release();
}
}
}
谢谢,Let me try.....
报相同的错,你写的一个函数好像跟我用语句写的没多大区别吧???出错的地方是Get_Document方法的调用,你帮我调调这一小段就好了,谢谢~~~~to lyneville(心佛):
没有办法了,懂这方面的人不多,只好出此下策了,呵呵~~~~~
我再看了一次,好像你的意思是说我调用的对象以及顺序都错了,right???
这里好像只提到了如何Load,Load完后怎么通过IHTMLDocument2接口进行处理呢????http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/tutorials/WebOCStream.asp?frame=true
怎么设置我的webbrowser里的文档呢????
问题出在哪??如何解决??
问题出在哪??如何解决??
回复人: superrg(秀华) (2002-1-21 17:26:56) 得0分
to jiangsheng(蒋晟):
这里好像只提到了如何Load,Load完后怎么通过IHTMLDocument2接口进行处理呢????http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/tutorials/WebOCStream.asp?frame=true
Navigating to about:blank(这个你没看?)
The IWebBrowser2::Navigate2 method of the IWebBrowser2 interface enables you to navigate the browser to a URL. In the following sample code, the IWebBrowser2::Navigate2 method is used to navigate to the about:blank page. Navigating to this empty page ensures that MSHTML is loaded and that the HTML elements are available through the Dynamic HTML (DHTML) Object Model.This example demonstrates how to navigate the WebBrowser control to an empty page. The variable m_pBrowser contains the IWebBrowser2 interface pointer obtained from the WebBrowser control.m_pBrowser->Navigate2( _T("about:blank"), NULL, NULL, NULL, NULL );
Availability of the DHTML Object Model
The DHTML Object Model is used to access and manipulate the contents of an HTML page and is not available until the page is loaded. Your application determines that a page is loaded by handling the DWebBrowserEvents2::DocumentComplete event of the WebBrowser control. This event may be fired once for each frame in the page, and once when the top frame of the document is loaded. You can determine if the DWebBrowserEvents2::DocumentComplete event is for the top frame by comparing the IDispatch interface pointer passed by this event with that of the WebBrowser control.This sample handler code for the WebBrowser DWebBrowserEvents2::DocumentComplete event demonstrates how to determine if this event is for the top frame, which indicates that the HTML page has loaded. This sample also demonstrates how to create a stream from a block of memory—in this case a string that contains the HTML content to be displayed.Hide Examplevoid myObject::DocumentComplete(LPDISPATCH pDisp, VARIANT* URL)
{
HRESULT hr;
IUnknown* pUnkBrowser = NULL;
IUnknown* pUnkDisp = NULL;
IStream* pStream = NULL;
HGLOBAL hHTMLText;
static char szHTMLText[] = "<html><h1>Stream Test</h1><p>This HTML content is/
being loaded from a stream.</html>"; // Is this the DocumentComplete event for the top frame window?
// Check COM identity: compare IUnknown interface pointers.
hr = m_pBrowser->QueryInterface( IID_IUnknown, (void**)&pUnkBrowser );
if ( SUCCEEDED(hr) )
{
hr = pDisp->QueryInterface( IID_IUnknown, (void**)&pUnkDisp );
if ( SUCCEEDED(hr) )
{
if ( pUnkBrowser == pUnkDisp )
{ // This is the DocumentComplete event for the top frame - page is loaded!
// Create a stream containing the HTML.
// Alternatively, this stream may have been passed to us.
hHTMLText = GlobalAlloc( GPTR, lstrlen(szHTMLText)+1 );
if ( hHTMLText )
{
lstrcpy( (char*)hHTMLText, szHTMLText );
hr = CreateStreamOnHGlobal( hHTMLText, TRUE, &pStream );
if ( SUCCEEDED(hr) )
{
// Call the helper function to load the Web Browser from the stream.
LoadWebBrowserFromStream( m_pBrowser, pStream );
pStream->Release();
}
GlobalFree( hHTMLText );
}
}
pUnkDisp->Release();
}
pUnkBrowser->Release();
}
}
Using QueryInterface to Obtain the IPersistStreamInit Interface
The IWebBrowser2::get_Document property on the WebBrowser control retrieves the document object that represents the DHTML Object Model for the top frame. MSHTML implements the IPersistStreamInit interface to provide the ability to load and save HTML using a stream, through the document object. The IDispatch interface for the document object can be queried for the IPersistStreamInit interface pointer using QueryInterface with an identifier of IID_IPersistStreamInit, as shown in the following code example.Hide ExampleHRESULT LoadWebBrowserFromStream(IWebBrowser* pWebBrowser, IStream* pStream)
{
HRESULT hr;
IDispatch* pHtmlDoc = NULL;
IPersistStreamInit* pPersistStreamInit = NULL; // Retrieve the document object.
hr = pWebBrowser->get_Document( &pHtmlDoc );
if ( SUCCEEDED(hr) )
{
// Query for IPersistStreamInit.
hr = pHtmlDoc->QueryInterface( IID_IPersistStreamInit, (void**)&pPersistStreamInit );
if ( SUCCEEDED(hr) )
{
// Initialize the document.
hr = pPersistStreamInit->InitNew();
if ( SUCCEEDED(hr) )
{
// Load the contents of the stream.
hr = pPersistStreamInit->Load( pStream );
}
pPersistStreamInit->Release();
}
}
}
Using the IPersistStreamInit Interface to Load HTML Content
The IPersistStreamInit interface has InitNew and Load methods that are used to initialize and load an HTML document from a stream. The InitNew method initializes the stream to a known state and the Load method loads the HTML content from the stream.In the previous sample code, the HTML document is initialized and the HTML content is loaded from the stream.Note In Microsoft Internet Explorer 5, more than one call to the Load method of the IPersist interfaces is supported. In earlier versions, only one call to Load per instance of MSHTML is supported.
Offline Reading
The following articles provide information about the Component Object Model (COM).Inside OLE, 2nd Edition, by Kraig Brockschmidt (Microsoft Press)
Understanding ActiveX and OLE, by David Chappell (Microsoft Press)
Inside COM, by Dale Rogerson (Microsoft Press)
现在看完了,照着做,结果运行时还是报错:
内存0X00000000不能为read~~~~~~~
如果直接用IHTMLDocument2的write方法,IHTMLDocument2的URL属性就会丢掉了,再解释脚本以及取Links都会出现问题~~~~~~
printf("hr = %d\n",hr);
//这里报错了
我想既然是LoadStream的,应该不用等吧??否则应该如何等待事件的发生呢???
怎么等???
void myObject::DocumentComplete(LPDISPATCH pDisp, VARIANT* URL)
{
HRESULT hr;
IUnknown* pUnkBrowser = NULL;
IUnknown* pUnkDisp = NULL;
IStream* pStream = NULL;
HGLOBAL hHTMLText;
static char szHTMLText[] = "<html><h1>Stream Test</h1><p>This HTML content is/
being loaded from a stream.</html>"; // Is this the DocumentComplete event for the top frame window?
// Check COM identity: compare IUnknown interface pointers.
hr = m_pBrowser->QueryInterface( IID_IUnknown, (void**)&pUnkBrowser );
if ( SUCCEEDED(hr) )
{
hr = pDisp->QueryInterface( IID_IUnknown, (void**)&pUnkDisp );
if ( SUCCEEDED(hr) )
{
if ( pUnkBrowser == pUnkDisp )
{ // This is the DocumentComplete event for the top frame - page is loaded!
// Create a stream containing the HTML.
// Alternatively, this stream may have been passed to us.
hHTMLText = GlobalAlloc( GPTR, lstrlen(szHTMLText)+1 );
if ( hHTMLText )
{
lstrcpy( (char*)hHTMLText, szHTMLText );
hr = CreateStreamOnHGlobal( hHTMLText, TRUE, &pStream );
if ( SUCCEEDED(hr) )
{
// Call the helper function to load the Web Browser from the stream.
LoadWebBrowserFromStream( m_pBrowser, pStream );
pStream->Release();
}
GlobalFree( hHTMLText );
}
}
pUnkDisp->Release();
}
pUnkBrowser->Release();
}
}
必须要界面吗????
好像walkall也是没有界面的呀~~~~~~~~~
应该是有事件的,不过怎么调用具体我就不清楚了~~~~~~~
应该不用两秒,但我见过一个例子,很奇怪的,必须要弹出一个MessageBox才能载入成功,否则就什么也不干的~~~~~~~~我也试过在那个例子中::Sleep(20000),但还是载入失败的,所以我想,等两秒钟还是不能解决问题的~~~~~~~~
如果我要开一千几百个线程,用有界面的应该怎么做呢????
我的基本思路如何不正确呀???你的邮箱是什么来的???
HRESULT CApp::LoadURLFromMoniker()
{
//load m_szURL
//use m_pMSHTML
IPersistStreamInit *pPersist = NULL;
m_pMSHTML->QueryInterface(IID_IPersistStreamInit,
(LPVOID *) &pPersist);
if (pPersist)
{
pPersist->InitNew();
IStream* pStream;
HRESULT hr = NOERROR;
char szWebSite[] = "http://www.163.net";
(URLOpenBlockingStream( 0, szWebSite, &pStream, 0, 0));
pPersist->Load(pStream);
pPersist->Release();
}
return S_OK;
}
也就是说一定要新建一个类,用事件来触发分析IHTMLDocument2的各个元素罗??是不是呀??怎么联系你???
当然要代码,越快越好,谢谢,我的地址是:
[email protected]
由于时间关系,本人不打算再等了,现在准备结贴,至于问题解决不了只能走另一种方案了。为感谢大家对本人的帮助,现请下列高手移步到下贴处再拿三百分,贴的地址为:
http://211.157.102.21/expert/topic/488/488742.shtm
高手名单列表如下:
masterz()
jiangsheng(蒋晟);
另外,如果horizon_tj(地平线)有调试用的源代码请速寄我一份,我的邮箱为
[email protected],收到源码后我再给你送分,谢谢;
而mickeyx(alanet.51.net),我进过你的网站看你的产品,的确很有名家风范,可惜一直未能谋面,本人随时恭候您指点一二,很希望有机会跟你合作,做一个成功的产品,要专家分要人民币都不成问题,谢谢~~~~~
[email protected]
能给代码我学习吗?谢谢
这个问题,其实可以用捕获异步事件而不是同步的流(IStream)来解决。
采用异步事件,将事件的响应和处理的类连接到IWebbrowser控件上,然后捕捉documentcomplete事件,在该事件中就可以得到IhtmlDocument接口。
看http://www.csdn.net/Expert/topic/492/492702.shtm