HTML(4):杂项

Qhtml问题,高手请进,或者搞过html分析的请进 
T我想写个程序,能够获取html叶面里的表单,然后再在程序里面显示出来,但现在的问题是有些表单里的数据(网页里预定义,存在array里面,有jsscript把它放到表单里面去)没法子通过分析单纯的网页得到,所以我想问问该怎么办?并且还想问一下,有什么办法能做到点击html的submit的时候,截取那段post数据??
AIHTMLInputElement::value Property
Sets or retrieves the default or selected value of the control.
Syntax
HRESULT IHTMLInputElement::get_value(BSTR *p);HRESULT IHTMLInputElement::put_value(BSTR v);
to handle posted data,check
BeforeNavigate2 Event

Syntax

void BeforeNavigate2(
    IDispatch *pDisp,
    VARIANT *URL,
    VARIANT *Flags,
    VARIANT *TargetFrameName,
    VARIANT *PostData,//here it is
    VARIANT *Headers,
    VARIANT_BOOL *Cancel
);

DWebBrowserEvents2::BeforeNavigate2 Event

--------------------------------------------------------------------------------

Fires before a navigation occurs in the given object (on either a window or frameset element).

Syntax

void BeforeNavigate2(
    IDispatch *pDisp,
    VARIANT *URL,
    VARIANT *Flags,
    VARIANT *TargetFrameName,
    VARIANT *PostData,
    VARIANT *Headers,
    VARIANT_BOOL *Cancel
);

PostData
[in] Pointer to a VARIANT structure of type VT_BYREF or VT_VARIANT that contains the data to send to the server if the HTTP POST transaction is being used.

IHTMLInputElement::value Property

--------------------------------------------------------------------------------

Sets or retrieves the default or selected value of the control.

Syntax

HRESULT IHTMLInputElement::get_value(BSTR *p);HRESULT IHTMLInputElement::put_value(BSTR v);


set resource handle back to your dll each time u load resources internally,and set it back when u done loading resources
I save the instance handle of DLL at DllMain, and write a class whose constructor call AfxSetResourceHandle(dllHandle) and save the ole resource handle,and destructor set it back.
QDHtmlEdit控件的右键菜单问题?
T
DHTMLEdit有缺省的右键菜单吗?就像htmlview那样的。

还有我测试msdn的例子程序,by vb.
Private Sub CreateContextMenu()
    Dim MenuText(3)
    Dim MenuState(3) As OLE_TRISTATE
    MenuText(0) = "Choice 1 (Unchecked)"
    MenuText(1) = "Choice 2 (Checked)"
    MenuText(2) = ""    ' Line
    MenuText(3) = "Choice 3 (Gray)"
    MenuState(0) = Unchecked
    MenuState(1) = Checked
    MenuState(3) = Gray
    DE1.SetContextMenu MenuText, MenuState
End Sub

是没有问题的。
但是我不知道怎么将这段代码利用到vc里,做了好几回尝试,都不行,我的代码就不放上来贻笑大方了。。。。
A用SafeArray和Variant……
Q哪里有MSHTML的编程资料下载?
T请问:哪里有MSHTML的编程资料(最好包含例程的)下载?

不要告诉我MSDN里。那里的东西简直没法看,跟实际好像完全不一样。

请发邮件到kingchy@china-dalian.net,最近CSDN老是出问题,动不动就访问不了,多谢了!
AIHTMLDocument2::all Property

--------------------------------------------------------------------------------

Retrieves an interface pointer to a zero-based collection of all the elements in an HTML document.

Syntax

HRESULT IHTMLDocument2::get_all(IHTMLElementCollection **p);

C++的属性存取语法一般是加一个get/set前缀
item不是属性是方法,所以没有前缀
Q想将内存的图片数据传递给IHTMLDocument2,而不希望用<img src=...>有什么办法
TMSHTML 中有没有什么接口可以让我直接改写存放在内存中的图片数据的?
AIHTMLDocument2::designMode Property

Sets or retrieves whether the document can be edited.

Syntax

HRESULT IHTMLDocument2::get_designMode(BSTR *p);HRESULT IHTMLDocument2::put_designMode(BSTR v);
设计模式下怎么改文档都可以

1 选择图片,将图像数据复制到剪贴板,然后粘贴(未测试)
或者
2 保存到临时文件,然后修改链接
你可以只在修改文档的前后设置designMode为True。

创建IHtmlDocument?直接CoCreateInstance就可以啊
Qjiangsheng 请进
T
jiangsheng:您好。
     我知道您早编程方面有非常丰富的经验。我说话比较直接,开门见山。
     我最近在写一个关于系统的软件,它需要禁止CTRL+ALT+DEL(CAD)系统键。和一些系统登陆认证的工作。你的帖子我一直很关注。上次发表的关于禁止CAD的那段代码,我想参考借用的,但是不明白编译的时候出现一些头文件的错误。
     不置可否传一个您编译通过的程序给我。
     还有想请教一个关于注册表的问题。在程序中,一个非系统管理员的用户如何写注册表(获得写注册表的特权)。
     顺便请问一下,是否第三方编写的GINA在XP经典开始菜单中,会导致‘注销’项消失,是否牵涉到XP的桌面主题方面的内容。
     如果不用GINA,是不是可以用NET PROVIDER这样级别的DLL,能否指导一下思路。 
A>上次发表的关于禁止CAD的那段代码,我想参考借用的,但是不明白编译的时候出现一些头文件的错误。
http://www.microsoft.com/msdownload/platformsdk/sdkupdate/
>不置可否传一个您编译通过的程序给我。
http://www.angelfire.com/ms3/sheng_jiang/disablectrlaltdelete.zip
>还有想请教一个关于注册表的问题。在程序中,一个非系统管理员的用户如何写注册表(获得写注册表的特权)。
以有权限的用户身份运行程序
>顺便请问一下,是否第三方编写的GINA在XP经典开始菜单中,会导致‘注销’项消失,是否牵涉到XP的桌面主题方面的内容。
The Group Policy Reference provides detailed descriptions of the Group Policies in Windows 2000. These descriptions describe the effect of enabling, disabling, and not configuring each policy, as well as explanations of how related policies interact.
Group Policy Registry Table
Group Policy Registry Table
Group Policy, a Windows 2000 administrative tool, determines how programs, network resources, and the operating system behave for users and computers in an organization. Group Policy uses Group Policy Objects in Active Directory, and affects computers and users by adding, deleting, and changing the values of entries in the Windows 2000 registry.

The following table displays the Group Policy settings in the Administrative Templates folder and the registry entries that they change. The policies are listed in alphabetical order.

For information about the registry entry, click the entry name in the table. For information about the Group Policy settings, click the name of the policy.

 Caution

To change the value of entries in this table, use Group Policy. Do not edit the registry.

Disable Logoff

(User Configuration/Administrative Templates/System/Logon/Logoff)
 NoLogoff

(HKCU/Software/Microsoft/Windows/CurrentVersion/Policies/Explorer)
 
Disable Logoff on the Start Menu

(User Configuration/AdministrativeTemplates/Start Menu & Taskbar)
 StartMenuLogOff

(HKCU/Software/Microsoft/Windows/CurrentVersion/Policies/Explorer)
 

>如果不用GINA,是不是可以用NET PROVIDER这样级别的DLL,能否指导一下思路。
这个不熟,可行的其他方案参见 http://www.csdn.net/develop/Read_Article.asp?Id=15645的概要一节。

上次上传文件的确是空文件,在angelfire上每个文件必须上传两次才能成功:(你现在可以重新下载。
如果计算机上安装了RunAs(Windows2000)/Secondary Logon (WindowsXP)服务,你就可以以不同于当前登录用户的身份启动程序启用程序,除非你的登陆策略设置不是密码验证(比如智能卡验证)
参见MSDN中CreateProcessAsUser的文档

我的源代码在http://www.csdn.net/develop/Read_Article.asp?Id=15645中可以下载,如果你编译不能通过,请去http://www.microsoft.com/msdownload/platformsdk/sdkupdate/升级你的库SDK文件和头文件
至于怎么获取管理员身份的问题,现在我还没有办法。或许你可以尝试一下暴力破解管理员密码。

用一个线程来检视文件的修改时间……WinRAR就这么干,你修改了解开的文档之后会问你是不是也更新压缩包
Q请教jiangsheng(蒋晟.Net)老大一个问题 
T我想在一个table中插入一行,我想插入的这一行同我鼠标所在行的tr,td设置完全一样。
因为:pTableElement->insertRow(num,&TrDisp)只是单纯在其中加入了<tr></tr>
在IHTMLTableRow中是否有直接设置此tr的所有td的方法?
ACreating Nodes
Nodes are created using the createElement and createTextNode methods. Both methods are exposed only to the document object, and can be used in HTML documents, DHTML behaviors, and HTAs. In the DHTML Object Model, elements are added to the document hierarchy by modifying the innerHTML and outerHTML property values, or by using methods explicit to particular elements, such as the insertRow and insertCell methods for the table element. With the createElement method, only the name of the element is needed.

Use the following syntax to create a new element.

// Create an element
var oElement = document.createElement(sElementName);
The createElement method is available in Internet Explorer 4.0, but only the area, img, and option elements can be created. As of Internet Explorer 5, all elements can be created stand-alone. In addition, read-only properties, such as id, are read-write for stand-alone elements before they are inserted into the document hierarchy. Some elements might require additional steps or rely on the existence of other elements. For example, the TYPE attribute of the input element defaults to text. So, to create a button control, the type property needs to be set to button, and the value property should be set to provide a label.

The following sample code highlights how a fieldSet, legend, and INPUT type=button control are created in script to build a short form. Notice that one function is designed to create and append the elements, and a reference to the new element is returned so additional elements can be appended as children.

Hide Example

function fnCreate(sElement,sData,sType,oNode){
   var oNewElement=document.createElement(sElement);
   if(sType){
      oNewElement.type=sType;
      oNewElement.value=sData;
   }
   if(sData){
      if(sElement.toLowerCase()!="input"){
         var oNewText=document.createTextNode(sData);
         oNewElement.appendChild(oNewText);
      }
   }
   if(oNode){
      oNode.appendChild(oNewElement);
   }
   else{
      oNewForm.appendChild(oNewElement);
   }
   return oNewElement;
}

var oNode=fnCreate("FIELDSET");
fnCreate("LEGEND","My Form","",oNode);
fnCreate("INPUT","Some Text","text",oNode);
fnCreate("INPUT","A button","button",oNode);
Show Me
When creating and threading together nodes, it is important to use well-formed HTML to avoid creating an invalid tree. By creating and adding an invalid tree into the document hierarchy, unpredictable behavior can ensue. For the most part, Web authors need not be concerned. However, there are some elements, such as table, that warrant special discussion.

A well-formed HTML table consists of at least two nodes: table and tBody. In the DHTML Object Model, a table, with accompanying rows and cells, can be created using the innerHTML property, the insertRow and insertCell methods, and the rows and cells collections. While the tBody element is not explicitly added, it is created as a part of the table object model. For example, the following code generates a two-cell table using the DHTML Object Model.

var sTable="<TABLE ID='oTable1'></TABLE>"
document.body.innerHTML+=sTable;
oTable1.insertRow(oTable1.rows.length);
oTable1.insertRow(oTable1.rows.length);
oTable1.rows(0).insertCell(oTable1.rows(0).cells.length);
oTable1.rows(0).insertCell(oTable1.rows(0).cells.length);
oTable1.rows(0).cells(0).innerHTML="Cell 1";
oTable1.rows(0).cells(1).innerHTML="Cell 2";
The following HTML is the result of the previous code. Notice that the tBody element exists even though it was not added in script.

<TABLE ID="oTable">
<TBODY>
<TR><TD>Cell 1</TD><TD>Cell 2</TD></TR>
</TBODY>
</TABLE>
To create a well-formed table in the W3C DOM, the tBody element must be explicitly created and added to the tree. By not including the tBody element, the nodes comprising the entire table form an invalid tree and result in unpredictable behavior. The following script outlines the creation of a table using the W3C DOM, including the tBody element.

var oTable=document.createElement("TABLE");
var oTBody=document.createElement("TBODY");
var oRow=document.createElement("TR");
var oCell=document.createElement("TD");
var oCell2=oCell.cloneNode();
oRow.appendChild(oCell);
oRow.appendChild(oCell2);
oTable.appendChild(oTBody);
oTBody.appendChild(oRow);
document.body.appendChild(oTable);
oCell.innerHTML="Cell 1";
oCell2.innerHTML="Cell 2";

是IHTMLXXXX接口的成员函数,VC.Net里面没有这样的类。
Q关于Html的显示问题 
T问题1:
我在Dialog Based Project中使用WebControl控件来显示HTML,
那么是不是只能够显示file or url?
如果我想显示内存中某变量存储的HTML怎么实现呢?

问题2:
使用WebControl控件来显示HTML,我如果先把内存中的HTML写到一个
文件里面去,然后用WebControl控件来显示。最后我想删除这个文件,
那么应该在什么时候呢?
我碰到了这样的问题,就是在调用了Navigate()以后,然后接着删除,
那么在对话框中就会显示没有此文件,我想是不是Navigate()还没有
显示完,我就把文件给删除了造成的。
所以第二个问题就是如何判断已经显示完毕html文件,可以安全删除。
A用内存流文件就可,写到COleStreamFile然后用IHtmlDocument::Load
Q如何在网页浏览器中实现保存为html文件? 
T请各位高手指点,谢谢了
AKnowledge Base 

HOWTO: Programmatically Save an HTML Page to DiskPSS ID Number: Q292485

Article Last Modified on 09-13-2001


--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Internet Explorer (Programming) 4.0, 4.01, 4.01 SP1, 4.01 SP2, 5, 5.01, 5.01 SP1, 5.5, 5.5 Service Pack 1
Microsoft Visual Basic Enterprise Edition for Windows 6.0
Microsoft Visual C++, 32-bit Enterprise Edition 6.0

--------------------------------------------------------------------------------
Visual C++ Solution
Accomplishing this task from a Visual C++ host is very straightforward. You can use an IWebBrowser2 interface to call the QueryInterface method for the IHTMLDocument2 interface. After you obtain a pointer to the document, then call QueryInterface for the IPersistFile interface. After you obtain this interface pointer, you can call the save method to save the file to disk.
    HRESULT          hr    = E_FAIL;
    IDispatch*       pDisp = NULL;
    IHTMLDocument2*  pDoc  = NULL;
 
    pDisp                  = m_webOC.GetDocument();

   if(SUCCEEDED(hr = pDisp->QueryInterface(IID_IHTMLDocument2,(void**)&pDoc)))
   {
       IPersistFile* pFile = NULL;
       if(SUCCEEDED(pDoc->QueryInterface(IID_IPersistFile,(void**)&pFile)))
       {
 LPCOLESTR file = L"c://test1.htm";
 pFile->Save(file,TRUE);
       }
   }
Q请教,用IHTMLDocument2取当前活动页面的内容? 
T小弟写一段显示当前活动页面的显示内容的代码,用的是IHTMLDocument2,当前的整个页面的指针可以获得,但是不知道应当如何得到活动页面(鼠标点击的页面)的指针,比如象csdn的框架结构,鼠标点击框架右边的页面时,怎么得到其指针?当然不单纯指 框架结构,是针对所有鼠标点击的活动页面而言,谢谢!
Aexpert.csdn.net/Expert/topic/1440/1440385.xml?temp=.3461878

MSDN KB
Q196340 HOWTO: Get the WebBrowser Object Model of an HTML Frame
Q249232 HOWTO: Get IHTMLDocument2 from a HWND
Q176792 HOWTO: Connecting to a Running Instance of Internet Explorer

http://www.vcroad.net/shownews.asp?newsid=965
Q我怎样用vc,模拟鼠标按下网页中“获得金钱”的按钮。(在Table中的图象按钮) 
T<A href="javascript:void%20open('/vbb/onlinecount.php?action=save', '', 'width=180,height=180')">
<IMG alt=获得金钱 src="游侠网——NetShow论坛_files/top_getmoney.gif"
                        border=0> </A>
AMSDN Home >  MSDN Library >  Programming and Reusing the Browser >  Overviews/Tutorials 
Handling HTML Element Events

http://expert.csdn.net/Expert/topic/934/934618.xml?temp=.4553034
IHTMLElement::click Method
Simulates a click by causing the onclick event to fire. 
Q500分求助:我用DHTML控件打开了一个页面,并且可以对输入框的<INPUT>属性、选择框的<SELECT>属性进行修改,但却不能把修改后的数据保存 
T我用DHTML控件打开了一个页面,并且可以对输入框的<INPUT>属性、选择框的<SELECT>属性进行修改,修改的方法是:生成一个鼠标点击事件,利用控件的以下代码实现得到<INPUT>的属性。
CDHTMLEdit pHTML;
CHTMLDocument2  pDocument;
CHTMLElement htmlElement;

VARIANT varNameTemp;

int x,y;
y = HIWORD(lParam);
x = LOWORD(lParam);


pDocument = (CHTMLDocument2)pHTML.GetDom();
htmlElement = pDocument.elementFromPoint(x, y);
tagHtmlElement=htmlElement.GetTagName();

if( tagHtmlElement == "INPUT" )
{
    varNameTemp = htmlElement.getAttribute("name",0);//得到<INPUT>中的name属性
    dlgInput.m_inputName = varNameTemp.bstrVal;
}

然后我想用setAttribute()来把在对话框中修改好的属性寸入HTML文件中就不行了。

我问了一下,有人说需要把网页设置成网页编辑模式,但我不知道用这个控件怎么改,请各位大侠帮助我!很急!只要有帮助的一定给分,另外开贴给分!
A〉但我用的是DHTML控件,没办法得到Document的指针
这个就是啊,pDocument = (CHTMLDocument2)pHTML.GetDom();
后面hr = piDisp->QueryInterface(IID_IHTMLDocument2, (void**)&piDoc);就可以了
Q我在一个函数里调出了一个页面,同时在这个函数里对页面进行了操作,如何使页面完全显示出来后再做这些操作?
T
说得清楚点:
我在这个函数里调用了nagate2函数来显示页面,如果我在这个函数后加一个MESSAGEBOX,等一会再继续运行下面的程序没问题。但如果没有MESSAGEBOX对话框,直接就运行下面的程序就不对。
CHTMLView里有什么函数可以判断页面是否完全显示出来了的函数吗?或者有什么解决的方法吗?
A
捕获DocumentComplete事件
不能用CHtmlView的那个虚函数,要自己处理这个事件。参见http://www.csdn.net/develop/read_article.asp?id=18465
QIE编程的问题-如何正确的得到IHTMLDocument2接口
T我的程序sink了DWebBrowserEvents2。
然后在Invoke函数的
DISPID_DOCUMENTCOMPLETE中sink了HTMLDocumentEvents2.
我想在DISPID_HTMLDOCUMENTEVENTS2_ONCLICK
中得到IHTMLDocument2接口。
于是
CComPtr<IDispatch> spDisp;
spDisp = pDispParams->rgvarg[0].pdispVal;
结果程序出错。
调试发现,pDispParams->rgvarg竟然指向空(NULL)。
请问这是什么原因呢?
我该如何正确的得到IHTMLDocument2接口呢?
A
void DocumentComplete(
Idispatch *pDisp,
VARIANT *URL
);
Parameters
pDisp
[in] Pointer to the IDispatch interface of the window or frame in which the document has loaded. This IDispatch interface can be queried for the IWebBrowser2 interface.
URL
[in] Pointer to a VARIANT structure of type VT_BSTR that specifies the URL, Universal Naming Convention (UNC) file name, or pointer to an item identifier list (PIDL) of the loaded document.
从IWebBrowser2 就可以获得文档了
DISPID_HTMLDOCUMENTEVENTS2_ONCLICK事件的event.fromelement可以获得元素指针

event.fromelement.document
event.srcelement.document
这两个应该有一个可以

Q为什么get_body(&m_Body)所得m_Body会为空?
T//m_Browser 为 WebBrowser 控件的一个对象
m_Browser.Navigate("http://www.sina.com.cn",.....)
...
...
//在OnDownLoadComplete里面
//得到一个Ihtmldocument2 接口指针 m_pHtmlDocument
CComPtr<IHTMLElement> m_HtmlBody;
m_pHtmlDocument->get_body(&m_HtmlBody);

(1)为什么我调试的时候m_HtmlBody都是一个NULL呢?
(2)当获得一个body后,要怎么释放?
A
1 只有在第一次导航完成之后,DOM才有效,而DownLoadComplete在一次导航中可能触发多次
2 CComPtr的析构函数自己会释放
>DownloadComplete,DownloadBegin,DocumentComplete是什么时候才会产生?

这个么,去看看DWebBrowserEvents的说明
Q请问高手:如何获取指定网页中的CSS和JS的文件地址呢?
T我现在能搞定网页中所有链接和所有图片,但是提取CSS文件时出错,其代码如下:
 TCHAR HostName[200*MAX_PATH];
 CComPtr<IDispatch> spDispatch;
 CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> pDoc2;
 CComPtr<IHTMLElementCollection> pElementCol;
 CComPtr<IHTMLLinkElement> pLink1;
  //IHTMLElement
 // TODO: Add your control notification handler code here
 int n = m_LinksList.GetItemCount();//GetCount();

 for (int i = 0; i < n; i ++){
  IWebBrowser2 *pBrowser = (IWebBrowser2 *)m_LinksList.GetItemData(i);
  if (pBrowser){
   pBrowser->Release();
  }
 }//设置最后一个IE窗口为数据窗口

 m_LinksList.DeleteAllItems();
 m_LinksNum = 0;
 Log("**************************************************************");
 Log("/r/n");

 if (m_spSHWinds){
  int n = m_spSHWinds->GetCount();
  for (int i = 0; i < n; i++){
   _variant_t v = (long)i;
   IDispatchPtr spDisp = m_spSHWinds->Item(v);
   SHDocVw::IWebBrowser2Ptr spBrowser(spDisp);   //生成一个IE窗口的智能指针
   if (spBrowser){

    if (SUCCEEDED(spBrowser->get_Document( &spDispatch)))//打开一个IE窗口文档
     pDoc2 = spDispatch;
    if(pDoc2!=NULL)
    {

     if (SUCCEEDED(pDoc2->get_links(&pElementCol)))//获得连接
     {
      // AfxMessageBox("IHTMLElementCollection");
      long p=0;
      if(SUCCEEDED(pElementCol->get_length(&p)))
       if(p!=0)
       {  
        m_LinksNum = m_LinksNum+p;//连接数
        UpdateData(FALSE);//更新EDITBOX

        for(long i=0;i<=(p-1);i++)
        {

         CComBSTR String;
         _variant_t index = i;
         if(SUCCEEDED(pElementCol->item( index, index, &spDispatch)))
         if(SUCCEEDED(spDispatch->QueryInterface( IID_IHTMLLinkElement,(void **) &pLink1)))//获得单个连接
         pLink1->get_href(&String);//得到是一个空串********
         ZeroMemory(HostName,200*MAX_PATH);
         lstrcpy(HostName,_bstr_t(String));
         //pLoct->get_target
         //添加到列表
         m_LinksList.InsertItem(i,HostName);
         m_LinksList.SetCheck(i,TRUE);
          pLink1->get_rel(&String);//提示出错**********                                    ZeroMemory(HostName,200*MAX_PATH);
         lstrcpy(HostName,_bstr_t(String));
         if(lstrlen(HostName))
         {
          m_LinksList.SetItemText(i,1,HostName);
          Log(HostName );
          Log("/r/n");
         }}}}
}}}}
AHRESULT IHTMLDocument2::get_scripts(IHTMLElementCollection **p);+IHTMLScriptElement::src
HRESULT IHTMLDocument2::get_styleSheets(IHTMLStyleSheetsCollection **p);+IHTMLStyleSheet::href

1 IHTMLStyleSheet只是接口而已,没有成员变量,你怎么试的?
2 http://www.csdn.net/develop/author/netauthor/jiangsheng/
如何: 通过HTML文档对象模型访问文档中的ActiveX控件的属性
Q关于IUnknown::queryInterface去访问IHTMLFrameBase的问题
Tjiangsheng:你好!
下面有一点小问题,好像不能通过IUnknown::queryInterface获得IHTMLFrameBase的接口!(不知道是不是这去访问IUnknown的接口!)
CComPtr<IHTMLFramesCollection2> spFrames=NULL;
hr=pDoc2->get_frames (&spFrames);
if(spFrames!=NULL&& SUCCEEDED(hr))
{
  long nFrameCount;
  hr=spFrames->get_length (&nFrameCount);
  for(long j=0;j<nFrameCount;j++)
   {
     CComBSTR String;
     CComVariant varFrame(j);
     VARIANT frameOut;
     spFrames->item(&varFrame, &frameOut);
     IUnknown* pUnkDisp = NULL;
     hr = frameOut.pdispVal->QueryInterface(IID_IUnknown,(void**)&pUnkDisp );
    if ( SUCCEEDED(hr) )
     {
/*
       if SUCCEEDED(pUnkDisp->QueryInterface(IID_IHTMLFrameBase,(void **) &pFrameBase1))   //此句执行不成功
/*
 {           pFrameBase1->get_src(&String);
 }
      }
    }
}
--
原贴内容:
IUnknown::queryInterface
A是啊,获得了IDispatch接口指针之后就可以调用了,IDispatch继承自
IUnknown的。
P.S.IHTMLFrameBase不是每个版本的IEFrame都支持的,建议用新的接口的话,程序启动时检查IE版本

MFC7 CDHtmlDialog::DDX_DHtml_IFrame_Src

QI either IHTMLFrameElement or IHTMLIFrameElement.
or QI IHtmlWindow4 and use IHTMLWindow4::get_frameElement
Q一个困扰了我很久的问题,请各位大哥帮忙看看,提点建议,问题是关于HTML页面的!
T
我用HTMLVIEW的Navigate2方法打开了一个页面,然后用HTMLVIEW的GetHtmlDocument方法或得页面的信息放入IHTMLDocument2接口中。
这个页面是这样的:
<HTML>
<BODY>
<TABLE class=unnamed1 borderColor=#42b6ce cellSpacing=0 cellPadding=0 width=564 align=center border=1>
  <TBODY>
      ……
      ……
  </TBODY>
</TABLE>

<XML id=customer_xmlid>
      ……
      ……
</XML>

<SCRIPT title="">
     ……
     ……
</SCRIPT>

</BODY>
</HTML>

现在我已经把所有页面内容都读到IHTMLDocument2接口中了,然后我要保存到另一个文件中,保存的内容只是:
<TABLE class=unnamed1 borderColor=#42b6ce cellSpacing=0 cellPadding=0 width=564 align=center border=1>
  <TBODY>
      ……
      ……
  </TBODY>
</TABLE>
而那些:
<XML id=customer_xmlid>
      ……
      ……
</XML>

<SCRIPT title="">
     ……
     ……
</SCRIPT>
并不想保存进新的文件中。

我应该如何做?

注:我保存的时候是用了:IPersistFile的Save方法。而IPersistFile的接口是IHTMLDocument2通过QueryInterface方法连接过去的。

主要是我不知道再IHTMLDocument2中我如何删除那些我不需要的东西,或者只提取我需要的东西,请各位高手给点意见。

AIHTMLDOMNode::removeNode

直接用IMarkupxxxx执行select,editcopy,editpaste

http://search.csdn.net/expert/topic/50/5009/2002/1/16/481701.htm
http://search.csdn.net/expert/topic/50/5009/2001/11/1/351580.htm
Q如何在进入链接前获得链接地址?
T   我编了一个浏览器,在点击一个链接时会弹出一个IE窗口,我想在弹出前获得这个链接的地址?请指教!
A1 处理DWebBrowserEvents2::NewWindow2,标记对象需要检查
2 处理DWebBrowserEvents2::BeforeNavigate2获得URL,检查

When an application calls the Navigate or Navigate2 method with the navOpenInNewWindow flag, the NewWindow2 event occurs before the new browser window is created. This event allows the application to create the new browser window or have a new instance of the Internet Explorer application created. Once the new window is created, an accompanying BeforeNavigate2 event occurs.

reuse the old window
void CDWebBrowserEvents::OnNewWindow(BSTR URL, long Flags, BSTR TargetFrameName,
     VARIANT* PostData, BSTR Headers, BOOL FAR* Processed)
{
 if (m_Browser) {
     COleVariant varEmpty;
     *Processed = TRUE;
     m_Browser->Navigate((LPCSTR)URL, &varEmpty, &varEmpty, &varEmpty, &varEmpty);
 }
}

   
If you use NewWindow2, the following code fails in all versions of the Internet Explorer:
void CIEDlg::OnNewWindow2(LPDISPATCH FAR* ppDisp, BOOL FAR* Cancel)
{

 IUnknown* pUnk = m_Browser.GetControlUnknown();
 if (pUnk)
 {
  IDispatch* pDisp = NULL;
  HRESULT hr = pUnk->QueryInterface(IID_IDispatch, (void**)&pDisp);

  if (SUCCEEDED(hr) && pDisp)
   *ppDisp = pDisp;
 }
}

use new window
void CMyHtmlView::OnNewWindow2(LPDISPATCH* ppDisp, BOOL* Cancel)
{
   // Get a pointer to the application object.
   CWinApp* pApp = AfxGetApp();

   // Get the correct document template.
   POSITION pos = pApp->GetFirstDocTemplatePosition();
   CDocTemplate* pDocTemplate = pApp->GetNextDocTemplate( pos );

   // Create a new frame.
   CFrameWnd* pFrame = pDocTemplate->CreateNewFrame(
                                          GetDocument(),
                                          (CFrameWnd*)AfxGetMainWnd() );

   // Activate the frame.
   pDocTemplate->InitialUpdateFrame( pFrame, NULL );
   CNewWindow2View* pView = (CNewWindow2View*)pFrame->GetActiveView();

   // Pass pointer of WebBrowser object.
   pView->SetRegisterAsBrowser( TRUE );
   *ppDisp = pView->GetApplication();  
}
void CYourDlg::OnNewWindow2(LPDISPATCH FAR* ppDisp, BOOL FAR* Cancel)
   {
      m_dlgNewWB = new CYourDlg;
      m_dlgNewWB->Create(IDD_WBDLG_DIALOG);

      m_dlgNewWB->m_webBrowser.SetRegisterAsBrowser(TRUE);

      *ppDisp = m_dlgNewWB->m_webBrowser.GetApplication();
   }

showModalDialog and showModelessDialog Do Not Fire NewWindow2

去看reuse the old window那一段
Q如何在VC中使用IHTMLDocument2::createElement()函数创建一个 IHTMLScriptElement
T
IHTMLDocument2::createElement()函数可以创建一个新的IHTMLElement,但是我在创建一个IHTMLScriptElement的时候却遇到了问题。虽然使用“script”关键字创建了一个新的element,但是它并不是一个IHTMLScriptElement,这是为什么?代码如下:
 IHTMLElementCollectionPtr pColl;
 if( m_pDoc2 != 0 && S_OK == m_pDoc2->get_all( &pColl ) )
 {
  long l;
  if( S_OK == pColl->get_length( &l ) )
  {
   for( long i=0; i<l; i++ )
   {
    VARIANT vt;
    vt.vt = VT_I4;
    vt.lVal = i;
    IDispatchPtr pDis;      
    if( S_OK == pColl->item( vt, vt, &pDis ) )
    {
     CComBSTR str;    
     IHTMLDOMNodePtr pNode = pDis;
     if( pNode )
     {
      if( S_OK == pNode->get_nodeName( &str ) )
      {      
       IHTMLElementPtr pEle;
       //获取body element
       if( str == CComBSTR("BODY") || str == CComBSTR("body") )
       {
        //创建一个script关键字的element
        if( S_OK == m_pDoc2->createElement( L"script", &pEle ) )
        {
         IHTMLDOMNodePtr p = pEle;
         if( p )
         {
          IHTMLDOMNodePtr pReturn;
          //将新的element插入到body最后
          if( S_OK == pNode->appendChild( p, &pReturn ) )
          {
           break;
          }
         }
        }      
       }
      }
     }
    }
   }
  }
 }
A用PersistStream在文件末尾添加脚本看看
http://www.csdn.net/develop/read_article.asp?id=18465

try document.script.applyElement
Q怎样抓取网页文件中的文字而去掉其html语法符号
T 利用文件操作相当于操作html文件的源文件,不知道有没有好的办法只取其汉字即内容去掉其他无用的如,<br><html>这种脚本符号? Thx
A
使用MSHTML:
首先得到IHTMLDocument2接口,然后访问IHTMLDocument2的all集合或者分类集合,得到IHTMLElement2接口,然后调用GetText方法。
http://msdn.microsoft.com/downloads/samples/internet/browser/WalkAll/default.asp?frame=true
Q关于自动填写网页中的编辑框 
T
看到网上一些用IHTMLDocument2接口自动填写网页的代码,其是否只能对
input type="text"的编辑框有效?
为什么对下面这样的编辑框无效?
<TR id=tr6>
  <TD id=TD6 >
    Input name:
    <INPUT id=INPUT6 name=name1 size=20 >
  </TD>
</TR>

A你给出的spDispatch是form么?

get_forms是获得所有的forms,get_all是获得所有的element
pElementCol是什么?

当然会没有form
pElementCol是智能指针,初值为空。你怎么设置的它的值?

需要获得frame中的文档的IHtmlDocument2接口
参见http://www.csdn.net/develop/read_article.asp?id=21702中源代码的网页分析代码

叫你去看的是代码……
void CDlgDocOutline::OnButtonEditFrameSource()
{
 HTREEITEM hItem=m_wndTree.GetSelectedItem();
 if(hItem==NULL)return;
 TVITEM tvi;
 ZeroMemory(&tvi,sizeof(tvi));
 tvi.mask=TVIF_HANDLE|TVIF_PARAM;
 tvi.hItem=hItem;
 m_wndTree.GetItem(&tvi);
 LPDISPATCH spNode=(LPDISPATCH)tvi.lParam;
 CComQIPtr<IHTMLDOMNode> pNode(spNode);
 CComQIPtr<IHTMLElement> pElement(pNode);
 CComQIPtr<IWebBrowser2> pWebBrowser(pElement);
 if(pWebBrowser){
  CComPtr<IDispatch> spDocument;
  pWebBrowser->get_Document(&spDocument);
  CComQIPtr<IHTMLDocument2> pDocument(spDocument);
  if(pDocument){
   CDlgDocOutline DlgDocOutline;
   DlgDocOutline.m_pHtmlDoc=pDocument;
   DlgDocOutline.DoModal();
   BuildDocOutline();
  }
 }
 
}
LR

访问方式换换
用frame元素的IWebBrowser2接口
Q怎样把html文件转换成txt文件?
T程序要求,能单个或批量处理一个目录下的html文件,只出现文本部分(就向ie另存的一样)
Asee WalkAll Sample in Web Workshop
使用IHtmlDocument接口获得BODY元素的innerText就可以了
http://www.csdn.net/expert/topic/299/299106.shtm
document属性返回一个IHtmlDocument2接口。

自己写代码存到文件
使用
outerHTML Property (IHTMLElement)

--------------------------------------------------------------------------------

Sets or retrieves the object and its content in HTML.

Syntax

HRESULT IHTMLElement::get_outerHTML(BSTR *p);HRESULT IHTMLElement::put_outerHTML(BSTR v);
Parameters

p
Pointer to a BSTR that receives content and HTML tags.
v
BSTR that specifies content and HTML tags.
Return Value

Returns S_OK if successful, or an error value otherwise.
Remarks

The IHTMLElement::outerHTML property is read-only on the HTML, HEAD, body, FRAMESET, TBODY, TD, TFOOT, TH, THEAD, and TR objects.

The property can be any valid string containing a combination of text and tags.

When the property is set, the given string completely replaces the object, including its start and end tags. If the string contains HTML tags, the string is parsed and formatted as it is placed into the document.

This property is accessible at run time as of Microsoft&reg; Internet Explorer 5. Removing elements at run time, before the closing tag has been parsed, can prevent other areas of the document from rendering.

You can set this property only after the onload event fires on the window. When dynamically creating a tag using TextRange, IHTMLElement::innerHTML, or IHTMLElement::outerHTML, use Microsoft&reg; JScript&reg; (compatible with ECMA 262 language specification) to create new events to handle the newly formed tags. Microsoft&reg; Visual Basic&reg; Scripting Edition (VBScript) is not supported.

You can change the value of the title element using the document.TITLE property.

To change the contents of the TABLE, TFOOT, THEAD, and TR elements, use the table object model. For example, use the IHTMLTableRow::rowIndex property or the rows collection to retrieve a reference to a specific table row. To retrieve a reference to a specific cell, use the IHTMLTableCell::cellIndex property or the cells collection. You can add or delete rows using the IHTMLTableRow::insertCell and IHTMLTableRow::deleteCell methods. To change the content of a particular cell, use the IHTMLElement::innerHTML property.

Property Information

WebBrowser1_DocumentComplete之后才能用webbrowser1.document.body.innertext获得文档
QMsHtml的问题
T
网页里<table>怎么找出来?

我查了很9的MSDN
也不知道table对应着哪个接口
也不知道用什么方法能获得这个接口
AIHTMLTable

必须在网页载入成功后才修改网页元素。参见我的文档
在对话框中使用网页输入数据 (jiangsheng原创) 
http://www.csdn.net/develop/read_article.asp?id=9408

对于IHTMLElement QI一下看看是不是支持IHTMLTable


BOOL    CAboutBox::ReplaceHtmlByID(LPCTSTR  lpszTagID,LPCTSTR lpszHtml,BOOL bIsInnerHtml)
{
    CComDispatchDriver  pHTMLDispatch(m_wndBrowser.GetDocument());
    if(pHTMLDispatch.p){
        HRESULT hr;
        CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> pHTMLDocument(pHTMLDispatch);
        if(pHTMLDocument.p){
            CComPtr<IHTMLElementCollection> pHTMLElementCollection;
            hr=pHTMLDocument->get_all(&pHTMLElementCollection);
            if(hr==S_OK &&  pHTMLElementCollection.p!=NULL){
                LONG    celem;
                hr=pHTMLElementCollection->get_length(&celem);
                if(hr==S_OK){
                    for(int i=0;i<celem;i++){
                        COleVariant varIndex,var2;//var2 is not used because accessing index,not name
                        varIndex.vt=VT_UINT;
                        varIndex.lVal=i;
                        CComDispatchDriver  pDisp;
                        hr=pHTMLElementCollection->item(varIndex,var2,&pDisp);
                        if(hr==S_OK){
                            CComQIPtr<IHTMLElement, &IID_IHTMLElement> pHTMLElement(pDisp);
                            if(pHTMLElement){
                                //find html element
                                BSTR    bstrTagID;
                                if(pHTMLElement->get_id(&bstrTagID)==S_OK){
                                    if(bstrTagID!=NULL){
                                        _bstr_t bstrHTML(lpszHtml);
                                        _bstr_t bstrTagIDToCompare(lpszTagID);
                                        _bstr_t _bstrTagID(bstrTagID,FALSE);
                                        if(_bstrTagID==bstrTagIDToCompare){
                                            if(bIsInnerHtml)
                                                pHTMLElement->put_innerHTML(bstrHTML);
                                            else
                                                pHTMLElement->put_outerHTML(bstrHTML);
            #ifdef  _DEBUG
                                            BSTR    bstrTag;
                                            hr=pHTMLElement->get_outerHTML(&bstrTag);
                                            CString strTag=bstrTag;
                                            ::afxDump<<strTag;
            #endif
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return TRUE;
}

pElem->QueryInterface(IID_IHTMLElement3,(LPVOID*)&pTable);
pTable->get_outerHTML


#include <afxpriv.h>  
#include <mshtml.h>
#include <atlbase.h>
extern CComModule _Module;
#include <atlcom.h>
#include <COMDEF.h>

改过后的CHtmlParsingDlg::GetTables
void CHtmlParsingDlg::GetTables(CString cs)
{
    //convert CString to widechar
    int nFromLen=cs.GetLength()+1;
    OLECHAR *szHTML;
    szHTML= new OLECHAR[ nFromLen];
    MultiByteToWideChar( CP_ACP, 0, cs, -1, szHTML, nFromLen);
    try{
        CComPtr<IHTMLDocument2> pDoc2; // document to create IMarkupServices
        COM_CHECK(CoCreateInstance(CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER,IID_IHTMLDocument2,(void**)&pDoc2));
        CComQIPtr<IPersistStreamInit,&IID_IPersistStreamInit>   pPersist(pDoc2);
        if(pPersist){
            COM_CHECK(pPersist->InitNew());
            CComQIPtr<IMarkupServices,&IID_IMarkupServices> pMS(pDoc2);
            if(pMS){
                CComPtr<IMarkupContainer>   pMC ;
                CComPtr<IMarkupPointer> pMkStart ;
                CComPtr<IMarkupPointer> pMkFinish ;
                CComPtr<IHTMLDocument2> pDoc2;
                COM_CHECK(pMS->CreateMarkupPointer(&pMkStart));
                COM_CHECK(pMS->CreateMarkupPointer(&pMkFinish));
                COM_CHECK(pMS->ParseString(szHTML, 0, &pMC, pMkStart, pMkFinish));
                CComQIPtr<IHTMLDocument3,&IID_IHTMLDocument3>   pDoc3(pMC);
                if(pDoc3){
                    CComBSTR    tagName("TABLE");
                    if(pDoc3){
                        CComPtr<IHTMLElementCollection> pTableCol;
                        long p;
                        CComBSTR bstrOuterHTML;
                        CComVariant varIndex,varDummy;
                        COM_CHECK(pDoc3->getElementsByTagName(tagName,&pTableCol));
                        COM_CHECK(pTableCol->get_length(&p));
                        IDispatch * pDummy;
                        for(int i=0;i<p;i++){//遍历所有元素
                            varIndex= i;
                            COM_CHECK(pTableCol->item(varIndex,varDummy,&pDummy));//获取元素对象指针
                            CComQIPtr<IHTMLElement,&IID_IHTMLElement>   pTableElement(pDummy);
                            if(pTableElement){
        //do something with this element
                                COM_CHECK(pTableElement->get_outerHTML(&bstrOuterHTML));
                                TRACE(CString(bstrOuterHTML)+"/n");
                            }
                        }
                    }
                }
            }
        }
    }
    catch(HRESULT hr){
        TRACE(_T("COM ERROR:%d"),hr);
    }
    delete szHTML;
}

#define COM_CHECK(hr) {if(FAILED(hr))throw hr;}


HRESULT item(
    VARIANT name,
    VARIANT index,
    IDispatch **pdisp
);
Parameters

name
[in] VARIANT of type VT_I4 or VT_BSTR that specifies the object or collection to retrieve. If this parameter is an integer, it is the zero-based index of the object. If this parameter is a string, all objects with matching name or id properties are retrieved, and a collection is returned if more than one match is made.
index
[in] VARIANT of type VT_I4 that specifies the zero-based index of the object to retrieve when a collection is returned.
pdisp
[out, retval] Address of a pointer that receives an IDispatch  interface for the object or collection if successful, or NULL otherwise.
如果通过索引来访问,则第二个参数被忽略
如果通过名字来访问,则第二个参数为同名元素集中的序号。

可以去看看http://www.csdn.net/expert/topic/360/360785.shtm里面怎么分析表格


到现在还没会??晕~
Q高手过来,解决网页接口问题
T谁知道内存网页中的图像怎么获得?有谁有这方面的资料或信息么,帮帮俺,谢谢!
A选定之后复制到剪贴板看看
复制到剪贴板之后想怎么干就怎么干
要不你根据IMG的src去把那个图片down回来算了

IWebBrowser2::ExecWB Method

--------------------------------------------------------------------------------

Implements a wrapper that allows you to execute a command on an OLE object using the IOleCommandTarget::Exec method.

Syntax

HRESULT ExecWB(
    OLECMDID cmdID,
    OLECMDEXECOPT cmdexecopt,
    VARIANT *pvaIn,
    VARIANT *pvaOut
);



IDM_COPY Command ID
Copies the current selection to the clipboard.
C++ Information
Command group CGID_MSHTML (defined in mshtmhst.h) 
Symbolic constant IDM_COPY 
User interface None. Set nCmdExecOpt to OLECMDEXECOPT_DONTPROMPTUSER.
IOleCommandTarget::Exec parameters pvaIn Set to NULL.
pvaOut Set to NULL.
 
Header file mshtmcid.h 
Applies to IHTMLDocument2::execCommand, IHTMLDocument2::queryCommandEnabled, IHTMLDocument2::queryCommandIndeterm, IHTMLDocument2::queryCommandState, IHTMLDocument2::queryCommandSupported, IHTMLDocument2::queryCommandValue, IOleCommandTarget::Exec, IOleCommandTarget::QueryStatus. 

Minimum Availability

Internet Explorer 4.0 and later.
你先用程序选择那个element不就完了


微软的文档,还没看懂:(
The IHTMLEditServices Interface
The IHTMLEditServices interface provides general editing services, including registering and unregistering a designer. The following example shows how to obtain a pointer to the IHTMLEditServices interface and register a designer, assuming m_pIDoc is a pointer to one of the IHTMLDocument* interfaces on the document object.

IServiceProvider* pIServiceProvider;
IEditServices* pIEditServices;
IHTMLEditDesigner* pIHTMLEditDesigner;
m_pIDoc->QueryInterface( IID_IServiceProvider, & pIServiceProvider );
pIServiceProvider->QueryService( SID_SHTMLEditServices,
    IID_IHTMLEditServices, & pIEditServices );
pIEditServices ->AddDesigner( pIHTMLEditDesigner );
The IHTMLEditServices interface has five methods: AddDesigner, RemoveDesigner, GetSelectionServices, MoveToSelectionAnchor, and MoveToSelectionEnd.

The AddDesigner and RemoveDesigner methods are used to register and unregister a designer with the MSHTML editor. They each have only one parameter, a pointer to the IHTMLEditDesigner interface on the designer object being registered or removed.

The MoveToSelectionAnchor and MoveToSelectionEnd methods support markup-pointer-based selection. They each have one parameter, which takes a pointer to an IMarkupPointer interface. This markup pointer is placed at the beginning or end, respectively, of the current text selection. For more information about markup pointers, see the SDK documentation on Markup Services.

The GetSelectionServices method retrieves a pointer to the ISelectionServices interface on a markup container. It has two parameters, a pointer to the IMarkupContainer interface on the markup container in question and an out parameter that returns a pointer to the ISelectionServices interface on that markup container. For more information on Selection Services, see the next section.

Other Editing Interfaces that Support Extensibility
The MSHTML editor exposes a lot of functionality through public interfaces, enabling designer authors to completely customize the editor’s behavior.

A designer can use the ISelectionServices, ISelectionServicesListener, ISegment, ISegementList, ISegmentListIterator, and IElementSegement interfaces to implement its own logical selection, replacing the editor’s selection. One example of how a designer might use these interfaces would be to implement row, column, and cell selection in a table editor. Column selection, in particular, requires a range of discontiguous elements to be selected as a single logical unit. Selection services provide the functionality required to implement this and other specialized types of selection.

The IHighlightRenderingServices, IHighlightSegment, and IHTMLRenderStyle interfaces can be used to add highlighting effects and text decorations to the displayed page without changing the source of the underlying document. These interfaces are used by the editor to implement text selection. Another example of how they might be used is to create squiggles under misspelled words in a designer that does background spell checking.

The IDisplayPointer, IDisplayServices, and ILineInfo interfaces provide methods that map on-screen user actions to elements or text in the underlying source. These interfaces can be used to find out what element corresponds to the current caret position and to retrieve information about what’s displayed at a particular screen location.

The IHTMLCaret interface exposes the ability to show, hide, or move the caret and insert text at the caret position.

All of these interfaces can be used to manipulate low-level editing functionality, making it possible for a designer to control virtually every aspect of editing behavior.


Q有关IHTMLDocument2接口一系列问题,300分大赠送,masterz(),jiangsheng(蒋晟)请进~~~~~
T
1.不需要用户界面,怎样利用IHTMLDocument2及相关接口下载一个指定的网页,请给出简单且可用的源代码;
2.直接分析字符串(不下载网页)时,要执行其中的脚本程序,这时该字符串指向在网页地址为:“about:blank”,因此解释脚本出错,如何指定该字符串所属的URL呢??我试过用->put_URL方法,结果报内存错误。
如果嫌分数太少,可以另外加分,因为每贴最多只能加三百分,谢谢帮忙,越快越好~~~~
A1用<META> refresh一下看看
2怎么调用的put_URL?

This META tag causes a page to be automatically reloaded after a specified time interval. The form is as follows:
<META HTTP-EQUIV="Refresh" CONTENT="[secs];URL=[RefreshUrl]">
Possible values are described in the following table.

Value Meaning
secs Sets the number of seconds until the page is reloaded.
RefreshUrl URL to load after the specified interval.
2 iDoc是不是初始化过?
去看我put_innerHTML的代码
http://www.csdn.net/expert/topic/351/351580.shtm

1看看TRACE的输出
2这是个两难问题,walkall的说明里面就说了对脚本的支持性不好:(
看来你还是去Navigate 吧:(

  queryCommandValue Method       referrer Property (IHTMLD...       IHTMLDocument2     
 
Web Workshop  |  Reusing Browser Technology
 

readyState Property (IHTMLDocument2)

--------------------------------------------------------------------------------

Retrieves the current state of the object.

Syntax

HRESULT IHTMLDocument2::get_readyState(BSTR *p);
Parameters

p
Pointer to a BSTR that receives one of the values listed in Possible Values.
Possible Values

uninitialized Object is not initialized with data.
loading Object is loading its data.
loaded Object has finished loading its data.
interactive User can interact with the object even though it is not fully loaded.
complete Object is completely initialized.

Return Value

Returns S_OK if successful, or an error value otherwise.
Remarks

An object's state is initially set to uninitialized, and then to loading. When data loading is complete, the state of the link object passes through the loaded and interactive states to reach the complete state.

Each object determines which of the five states it exposes.

Property Information

Stock Implementation mshtml.dll
Custom Implementation No
Header and IDL files mshtml.h, mshtml.idl
Minimum availability Internet Explorer 4.0
Minimum operating systems Windows 95, Windows NT 4.0, Windows CE 2.12

See Also

onreadystatechange


Back to top 
Did you find this topic useful? Suggestions for other topics? Write us! 
&copy; 2000 Microsoft Corporation. All rights reserved. Terms of use.

IHtmlElement和一些标签相关的接口,比如IHTMLAnchorElement,IHTMLImgElement等等
Q600分悬赏IHTMLDocument2高手,急~~~~~~ 
T
先给三百分,解决问题后再给300分(因为一贴最多只能给300分)
编译连接都成功,但运行时报错,谁能调通,600分给谁,源程序如下:
#include <stdio.h>
#include <Urlmon.h>
#pragma comment(lib,"Urlmon.lib")

#include <mshtml.h>
#include <Exdisp.h>
#include <comutil.h>
#pragma comment(lib,"comsupp.lib")

#define COM_CHECK(hr) {if(FAILED(hr))throw hr;}

int main(void)
{
IStream* pStream;
HRESULT hr = NOERROR;

char szWebSite[] = "http://www.163.net";
COM_CHECK(URLOpenBlockingStream( 0, szWebSite, &pStream, 0, 0));

CoInitialize(NULL);
IWebBrowser * pWebBrowser=NULL;
IPersistStreamInit *pPersistStreamInit=NULL;
CoCreateInstance(CLSID_WebBrowser,
                   NULL,
                   CLSCTX_INPROC_SERVER,
                   IID_IWebBrowser,
                   (LPVOID *) &pWebBrowser);

COM_CHECK(pWebBrowser->QueryInterface(IID_IPersistStreamInit,(void **)&pPersistStreamInit));
//hr = pPersistStreamInit->InitNew();
//这里报错了
COM_CHECK(pPersistStreamInit->Load(pStream));

IDispatch *pDisp = NULL;
IHTMLDocument2 *pDoc = NULL;

COM_CHECK(pWebBrowser->get_Document(&pDisp));
hr = pDisp->QueryInterface(IID_IHTMLDocument2,(void**)&pDoc);
printf("hr = %d/n",hr);
//这里报错了
BSTR bstrText;
pDoc->get_title(&bstrText);
char *szPrint = _com_util::ConvertBSTRToString(bstrText);
printf("%s",szPrint);
SysFreeString(bstrText);
pDoc->Release();
pDisp->Release();
pWebBrowser->Release();
pPersistStreamInit->Release();
pStream->Release();

CoUninitialize();

return TRUE;
}
A
HRESULT LoadWebBrowserFromStream(IWebBrowser* pWebBrowser, IStream* pStream)
{
HRESULT hr;
IDispatch* pHtmlDoc = NULL;
IPersistStreamInit* pPersistStreamInit = NULL;

    // Retrieve the document object.
    hr = pWebBrowser->get_Document( &pHtmlDoc );
    if ( SUCCEEDED(hr) )
    {
        // Query for IPersistStreamInit.
        hr = pHtmlDoc->QueryInterface( IID_IPersistStreamInit,  (void**)&pPersistStreamInit );
        if ( SUCCEEDED(hr) )
        {
            // Initialize the document.
            hr = pPersistStreamInit->InitNew();
            if ( SUCCEEDED(hr) )
            {
                // Load the contents of the stream.
                hr = pPersistStreamInit->Load( pStream );
            }
            pPersistStreamInit->Release();
        }
    }
}


你的webbrowser里面至少要有一个文档(about:blank也可以)才能开始工作:(


回复人: superrg(秀华) (2002-1-21 17:26:56)  得0分
to jiangsheng(蒋晟):
这里好像只提到了如何Load,Load完后怎么通过IHTMLDocument2接口进行处理呢????

http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/tutorials/WebOCStream.asp?frame=true
 
Navigating to about:blank(这个你没看?)
The IWebBrowser2::Navigate2 method of the IWebBrowser2 interface enables you to navigate the browser to a URL. In the following sample code, the IWebBrowser2::Navigate2 method is used to navigate to the about:blank page. Navigating to this empty page ensures that MSHTML is loaded and that the HTML elements are available through the Dynamic HTML (DHTML) Object Model.

This example demonstrates how to navigate the WebBrowser control to an empty page. The variable m_pBrowser contains the IWebBrowser2 interface pointer obtained from the WebBrowser control.

m_pBrowser->Navigate2( _T("about:blank"), NULL, NULL, NULL, NULL );
Availability of the DHTML Object Model
The DHTML Object Model is used to access and manipulate the contents of an HTML page and is not available until the page is loaded. Your application determines that a page is loaded by handling the DWebBrowserEvents2::DocumentComplete event of the WebBrowser control. This event may be fired once for each frame in the page, and once when the top frame of the document is loaded. You can determine if the DWebBrowserEvents2::DocumentComplete event is for the top frame by comparing the IDispatch interface pointer passed by this event with that of the WebBrowser control.

This sample handler code for the WebBrowser DWebBrowserEvents2::DocumentComplete event demonstrates how to determine if this event is for the top frame, which indicates that the HTML page has loaded. This sample also demonstrates how to create a stream from a block of memory—in this case a string that contains the HTML content to be displayed.

Hide Example

void myObject::DocumentComplete(LPDISPATCH pDisp, VARIANT* URL)
{
HRESULT hr;
IUnknown* pUnkBrowser = NULL;
IUnknown* pUnkDisp = NULL;
IStream* pStream = NULL;
HGLOBAL hHTMLText;
static char szHTMLText[] = "<html><h1>Stream Test</h1><p>This HTML content is/
    being loaded from a stream.</html>";

    // Is this the DocumentComplete event for the top frame window?
    // Check COM identity: compare IUnknown interface pointers.
    hr = m_pBrowser->QueryInterface( IID_IUnknown,  (void**)&pUnkBrowser );
    if ( SUCCEEDED(hr) )
    {
        hr = pDisp->QueryInterface( IID_IUnknown,  (void**)&pUnkDisp );
        if ( SUCCEEDED(hr) )
        {
            if ( pUnkBrowser == pUnkDisp )
            {   // This is the DocumentComplete event for the top frame - page is loaded!
                // Create a stream containing the HTML.
                // Alternatively, this stream may have been passed to us.
                hHTMLText = GlobalAlloc( GPTR, lstrlen(szHTMLText)+1 );
                if ( hHTMLText )
                {
                    lstrcpy( (char*)hHTMLText, szHTMLText );
                    hr = CreateStreamOnHGlobal( hHTMLText, TRUE, &pStream );
                    if ( SUCCEEDED(hr) )
                    {
                       // Call the helper function to load the Web Browser from the stream.
                       LoadWebBrowserFromStream( m_pBrowser, pStream  );
                       pStream->Release();
                    }
                    GlobalFree( hHTMLText );
                }
            }
            pUnkDisp->Release();
        }
        pUnkBrowser->Release();
    }
}
Using QueryInterface to Obtain the IPersistStreamInit Interface
The IWebBrowser2::get_Document property on the WebBrowser control retrieves the document object that represents the DHTML Object Model for the top frame. MSHTML implements the IPersistStreamInit interface to provide the ability to load and save HTML using a stream, through the document object. The IDispatch interface for the document object can be queried for the IPersistStreamInit interface pointer using QueryInterface with an identifier of IID_IPersistStreamInit, as shown in the following code example.

Hide Example

HRESULT LoadWebBrowserFromStream(IWebBrowser* pWebBrowser, IStream* pStream)
{
HRESULT hr;
IDispatch* pHtmlDoc = NULL;
IPersistStreamInit* pPersistStreamInit = NULL;

    // Retrieve the document object.
    hr = pWebBrowser->get_Document( &pHtmlDoc );
    if ( SUCCEEDED(hr) )
    {
        // Query for IPersistStreamInit.
        hr = pHtmlDoc->QueryInterface( IID_IPersistStreamInit,  (void**)&pPersistStreamInit );
        if ( SUCCEEDED(hr) )
        {
            // Initialize the document.
            hr = pPersistStreamInit->InitNew();
            if ( SUCCEEDED(hr) )
            {
                // Load the contents of the stream.
                hr = pPersistStreamInit->Load( pStream );
            }
            pPersistStreamInit->Release();
        }
    }
}
Using the IPersistStreamInit Interface to Load HTML Content
The IPersistStreamInit interface has InitNew and Load methods that are used to initialize and load an HTML document from a stream. The InitNew method initializes the stream to a known state and the Load method loads the HTML content from the stream.

In the previous sample code, the HTML document is initialized and the HTML content is loaded from the stream.

Note  In Microsoft Internet Explorer 5, more than one call to the Load method of the IPersist interfaces is supported. In earlier versions, only one call to Load per instance of MSHTML is supported.
Offline Reading
The following articles provide information about the Component Object Model (COM).

Inside OLE, 2nd Edition, by Kraig Brockschmidt (Microsoft Press)
Understanding ActiveX and OLE, by David Chappell (Microsoft Press)
Inside COM, by Dale Rogerson (Microsoft Press)



在DocumentComplete事件处理里面LoadWebBrowserFromStream
void myObject::DocumentComplete(LPDISPATCH pDisp, VARIANT* URL)
{
HRESULT hr;
IUnknown* pUnkBrowser = NULL;
IUnknown* pUnkDisp = NULL;
IStream* pStream = NULL;
HGLOBAL hHTMLText;
static char szHTMLText[] = "<html><h1>Stream Test</h1><p>This HTML content is/
    being loaded from a stream.</html>";

    // Is this the DocumentComplete event for the top frame window?
    // Check COM identity: compare IUnknown interface pointers.
    hr = m_pBrowser->QueryInterface( IID_IUnknown,  (void**)&pUnkBrowser );
    if ( SUCCEEDED(hr) )
    {
        hr = pDisp->QueryInterface( IID_IUnknown,  (void**)&pUnkDisp );
        if ( SUCCEEDED(hr) )
        {
            if ( pUnkBrowser == pUnkDisp )
            {  // This is the DocumentComplete event for the top frame - page is loaded!
                // Create a stream containing the HTML.
                // Alternatively, this stream may have been passed to us.
                hHTMLText = GlobalAlloc( GPTR, lstrlen(szHTMLText)+1 );
                if ( hHTMLText )
                {
                    lstrcpy( (char*)hHTMLText, szHTMLText );
                    hr = CreateStreamOnHGlobal( hHTMLText, TRUE, &pStream );
                    if ( SUCCEEDED(hr) )
                    {
                      // Call the helper function to load the Web Browser from the stream.
                      LoadWebBrowserFromStream( m_pBrowser, pStream  );
                      pStream->Release();
                    }
                    GlobalFree( hHTMLText );
                }
            }
            pUnkDisp->Release();
        }
        pUnkBrowser->Release();
    }
}

Qjiangsheng,帮帮忙
T关于我的VC不支持IHTMLElement2接口,但系统肯定是支持的,我应该怎么调用这个接口。我不太懂COM,最好能给一些源码。谢谢
A
1 升级你的SDK

http://www.microsoft.com/msdownload/platformsdk/sdkupdate/
2 示例

HOWTO: Programmatically Copy an IMG Element to the Clipboard

Q293125


--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Internet Explorer (Programming) versions 4.0, 4.01, 4.01 SP1, 4.01 SP2, 5, 5.01, 5.01 SP1, 5.5, 5.5 Service Pack 1
Microsoft Visual Studio, Enterprise Edition 6.0

--------------------------------------------------------------------------------


SUMMARY
This article illustrates how to programmatically copy an image on a Web page (an IMG element) to the clipboard.



MORE INFORMATION
The best way to copy an image on a Web page to the clipboard is to use the execCommand method of the controlRange object. The following code illustrates to do this from within script on the page itself (given the ID of the image to be copied):


   function copyImage(sImgID)
   {
      var ctrlRange = document.body.createControlRange();
      ctrlRange.add(document.all(sImgID));
      ctrlRange.execCommand("Copy");
   }
In Microsoft Visual C++, this method call translates to IHTMLControlRange::execCommand. The following code illustrates how to implement the same technique in Visual C++ given an IDispatch pointer to the document that contains the image and the ID of the IMG element wrapped in a VARIANT structure (with a type VT_BSTR):

   STDMETHODIMP CMyBrowser::CopyImage(LPDISPATCH pDispDoc, VARIANT vImageID)
   {
      HRESULT hr        = E_FAIL;
      IHTMLDocument2* pDoc = NULL;
      IHTMLElement* pelmBody = NULL;
      IHTMLElement2* pelmBodyTwo = NULL;
      IDispatch* pdispImgElement = NULL;
      IDispatch* pdispCtrlRange = NULL;
      IHTMLElementCollection* pColl = NULL;
      IHTMLControlElement* pCtrlElement = NULL;
      IHTMLControlRange* pCtrlRange = NULL;
      BSTR bstrCommand = SysAllocString(L"Copy");
      VARIANT_BOOL vbReturn;
      VARIANT vEmpty;
      VariantInit(&vEmpty);
 
      if (pDispDoc == NULL)
         goto Cleanup;

      if (FAILED(pDispDoc->QueryInterface(IID_IHTMLDocument2, (void**) &pDoc)))
         goto Cleanup;

      if (FAILED(pDoc->get_all(&pColl)))
         goto Cleanup;

      if (FAILED(pColl->item(vImageID, vEmpty, &pdispImgElement))
            || pdispImgElement == NULL)
         goto Cleanup;
 
      if (FAILED(pDoc->get_body(&pelmBody)) || pelmBody == NULL)
         goto Cleanup;
 
      if (FAILED(pelmBody->QueryInterface(IID_IHTMLElement2, (void**) &pelmBodyTwo))
            || pelmBodyTwo == NULL)
         goto Cleanup;
 
      if (FAILED(pelmBodyTwo->createControlRange(&pdispCtrlRange))
            || pdispCtrlRange == NULL)
         goto Cleanup;
 
      if (FAILED(pdispCtrlRange->QueryInterface(IID_IHTMLControlRange, (void**) &pCtrlRange))
            || pCtrlRange == NULL)
         goto Cleanup;

      if (FAILED(pdispImgElement->QueryInterface(IID_IHTMLControlElement, (void**) &pCtrlElement))
            || pCtrlElement == NULL)
         goto Cleanup;
 
      hr = pCtrlRange->add(pCtrlElement);

      if (SUCCEEDED(hr))
         hr = pCtrlRange->execCommand(bstrCommand, VARIANT_FALSE, vEmpty, &vbReturn);
 
      pCtrlElement->Release();
      hr = S_OK;

   Cleanup:

      SysFreeString(bstrCommand);

      if (pCtrlRange)
         pCtrlRange->Release();

      if (pdispCtrlRange)
         pdispCtrlRange->Release();
 
      if (pelmBodyTwo)
         pelmBodyTwo->Release();

      if (pelmBody)
         pelmBody->Release();

      if (pdispImgElement)
         pdispImgElement->Release();

      if (pColl)
         pColl->Release();

      if (pDispDoc)
         pDispDoc->Release();

      return hr;
   }



Q===菜鸟系列===:请问如何用VC获得网页的标题?高手请进,菜鸟也请进,大家都进来吧!
T例如www.csdn.net的标题就是“CSDN.NET--中国软件”,就是最左上角的那个,请多多指教,谢谢了!
A
/****************************************************************************/
* Function: CHtml::GetTitle
*
* Description:
* &raquo;&ntilde;&micro;&Atilde;&Iacute;&oslash;&Ograve;&sup3;±ê&Igrave;&acirc;
*
* Parameters:
* CString strURL        ->&Iacute;&oslash;&Ograve;&sup3;&micro;&Oslash;&Ouml;·
* CString &strTitle     <-±ê&Igrave;&acirc;
*
* Return:
* HRESULT               <- S_OK if successful,S_FALSE otherwise
*
* 2002-4-5  13:24:20
*
* ×÷&Otilde;&szlig;: &frac12;&macr;ê&Eacute;
/*****************************************************************************/

HRESULT CHtml::GetTitle(CString strURL, CString &strTitle)
{
 strTitle=strURL;
 HRESULT hr = NOERROR;
 if (!g_pHtmlApp)
 {
  return S_FALSE;
 }

 if (SUCCEEDED(hr =g_pHtmlApp->Init(strURL)))
 {
  g_pHtmlApp->Run();
  g_pHtmlApp->Term();
  strTitle=g_pHtmlApp->GetTitle();
 }

 
 if (FAILED(hr))
 {
  return S_FALSE;
 }
 else
 {

  return S_OK;
 }
}

// ===========================================================================
// File: W I N S I N K . H
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright 1995-2000 Microsoft Corporation.  All Rights Reserved.

#ifndef _WinSink_h_
#define _WinSink_h_

class CWinSink : public IDispatch
{
public:
 CWinSink() : m_pWin(NULL), m_dwRef(1),
   m_hrConnected(CONNECT_E_CANNOTCONNECT),
   m_dwCookie(0), m_pCP(NULL)
 {
 }

 ~CWinSink()
 {
 }

 HRESULT Init(IHTMLWindow2* pWin);
 HRESULT Passivate()
 {
  HRESULT hr = NOERROR;
  if (m_pCP)
  {
   if (m_dwCookie)
   {
    hr = m_pCP->Unadvise(m_dwCookie);
    m_dwCookie = 0;
   }

    m_pCP->Release();
    m_pCP = NULL;
  }

  if (m_pWin)
  {
   m_pWin->Release();
   m_pWin = NULL;
  }

  return NOERROR;
 }

 // IUnknown methods
    STDMETHOD(QueryInterface)(REFIID riid, LPVOID* ppv);
    STDMETHOD_(ULONG, AddRef)();
    STDMETHOD_(ULONG, Release)();

 // IDispatch method
 STDMETHOD(GetTypeInfoCount)(UINT* pctinfo)
   { ODS("GetTypeInfoCount/n"); return E_NOTIMPL; }

 STDMETHOD(GetTypeInfo)(UINT iTInfo,
            LCID lcid,
            ITypeInfo** ppTInfo)
   { ODS("GetTypeInfo/n"); return E_NOTIMPL; }

 STDMETHOD(GetIDsOfNames)(REFIID riid,
            LPOLESTR* rgszNames,
            UINT cNames,
            LCID lcid,
            DISPID* rgDispId)
   { ODS("GetIDsOfNames/n"); return E_NOTIMPL; }
       
 STDMETHOD(Invoke)(DISPID dispIdMember,
            REFIID riid,
            LCID lcid,
            WORD wFlags,
            DISPPARAMS __RPC_FAR *pDispParams,
            VARIANT __RPC_FAR *pVarResult,
            EXCEPINFO __RPC_FAR *pExcepInfo,
            UINT __RPC_FAR *puArgErr);

protected:
 IHTMLWindow2* m_pWin;
 DWORD m_dwRef;

 LPCONNECTIONPOINT m_pCP;
 HRESULT m_hrConnected;
 DWORD m_dwCookie;

};

#endif
/******************************************************************************************
FileName  : D:/code/TUtil/Html.h
Author   : &frac12;&macr;ê&Eacute;
Purpose      : HTML&cedil;¨&Ouml;ú&ordm;&macr;&Ecirc;&yacute;
Date Of Creation: 2002-4-5
Modification History :
Date             Modifications
******************************************************************************************/

// Html.h: interface for the CHtml class.
//
//

#if !defined(AFX_HTML_H__9295B987_2464_4087_804E_DB3491DCC6F9__INCLUDED_)
#define AFX_HTML_H__9295B987_2464_4087_804E_DB3491DCC6F9__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "TUtil.h"

#include <windows.h>
#include <tchar.h>
#include <wininet.h>
#include <urlmon.h>
#include <mshtml.h>
#include <iostream.h>
#include <comdef.h>
#include <assert.h>
#include <servprov.h>
#include <mshtmdid.h>
#include "../TDef.h"
class CWinSink;

class DECLARE_DLL_TUTIL_CLASS CHtml 
{
public:
 static INTERNET_SCHEME GetScheme(LPCTSTR szURL);
 static HRESULT GetTitle(CString strURL,CString& strTitle);
 CHtml();
 virtual ~CHtml();

};

class CHtmlApp : public IPropertyNotifySink, IOleClientSite, IDispatch
{
public:
 CHtmlApp() : m_pMSHTML(NULL), m_dwRef(1),
   m_hrConnected(CONNECT_E_CANNOTCONNECT),
   m_dwCookie(0), m_pCP(NULL), m_nScheme(INTERNET_SCHEME_UNKNOWN),
   m_lReadyState(READYSTATE_UNINITIALIZED)
   {}
    ~CHtmlApp()
    {
    }

 HRESULT Passivate();


 // IUnknown methTRACE
    STDMETHOD(QueryInterface)(REFIID riid, LPVOID* ppv);
    STDMETHOD_(ULONG, AddRef)();
    STDMETHOD_(ULONG, Release)();

 // IPropertyNotifySink methTRACE
    STDMETHOD(OnChanged)(DISPID dispID);
    STDMETHOD(OnRequestEdit)(DISPID dispID);

 // IOleClientSite methTRACE
 STDMETHOD(SaveObject)(void) { TRACE("SaveObject/n"); return E_NOTIMPL; }

 STDMETHOD(GetMoniker)(DWORD dwAssign,
            DWORD dwWhichMoniker,
            IMoniker** ppmk)
   { TRACE("GetMoniker/n"); return E_NOTIMPL; }

 STDMETHOD(GetContainer)(IOleContainer** ppContainer)
   { TRACE("GetContainer/n"); return E_NOTIMPL; }

 STDMETHOD(ShowObject)(void)
   { TRACE("ShowObject/n"); return E_NOTIMPL; }

    STDMETHOD(OnShowWindow)(BOOL fShow)
   { TRACE("OnShowWindow/n"); return E_NOTIMPL; }

    STDMETHOD(RequestNewObjectLayout)(void)
   { TRACE("RequestNewObjectLayout/n"); return E_NOTIMPL; }

 // IDispatch method
 STDMETHOD(GetTypeInfoCount)(UINT* pctinfo)
   { TRACE("GetTypeInfoCount/n"); return E_NOTIMPL; }

 STDMETHOD(GetTypeInfo)(UINT iTInfo,
            LCID lcid,
            ITypeInfo** ppTInfo)
   { TRACE("GetTypeInfo/n"); return E_NOTIMPL; }

 STDMETHOD(GetIDsOfNames)(REFIID riid,
            LPOLESTR* rgszNames,
            UINT cNames,
            LCID lcid,
            DISPID* rgDispId)
   { TRACE("GetIDsOfNames/n"); return E_NOTIMPL; }
       
 STDMETHOD(Invoke)(DISPID dispIdMember,
            REFIID riid,
            LCID lcid,
            WORD wFlags,
            DISPPARAMS __RPC_FAR *pDispParams,
            VARIANT __RPC_FAR *pVarResult,
            EXCEPINFO __RPC_FAR *pExcepInfo,
            UINT __RPC_FAR *puArgErr);

 // Additional class methTRACE
 HRESULT Init(LPCTSTR lpszURL);
 HRESULT Run();
 HRESULT Term();
 HRESULT Walk();
 HRESULT GetUA(BSTR* pbstrUA);
 CString GetTitle(){return m_strTitle;}
protected:
 // Persistence helpers
 HRESULT LoadURLFromFile();
 HRESULT LoadURLFromMoniker();

 IHTMLDocument2* m_pMSHTML;
 DWORD m_dwRef;
 DWORD m_dwCookie;
 LPCONNECTIONPOINT m_pCP;
 HRESULT m_hrConnected;
 CString m_strURL;
 CString m_strTitle;
 INTERNET_SCHEME m_nScheme;
 READYSTATE m_lReadyState;

 CWinSink* m_pWinSink;
};
extern CHtmlApp * g_pHtmlApp ;
#endif // !defined(AFX_HTML_H__9295B987_2464_4087_804E_DB3491DCC6F9__INCLUDED_)


//
// File: W I N S I N K . C P P
//
// Copyright 1995-2000 Microsoft Corporation.  All Rights Reserved.
#include "stdafx.h"
#include <windows.h>
#include <mshtml.h>
#include <mshtmdid.h>
#include "common.h"
#include "winsink.h"
#include <iostream.h>


HRESULT CWinSink::Init(IHTMLWindow2* pWin)
{
 HRESULT hr = NOERROR;
 LPCONNECTIONPOINTCONTAINER pCPC = NULL;

 if (m_pWin)
 {
  m_pWin->Release();
 }
 m_pWin = pWin;
 try{
  hr = pWin->QueryInterface(IID_IConnectionPointContainer, (LPVOID*)&pCPC);
  if (FAILED(hr)) throw hr;
  hr = pCPC->FindConnectionPoint(DIID_HTMLWindowEvents2, &m_pCP);
  if (FAILED(hr)) throw hr;
  m_hrConnected = m_pCP->Advise((LPUNKNOWN)this, &m_dwCookie);
 }
 catch(HRESULT){
  if (pCPC) pCPC->Release();
 }
 return hr;
}

STDMETHODIMP CWinSink::QueryInterface(REFIID riid, LPVOID* ppv)
{
 *ppv = NULL;

 if (IID_IUnknown == riid)
 {
  *ppv = (LPUNKNOWN)this;
  AddRef();
  return NOERROR;
 }
 else if (IID_IDispatch == riid)
 {
  *ppv = (IDispatch*)this;
  AddRef();
  return NOERROR;
 }
 else
 {
  OLECHAR wszBuff[39];
  int i = StringFromGUID2(riid, wszBuff, 39);
  TCHAR szBuff[39];
  i = WideCharToMultiByte(CP_ACP, 0, wszBuff, -1, szBuff, 39, NULL, NULL);
  ODS("CWinSink QI: "); ODS(szBuff); ODS("/n");
  return E_NOTIMPL;
 }
}

STDMETHODIMP_(ULONG) CWinSink::AddRef()
{
 return ++m_dwRef;
}

STDMETHODIMP_(ULONG) CWinSink::Release()
{
 if (--m_dwRef == 0)
 {
  delete this;
  return 0;
 }

 return m_dwRef;
}

// OA events are fired through the IDispatch::Invoke of the sink object
STDMETHODIMP CWinSink::Invoke(DISPID dispIdMember,
            REFIID riid,
            LCID lcid,
            WORD wFlags,
            DISPPARAMS __RPC_FAR *pDispParams,
            VARIANT __RPC_FAR *pVarResult,
            EXCEPINFO __RPC_FAR *pExcepInfo,
            UINT __RPC_FAR *puArgErr)
{
 if (!pVarResult)
 {
  return E_POINTER;
 }

 switch(dispIdMember)
 {

 case DISPID_HTMLWINDOWEVENTS2_ONLOAD:
  break;
 default:
  return DISP_E_MEMBERNOTFOUND;
 }

 return NOERROR;
}

// Html.cpp: implementation of the CHtml class.

#include "stdafx.h"
#include "Html.h"
#include "common.h"
#include "winsink.h"
#define WM_USER_STARTWALKING WM_USER+400
#define C_USAGE _T("Usage: walkall <URL>")
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

CHtml::CHtml(){}
CHtml::~CHtml(){}
CHtmlApp* g_pHtmlApp =NULL;

HRESULT CHtmlApp::Passivate()
{
 HRESULT hr = NOERROR;

 // Disconnect from property change notifications
 if (m_pCP)
 {
  if (m_dwCookie)
  {
   hr = m_pCP->Unadvise(m_dwCookie);
   m_dwCookie = 0;
  }

  // Release the connection point
  m_pCP->Release();
  m_pCP = NULL;
 }

 if (m_pWinSink)
 {
  m_pWinSink->Passivate();
  m_pWinSink->Release();
  m_pWinSink = NULL;
 }

 if (m_pMSHTML)
 {
  m_pMSHTML->Release();
  m_pMSHTML = NULL;
 }

 return NOERROR;
}

STDMETHODIMP CHtmlApp::QueryInterface(REFIID riid, LPVOID* ppv)
{
 *ppv = NULL;

 if (IID_IUnknown == riid || IID_IPropertyNotifySink == riid)
 {
  *ppv = (LPUNKNOWN)(IPropertyNotifySink*)this;
  AddRef();
  return NOERROR;
 }
 else if (IID_IOleClientSite == riid)
 {
  *ppv = (IOleClientSite*)this;
  AddRef();
  return NOERROR;
 }
 else if (IID_IDispatch == riid)
 {
  *ppv = (IDispatch*)this;
  AddRef();
  return NOERROR;
 }
 else
 {
  return E_NOTIMPL;
 }
}

STDMETHODIMP_(ULONG) CHtmlApp::AddRef()
{
 return ++m_dwRef;
}

STDMETHODIMP_(ULONG) CHtmlApp::Release()
{
 if (--m_dwRef == 0)
 {
  delete this;
  return 0;
 }

 //TRACE(szBuff);
 return m_dwRef;
}

// Fired on change of the value of a 'bindable' property
STDMETHODIMP CHtmlApp::OnChanged(DISPID dispID)
{
 HRESULT hr;
 //TCHAR szBuff[255];

 if (DISPID_READYSTATE == dispID)
 {
  // check the value of the readystate property
  assert(m_pMSHTML);

  VARIANT vResult = {0};
  EXCEPINFO excepInfo;
  UINT uArgErr;

  DISPPARAMS dp = {NULL, NULL, 0, 0};
  if (SUCCEEDED(hr = m_pMSHTML->Invoke(DISPID_READYSTATE, IID_NULL, LOCALE_SYSTEM_DEFAULT,
   DISPATCH_PROPERTYGET, &dp, &vResult, &excepInfo, &uArgErr)))
  {
   assert(VT_I4 == V_VT(&vResult));
   m_lReadyState = (READYSTATE)V_I4(&vResult);
   switch (m_lReadyState)
   {
   case READYSTATE_COMPLETE: // = 4
    BOOL fRet = PostThreadMessage(GetCurrentThreadId(),
         WM_USER_STARTWALKING,
         (WPARAM)0,
         (LPARAM)0);
    break;
   }
   VariantClear(&vResult);
  }
 }
 return NOERROR;
}

STDMETHODIMP CHtmlApp::OnRequestEdit(DISPID dispID)
{
 // Property changes are OK any time as far as this app is concerned
 return NOERROR;
}

// Return the protocol associated with the specified URL
INTERNET_SCHEME GetScheme(LPCTSTR szURL)
{
 URL_COMPONENTS urlComponents;
 DWORD dwFlags = 0;
 INTERNET_SCHEME nScheme = INTERNET_SCHEME_UNKNOWN;

 ZeroMemory((PVOID)&urlComponents, sizeof(URL_COMPONENTS));
 urlComponents.dwStructSize = sizeof(URL_COMPONENTS);

 if (szURL)
 {
  if (InternetCrackUrl(szURL, 0, dwFlags, &urlComponents))
  {
   nScheme = urlComponents.nScheme;
  }
 }

 return nScheme;
}

// Initialize the app. Load MSHTML, hook up property notification sink, etc
HRESULT CHtmlApp::Init(LPCTSTR lpszURL)
{
 HRESULT hr;
 LPCONNECTIONPOINTCONTAINER pCPC = NULL;
 LPOLEOBJECT pOleObject = NULL;
 LPOLECONTROL pOleControl = NULL;
 BSTR bstrUA = NULL;
 _bstr_t _bstrUA;
 // check the scheme (protocol)
 // to determine which persistence interface to use
 // see the Run method for where the scheme is used
 m_strURL = lpszURL;
 m_nScheme = GetScheme(m_strURL);
 try{
  // Create an instance of an dynamic HTML document
  hr = CoCreateInstance( CLSID_HTMLDocument, NULL,
      CLSCTX_INPROC_SERVER, IID_IHTMLDocument2,
      (LPVOID*)&m_pMSHTML);
  if (FAILED(hr))   throw hr;
  IHTMLWindow2* pWin;
  hr = m_pMSHTML->get_parentWindow(&pWin);
  if (FAILED(hr))   throw hr;
  m_pWinSink = new CWinSink();
  if (!m_pWinSink)throw hr;
  hr = m_pWinSink->Init(pWin);
  if (FAILED(hr)){
   pWin->Release();
   throw hr;
  }
  hr = m_pMSHTML->QueryInterface(IID_IOleObject, (LPVOID*)&pOleObject);
  if (FAILED(hr))   throw hr;
  hr = pOleObject->SetClientSite((IOleClientSite*)this);
  if (FAILED(hr))   throw hr;
  pOleObject->Release();
  hr = m_pMSHTML->QueryInterface(IID_IOleControl, (LPVOID*)&pOleControl);
  if (FAILED(hr))   throw hr;
  hr = pOleControl->OnAmbientPropertyChange(DISPID_AMBIENT_USERMODE);
  if (FAILED(hr))   throw hr;
  hr = pOleControl->OnAmbientPropertyChange(DISPID_AMBIENT_DLCONTROL);
  if (FAILED(hr))   throw hr;
  pOleControl->Release();
  hr = m_pMSHTML->QueryInterface(IID_IConnectionPointContainer, (LPVOID*)&pCPC);
  if (FAILED(hr))   throw hr;
  hr = pCPC->FindConnectionPoint(IID_IPropertyNotifySink, &m_pCP);
  if (FAILED(hr))   throw hr;
  m_hrConnected = m_pCP->Advise((LPUNKNOWN)(IPropertyNotifySink*)this, &m_dwCookie);
 }
 catch(HRESULT ){
  if (pCPC) pCPC->Release();
 }
 return hr;
}

// Clean up connection point
HRESULT CHtmlApp::Term()
{
 return Passivate();
}

// Load the specified document and start pumping messages
HRESULT CHtmlApp::Run()
{
 HRESULT hr;
 MSG msg;

 switch(m_nScheme)
 {
 case INTERNET_SCHEME_HTTP:
    case INTERNET_SCHEME_FTP:
    case INTERNET_SCHEME_GOPHER:
    case INTERNET_SCHEME_HTTPS:
    case INTERNET_SCHEME_FILE:
  // load URL using IPersistMoniker
  hr = LoadURLFromMoniker();
  break;
    case INTERNET_SCHEME_NEWS:
    case INTERNET_SCHEME_MAILTO:
    case INTERNET_SCHEME_SOCKS:
  // we don't handle these
  return E_FAIL;
  break;
 default:
  // try loading URL using IPersistFile
  hr = LoadURLFromFile();
  break;
 }

 if (SUCCEEDED(hr) || E_PENDING == hr)
 {

  while (GetMessage(&msg, NULL, 0, 0))
  {
   if (WM_USER_STARTWALKING == msg.message && NULL == msg.hwnd)
   {
    Walk();
   }
   else
   {
    DispatchMessage(&msg);
   }
  }
 }

 return hr;
}


Q好久没来啦,问几百个MSHTML的问题先!!!!!!!
T
jiangsheng在不在?masterz在吗?


问题1,我要把网页里的script的源代码弄出来,用IHTMLDocument2::get_scripts(IHTMLElementCollection** p);获得script的集合,然后我一个一个地item出每个IHTMLElement指针,最后用IHTMLElement::get_innerHTML获得源代码。可是每次都得到一行5、6个字符的乱码。

谁能告诉我如何把HTML里的script源代码弄出来?


问题2,想不起来了,想起来再问
A
老错误了
if(pAllElem->item(name, name, (LPDISPATCH*)&pElem)==S_OK)
这里错了,你不能把COM接口指针强制转换的,即使一个接口的对象总是支持另外一个接口。
CComQIPtr<IDispatch> pDispTemp;
if(m_pLastForm->item(_variant_t(_bstr_t("check")),varDummy,&pDispTemp.p)==S_OK){
CComQIPtr<IHTMLInputHiddenElement> pInput(pDispTemp);
if(pInput){
pInput->put_value(bstrTime);
}
}


对于这个问题的解释
struct IA:public IUnknown
{

};
struct IB:public IUnknown
{

};
CA:public IA{};
CB:public IB{};
struct IC:public IUnknown
{
};
CC:public IC
{
  A a;
  B b;
  HRESULT QueryInterface(REFIID riid, LPVOID* obp);
);

HRESULT CC::QueryInterface(REFIID riid, LPVOID* obp)
{
 *ppv=NULL;
            if (riid == IID_IUnknown)
                *ppv=this;
            if (riid == IID_IA)
                *ppv=&a;
            if (riid == IID_IB)
                *ppv=&b;
            if (NULL==*ppv)
                return ResultFromScode(E_NOINTERFACE);
            ((IUnknown*)*ppv)->AddRef();
            return NOERROR;  
   }
 
}

Q怎样从获得的IHtmlDocument2的接口中进一步获得flash的地址...(jiangsheng能帮忙吗)
T
我用elementFromPoint方法获得了flash对像的接口,再怎么进一步获得这个flash对像的地址呢?如
<PARAM NAME=movie VALUE="/images/ad/winsunlight_banner.swf">
中 VALUE 的值?
A
我用elementFromPoint方法获得了flash对像的接口,再怎么进一步获得这个flash对像的地址呢?如
<PARAM NAME=movie VALUE="/images/ad/winsunlight_banner.swf">
中 VALUE 的值?

From MFC source:
HRESULT CDHtmlDialog::GetElement(LPCTSTR szElementId, IDispatch **ppdisp,
         BOOL *pbCollection /*= NULL*/)
{
 CComPtr<IHTMLElementCollection> sphtmlAll;
 CComPtr<IHTMLElementCollection> sphtmlColl;
 CComPtr<IDispatch> spdispElem;
 CComVariant varName;
 CComVariant varIndex;
 HRESULT hr = S_OK;
 CComPtr<IHTMLDocument2> sphtmlDoc;
 USES_CONVERSION;

 *ppdisp = NULL;

 if (pbCollection)
  *pbCollection = FALSE;

 hr = GetDHtmlDocument(&sphtmlDoc);
 if (sphtmlDoc == NULL)
  return hr;

 varName.vt = VT_BSTR;
 varName.bstrVal = T2BSTR(szElementId);
 if (!varName.bstrVal)
 {
  hr = E_OUTOFMEMORY;
  goto Error;
 }

 hr = sphtmlDoc->get_all(&sphtmlAll);
 if (sphtmlAll == NULL)
  goto Error;
 hr = sphtmlAll->item(varName, varIndex, &spdispElem);
 if (spdispElem == NULL)
 {
  hr = E_NOINTERFACE;
  goto Error;
 }

 spdispElem->QueryInterface(__uuidof(IHTMLElementCollection), (void **) &sphtmlColl);
 if (sphtmlColl)
 {
  if (pbCollection)
   *pbCollection = TRUE;
#ifdef _DEBUG
  else
  {
   TRACE(traceHtml, 0, "Warning: duplicate IDs or NAMEs./n");
   ATLASSERT(FALSE);
  }
#endif

 }
Error:
 if (SUCCEEDED(hr))
 {
  *ppdisp = spdispElem;
  if (spdispElem)
   (*ppdisp)->AddRef();
 }
 return hr;
}

HRESULT CDHtmlDialog::GetElement(LPCTSTR szElementId, IHTMLElement **pphtmlElement)
{
 return GetElementInterface(szElementId, __uuidof(IHTMLElement), (void **) pphtmlElement);
}
HRESULT CDHtmlDialog::GetControlDispatch(LPCTSTR szId, IDispatch **ppdisp)
{
 HRESULT hr = S_OK;
 CComPtr<IDispatch> spdispElem;

 hr = GetElement(szId, &spdispElem);

 if (spdispElem)
 {
  CComPtr<IHTMLObjectElement> sphtmlObj;

  hr = spdispElem.QueryInterface(&sphtmlObj);
  if (sphtmlObj)
  {
   spdispElem.Release();
   hr = sphtmlObj->get_object(ppdisp);
  }
 }
 return hr;
}

VARIANT CDHtmlDialog::GetControlProperty(IDispatch *pdispControl, DISPID dispid)
{
 VARIANT varRet;
 varRet.vt = VT_EMPTY;
 if (pdispControl)
 {
  DISPPARAMS dispparamsNoArgs = { NULL, NULL, 0, 0 };
  pdispControl->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT,
   DISPATCH_PROPERTYGET, &dispparamsNoArgs, &varRet, NULL, NULL);
 }
 return varRet;
}

VARIANT CDHtmlDialog::GetControlProperty(LPCTSTR szId, DISPID dispid)
{
 CComPtr<IDispatch> spdispElem;

 GetControlDispatch(szId, &spdispElem);
 return GetControlProperty(spdispElem, dispid);
}

VARIANT CDHtmlDialog::GetControlProperty(LPCTSTR szId, LPCTSTR szPropName)
{
 CComVariant varEmpty;
 CComPtr<IDispatch> spdispElem;

 GetControlDispatch(szId, &spdispElem);
 if (!spdispElem)
  return varEmpty;

 DISPID dispid;
 USES_CONVERSION;
 LPOLESTR pPropName = (LPOLESTR)T2COLE(szPropName);
 HRESULT hr = spdispElem->GetIDsOfNames(IID_NULL, &pPropName, 1, LOCALE_USER_DEFAULT, &dispid);
 if (SUCCEEDED(hr))
  return GetControlProperty(spdispElem, dispid);
 return varEmpty;
}

void CDHtmlDialog::SetControlProperty(IDispatch *pdispControl, DISPID dispid, VARIANT *pVar)
{
 if (pdispControl != NULL)
 {
  DISPPARAMS dispparams = {NULL, NULL, 1, 1};
  dispparams.rgvarg = pVar;
  DISPID dispidPut = DISPID_PROPERTYPUT;
  dispparams.rgdispidNamedArgs = &dispidPut;

  pdispControl->Invoke(dispid, IID_NULL,
    LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUT,
    &dispparams, NULL, NULL, NULL);
 }
}

void CDHtmlDialog::SetControlProperty(LPCTSTR szElementId, DISPID dispid, VARIANT *pVar)
{
 CComPtr<IDispatch> spdispElem;
 GetControlDispatch(szElementId, &spdispElem);

 SetControlProperty(spdispElem, dispid, pVar);
}

void CDHtmlDialog::SetControlProperty(LPCTSTR szElementId, LPCTSTR szPropName, VARIANT *pVar)
{
 CComPtr<IDispatch> spdispElem;
 GetControlDispatch(szElementId, &spdispElem);
 if (!spdispElem)
  return;
 DISPID dispid;
 USES_CONVERSION;
 LPOLESTR pPropName = (LPOLESTR)T2COLE(szPropName);
 HRESULT hr = spdispElem->GetIDsOfNames(IID_NULL, &pPropName, 1, LOCALE_USER_DEFAULT, &dispid);
 if (SUCCEEDED(hr))
  SetControlProperty(spdispElem, dispid, pVar);
}


From MFC source:
HRESULT CDHtmlDialog::GetElement(LPCTSTR szElementId, IDispatch **ppdisp,
         BOOL *pbCollection /*= NULL*/)
{
 CComPtr<IHTMLElementCollection> sphtmlAll;
 CComPtr<IHTMLElementCollection> sphtmlColl;
 CComPtr<IDispatch> spdispElem;
 CComVariant varName;
 CComVariant varIndex;
 HRESULT hr = S_OK;
 CComPtr<IHTMLDocument2> sphtmlDoc;
 USES_CONVERSION;

 *ppdisp = NULL;

 if (pbCollection)
  *pbCollection = FALSE;

 hr = GetDHtmlDocument(&sphtmlDoc);
 if (sphtmlDoc == NULL)
  return hr;

 varName.vt = VT_BSTR;
 varName.bstrVal = T2BSTR(szElementId);
 if (!varName.bstrVal)
 {
  hr = E_OUTOFMEMORY;
  goto Error;
 }

 hr = sphtmlDoc->get_all(&sphtmlAll);
 if (sphtmlAll == NULL)
  goto Error;
 hr = sphtmlAll->item(varName, varIndex, &spdispElem);
 if (spdispElem == NULL)
 {
  hr = E_NOINTERFACE;
  goto Error;
 }

 spdispElem->QueryInterface(__uuidof(IHTMLElementCollection), (void **) &sphtmlColl);
 if (sphtmlColl)
 {
  if (pbCollection)
   *pbCollection = TRUE;
#ifdef _DEBUG
  else
  {
   TRACE(traceHtml, 0, "Warning: duplicate IDs or NAMEs./n");
   ATLASSERT(FALSE);
  }
#endif

 }
Error:
 if (SUCCEEDED(hr))
 {
  *ppdisp = spdispElem;
  if (spdispElem)
   (*ppdisp)->AddRef();
 }
 return hr;
}

HRESULT CDHtmlDialog::GetElement(LPCTSTR szElementId, IHTMLElement **pphtmlElement)
{
 return GetElementInterface(szElementId, __uuidof(IHTMLElement), (void **) pphtmlElement);
}
HRESULT CDHtmlDialog::GetControlDispatch(LPCTSTR szId, IDispatch **ppdisp)
{
 HRESULT hr = S_OK;
 CComPtr<IDispatch> spdispElem;

 hr = GetElement(szId, &spdispElem);

 if (spdispElem)
 {
  CComPtr<IHTMLObjectElement> sphtmlObj;

  hr = spdispElem.QueryInterface(&sphtmlObj);
  if (sphtmlObj)
  {
   spdispElem.Release();
   hr = sphtmlObj->get_object(ppdisp);
  }
 }
 return hr;
}

VARIANT CDHtmlDialog::GetControlProperty(IDispatch *pdispControl, DISPID dispid)
{
 VARIANT varRet;
 varRet.vt = VT_EMPTY;
 if (pdispControl)
 {
  DISPPARAMS dispparamsNoArgs = { NULL, NULL, 0, 0 };
  pdispControl->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT,
   DISPATCH_PROPERTYGET, &dispparamsNoArgs, &varRet, NULL, NULL);
 }
 return varRet;
}

VARIANT CDHtmlDialog::GetControlProperty(LPCTSTR szId, DISPID dispid)
{
 CComPtr<IDispatch> spdispElem;

 GetControlDispatch(szId, &spdispElem);
 return GetControlProperty(spdispElem, dispid);
}

VARIANT CDHtmlDialog::GetControlProperty(LPCTSTR szId, LPCTSTR szPropName)
{
 CComVariant varEmpty;
 CComPtr<IDispatch> spdispElem;

 GetControlDispatch(szId, &spdispElem);
 if (!spdispElem)
  return varEmpty;

 DISPID dispid;
 USES_CONVERSION;
 LPOLESTR pPropName = (LPOLESTR)T2COLE(szPropName);
 HRESULT hr = spdispElem->GetIDsOfNames(IID_NULL, &pPropName, 1, LOCALE_USER_DEFAULT, &dispid);
 if (SUCCEEDED(hr))
  return GetControlProperty(spdispElem, dispid);
 return varEmpty;
}

void CDHtmlDialog::SetControlProperty(IDispatch *pdispControl, DISPID dispid, VARIANT *pVar)
{
 if (pdispControl != NULL)
 {
  DISPPARAMS dispparams = {NULL, NULL, 1, 1};
  dispparams.rgvarg = pVar;
  DISPID dispidPut = DISPID_PROPERTYPUT;
  dispparams.rgdispidNamedArgs = &dispidPut;

  pdispControl->Invoke(dispid, IID_NULL,
    LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUT,
    &dispparams, NULL, NULL, NULL);
 }
}

void CDHtmlDialog::SetControlProperty(LPCTSTR szElementId, DISPID dispid, VARIANT *pVar)
{
 CComPtr<IDispatch> spdispElem;
 GetControlDispatch(szElementId, &spdispElem);

 SetControlProperty(spdispElem, dispid, pVar);
}

void CDHtmlDialog::SetControlProperty(LPCTSTR szElementId, LPCTSTR szPropName, VARIANT *pVar)
{
 CComPtr<IDispatch> spdispElem;
 GetControlDispatch(szElementId, &spdispElem);
 if (!spdispElem)
  return;
 DISPID dispid;
 USES_CONVERSION;
 LPOLESTR pPropName = (LPOLESTR)T2COLE(szPropName);
 HRESULT hr = spdispElem->GetIDsOfNames(IID_NULL, &pPropName, 1, LOCALE_USER_DEFAULT, &dispid);
 if (SUCCEEDED(hr))
  SetControlProperty(spdispElem, dispid, pVar);
}

Qmshtml.dll的问题:怎么打开html文件?IHTMLDocument2接口有方法可以打开html文件吗?
T 
AHRESULT IHTMLDocument2::put_URL(BSTR v);


首先你要确定指针是合法的IHTMLDocument2指针
然后你可能要截获IHTMLDocument2的onreadystatechange事件
HRESULT IHTMLDocument2::put_onreadystatechange
extern _variant_t varreadystatechange;
CComQIPtr<IHTMLDocument2> pDoc2(GetHtmlDocument());
if(pDoc2){
    if(IHTMLDocument2::put_onreadystatechange(varreadystatechange)){
        if(pDoc2->put_URL(_bstr_t("D://1.htm")){
        //启动消息循环
       ......    
        }
    }
}


HOWTO: Sink HTML Document Events for WebBrowser Host

Q246247


--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Internet Explorer (Programming) versions 4.0, 4.01, 4.01 SP1, 4.01 SP2, 5, 5.01, 5.5

--------------------------------------------------------------------------------


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值