在CHTMLView中调用IHTMLWindow2,来执行JS代码,可当此view中显示的不是网页,而是word文档内容,或是本地路径的文件夹内容时,程序运行到pIDoc->get_parentWindow(&pIhtmlwindow2);就死掉了,程序进行了get_parentWindow()就出不来了。
 具体代码如下:
    IHTMLDocument2* pIDoc = (IHTMLDocument2*) GetHtmlDocument();
HRESULT hr;
if(pIDoc ==NULL)
return FALSE;
IHTMLWindow2 * pIhtmlwindow2 = NULL;//= new IHTMLWindow2;
hr = pIDoc->get_parentWindow(&pIhtmlwindow2);
if(FAILED(hr))
{
pIDoc->Release();
return FALSE;
}
         ... 不明白其中缘故,请各位大侠不吝赐教,在此先谢谢了。

解决方案 »

  1.   

    这很简单,因为窗口已经加载为如syslistview32了。
    而不是Internet Explorer_Server了
    你用spy++查查就明白了。
      

  2.   

    (IHTMLDocument2*) GetHtmlDocument();
    这个有问题
    GetHtmlDocument()返回的不是HtmlDocument,是IDispatch。CComPtr<IDispatch> spDisp;
    spDisp.p = CHtmlView::GetHtmlDocument(); 
    CComQIPtr<IHTMLDocument2> pHTMLDocument2(spDisp);
    不过对于你这种情况,GetHtmlDocument()返回的是Word的_Document,不是HTMLDocument,用IHTMLDocument2接口访问当然会出问题
      

  3.   

    谢谢,请问那有没有办法判断GetHtmlDocument()返回的是不是HTMLdocument呢?
      

  4.   

    CComQIPtr<IHTMLDocument2> pHTMLDocument2(spDisp);
    之后判断pHTMLDocument2是否为空