我定义了:
CWebBrowser2 m_internetexplorer;对于打开的网页,我想查找其中特定的文本,
是用m_internetexplorer.GetDocument()吗?
该怎么使用啊?我这样的不行呃...void CMyWebDlg::OnFindtext() 
{
// TODO: Add your command handler code here
if(m_internetexplorer.GetDocument()==(IDispatch *)"控件")
MessageBox("OK");
else
MessageBox("NO");}
但是结果是,明明打开的网页上有"控件"两个字,却仍然提示"NO",
不知道这样做对吗?希望高手们能给点指点啊~~
谢谢!

解决方案 »

  1.   

    先用CWebBrowser2得到IHTMLDocument2指针,然后用get_all得到所有元素的集合,再用item(元素name,...)查找你所要的内容。不知道你所说的“控件”具体是什么类型的元素,下面举例查找input元素:
    <input   type="text"   name="myName"   value="控件"  maxlength="15"> 
    代码如下:  
    CComQIPtr<IHTMLDocument2,&IID_IHTMLDocument2> spHTML=NULL;
    CComQIPtr< IHTMLElementCollection > spElementCollection;
    CComPtr< IDispatch > spDisp;
    CComQIPtr < IHTMLInputTextElement > spInputText;
    //CComQIPtr < IHTMLInputButtonElement > spInputButton;
    //CComQIPtr < IHTMLInputHiddenElement > spInputHidden;
    //......spHTML = m_ctrlWeb.GetDocument();  
    if(spHTML) 
    {
       spHTML->get_all(&spElementCollection); 
       if(spElementCollection)  
       {
         spElementCollection->item(CComVariant(CComBSTR("myName")),CComVariant(),&spDisp);
         spInputText = spDisp;
         if(spInputText)
        {
           CComBSTR val;
           spInputText->get_value(&val);
           CString sVal = OLE2A(val.bstrVal);
           if(sVal=="控件")
               MessageBox("OK");
           else
      MessageBox("NO");
          }
        } 
    }
      

  2.   

    谢谢jovia(),不过我这样之后,程序编译链接有4个错误: #include "webbrowser2.h"
    #include "Atlbase.h"
    #include <mshtml.h>void CRefreshWebDlg::OnFindtext() 
    {
    // TODO: Add your command handler code here CComQIPtr <IHTMLDocument2,&IID_IHTMLDocument2> spHTML=NULL;  //335行error
    CComQIPtr < IHTMLElementCollection > spElementCollection;
    CComPtr< IDispatch > spDisp;
    CComQIPtr < IHTMLInputTextElement > spInputText;
    //CComQIPtr < IHTMLInputButtonElement > spInputButton;
    //CComQIPtr < IHTMLInputHiddenElement > spInputHidden;
    //...... spHTML = m_internetexplorer.GetDocument();  
    if(spHTML) 
    {
       spHTML->get_all(&spElementCollection); 
       if(spElementCollection)  
       {
     spElementCollection->item(CComVariant(CComBSTR("myName")),CComVariant(),&spDisp);
     spInputText = spDisp;
     if(spInputText)
    {
       CComBSTR val;
       spInputText->get_value(&val);
       CString sVal = OLE2A(val.bstrVal);  //355行error
       if(sVal=="控件")
       MessageBox("OK");
       else
    MessageBox("NO");
     }

    }}
    Compiling...
    RefreshWebDlg.cpp
    E:\VC++\FindWeb\FindWebDlg.cpp(335) : error C2440: 'initializing' : cannot convert from 'const int' to 'class ATL::CComQIPtr<struct IHTMLDocument2,&struct _GUID const IID_IHTMLDocument2>'
            No constructor could take the source type, or constructor overload resolution was ambiguousE:\VC++\FindWeb\FindWebDlg.cpp(355) : error C2065: '_lpw' : undeclared identifier
    E:\VC++\FindWeb\FindWebDlg.cpp(355) : error C2039: 'bstrVal' : is not a member of 'CComBSTR'
            c:\program files\microsoft visual studio\vc98\atl\include\atlbase.h(3889) : see declaration of 'CComBSTR'
    E:\VC++\FindWeb\FindWebDlg.cpp(355) : error C2065: '_convert' : undeclared identifier
    Error executing cl.exe.RefreshWeb.exe - 4 error(s), 0 warning(s)这个会是哪里错了呢?
    谢谢了啊!