不用这么麻烦吧
干脆把整个HTML页的outerHtml村成CString
然后Find("<head>")之后加css
然后put_outerHTML回去

解决方案 »

  1.   

    你想想啊,要是我的HTML里没写<head>你不是废了?
      

  2.   

    没有关系,我的html全部都是自己生成的。是个封闭的系统。
      

  3.   

    解决了。
    IHTMLDocument2 *pDoc;
    if(SUCCEEDED(HrGetDoc(&pDoc)))
    {
    CString strScript = "";
    BSTR bstrContent = strScript.AllocSysString();
    IHTMLStyleSheet* pnewStyleSheet;
    if(pDoc->createStyleSheet(bstrContent,1,&pnewStyleSheet) == S_OK)
    {
    if(pnewStyleSheet != NULL)
    {
    CString strP = "p";
    BSTR bstrP = strP.AllocSysString();
    CString strStyle = "margin-top:0;margin-bottom:0";
    BSTR bstrStyle = strStyle.AllocSysString();
    long notuse;
    pnewStyleSheet->addRule(bstrP,bstrStyle,-1,&notuse);
    ::SysFreeString(bstrP);
    ::SysFreeString(bstrStyle);
    pnewStyleSheet->Release();
    }
    }
    ::SysFreeString(bstrContent);
    pDoc->Release();
    }谢谢。后天送分。
    看看谁还有没有其他的方法。