CComQIPtr<IHTMLElement> spEleColl;
spHTMLDoc3->get_documentElement(&spEleColl);     //得到文档的根节点
CComPtr<IHTMLElementCollection> spEleCollAll;
HRESULT hr = spEleColl->get_all(&spEleCollAll);  //获取当前元素下的所有元素的 HtmlElementCollection是不是属性或是接口弄错了..spEleCollAll的值一直为空?

解决方案 »

  1.   

    用法错误。IHTMLElement::get_all获得的不是IHTMLElementCollection,而是IDispatch。
    CComPtr<IDispatch> spDisp;
    spEleColl->get_all(&spDisp);
    CComQIPtr<IHTMLElementCollection> spEleCollAll = spDisp;
      

  2.   

    不好意思..我问题没有说清楚..不是没有值,而是走到那句就出现IE遇到问题需要关闭,这是怎么回事呢二楼的朋友返回值表达获取当前元素下所有元素是否成功三楼的朋友我照你的写法改了...一样的..get_all那句依然是出现IE遇到问题需要关闭..
      

  3.   

    spEleColl的数据类型到底是什么?不要用CComQIPtr,要用CComPtr<IHTMLElement>
      

  4.   

    就是IHTMLElement接口类型, 用它来保存返回的文档的根结点 CComQIPtr<IHTMLStyleElement> spStyleEle;
    hr = spHTMLDoc2->createElement(_T("style"), (IHTMLElement**)&spStyleEle);   //创建元素style
    if (FAILED (hr) || !spStyleEle)
    {
    return;
    }

    //IHTMLElement::get_Style之后用IHTMLStyleElement的方法设置风格
    CComBSTR bstroldtype, bstrnewtype; /*spStyleEle ->get_type (&bstroldtype);         
    bstrnewtype = _T("text/css");
    hr = spStyleEle ->put_type (bstrnewtype);
    if (FAILED (hr))
    {
    return;
    }*/     
                                      

    CComPtr<IHTMLStyleSheet> spStyleSheet;
    hr = spStyleEle->get_styleSheet(&spStyleSheet);
    if (FAILED (hr) || !spStyleSheet)
    {
    return;
    } //TODO:字符串拼接
    STYLE_xarios_main.Append (STYLE_xarios_main_left);
    STYLE_xarios_main.Append (STYLE_xarios_main_right);
    STYLE_xarios_main.Append (STYLE_xarios_main_text);
    STYLE_xarios_main.Append (STYLE_xarios_main_blank);
    STYLE_xarios_main.Append (STYLE_contextmenu);
    STYLE_xarios_main.Append (STYLE_contextmenuitem);
    STYLE_xarios_main.Append (STYLE_contextmenuitem_hover); spStyleSheet->put_cssText(STYLE_xarios_main); CComPtr<IHTMLDOMNode> spNewNode2, spNewNodeBack2;
    spNewNode2 = spStyleEle;
    hr = spNode->appendChild(spNewNode2, &spNewNodeBack2);
    if (FAILED (hr) || !spNewNodeBack2)
    {
    return;
    }
    CComPtr<IHTMLElement> spEleColl;
    hr = spHTMLDoc3->get_documentElement(&spEleColl);         //得到文档的根节点
    if (FAILED (hr) || !spEleColl)
    {
    return;
    } CComPtr <IDispatch> spDisp; 
    hr = spEleColl->get_all(&spDisp); 
    CComQIPtr <IHTMLElementCollection> spEleCollAll = spDisp;就是我把那个get_type 和PUT_TYPE注释了后又编译过去了...怎么回事呢