请问谁能详细说明一下put_innerHTML的用法,我想编写一个程序能够把打开的网页内容动态修改,比如加入一些要显示的文字,还有,可以自动在复选框前的选项上打钩,不知道怎么实现。
我用以下方法好象对输出的网页没有任何改变,谁能解答一下。
CComPtr<IHTMLDocument2> spDoc;
LRESULT lRes;
UINT nMsg = ::RegisterWindowMessage( _T("WM_HTML_GETOBJECT") );
::SendMessageTimeout( hWnd, nMsg, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD*)&lRes );

LPFNOBJECTFROMLRESULT pfObjectFromLresult= (LPFNOBJECTFROMLRESULT)::GetProcAddress( hInst, _T("ObjectFromLresult") ); {
HRESULT hr;
hr = (*pfObjectFromLresult)( lRes, __uuidof(MSHTML::IHTMLDocument2), 0, (void**)&spDoc );
if ( SUCCEEDED(hr) )
{
CComPtr<IDispatch> spDisp;
CComQIPtr<IHTMLWindow2> spWin;
CComQIPtr<IHTMLElementCollection> col; 
CComQIPtr<IHTMLElement> EL;
CComPtr<IDispatch> pdispHeader;  
spDoc->get_Script( &spDisp );
spDoc->get_all(&col);   
long l;
col->get_length(&l);
_variant_t v1,v2;
v1=(long)0;
v2=(long)0;
col->item(v1,v2,&pdispHeader);
EL=pdispHeader;
CString str22("Hockey is Best!");
BSTR bstr3 = str22.AllocSysString();
EL->put_innerHTML(bstr3);

解决方案 »

  1.   

    WM_HTML_GETOBJECT消息是你自定义的?窗口要能处理这个消息才行。有一个WM_GETOBJECT消息,不过这个消息是获取IAccessible接口的。
    即使窗口能处理这个消息,返回的接口也不一定是IHTMLDocument2,可能是IWebBrowser2
      

  2.   

    应该是IHTMLDocument2接口,因为我用spDoc->get_all(&col)是可以得到所有内容的。
      

  3.   

    不是所有元素都能put_innerHTML的
      

  4.   

    type=file类型由于安全原因不能put_value