IE编程问题收藏

QCWebBrowser2的用法
T 我如何在一个函数中自己动态(因为我不需要对话框)创建CWebBrowser2控件,实现打印一个指定.htm文件的功能?
Ato print
m_wndWebbrowser2.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER,NULL,NULL);
to create
call CWnd::CreateControl

see the CHtmlView code in MFC source

BOOL CHtmlView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName,
      DWORD dwStyle, const RECT& rect, CWnd* pParentWnd,
      UINT nID, CCreateContext* pContext)
{
 // create the view window itself
 m_pCreateContext = pContext;
 if (!CView::Create(lpszClassName, lpszWindowName,
    dwStyle, rect, pParentWnd,  nID, pContext))
 {
  return FALSE;
 }

 // assure that control containment is on
 AfxEnableControlContainer();

 RECT rectClient;
 GetClientRect(&rectClient);

 // create the control window
 // AFX_IDW_PANE_FIRST is a safe but arbitrary ID
 if (!m_wndBrowser.CreateControl(CLSID_WebBrowser, lpszWindowName,
    WS_VISIBLE | WS_CHILD, rectClient, this, AFX_IDW_PANE_FIRST))
 {
  DestroyWindow();
  return FALSE;
 }

 // cache the dispinterface
 LPUNKNOWN lpUnk = m_wndBrowser.GetControlUnknown();
 HRESULT hr = lpUnk->QueryInterface(IID_IWebBrowser2, (void**) &m_pBrowserApp);
 if (!SUCCEEDED(hr))
 {
  m_pBrowserApp = NULL;
  m_wndBrowser.DestroyWindow();
  DestroyWindow();
  return FALSE;
 }

 return TRUE;
}
BOOL CHtmlEditCtrl::Create(LPCTSTR lpszWindowName, DWORD /*dwStyle*/, const RECT& rect, CWnd* pParentWnd,
         int nID, CCreateContext *pContext)
{
 BOOL bRet = FALSE;
 // create the control window

 AfxEnableControlContainer();
 if (CreateControl(CLSID_WebBrowser, lpszWindowName,
    WS_VISIBLE | WS_CHILD, rect, pParentWnd, nID))
 {
  // in order to put the webbrowser in design mode, you must
  // first load a document into it. "about:blank" seems to
  // be the safest thing to load for a good starting point.
  CComQIPtr<IWebBrowser2> pBrowserApp = GetControlUnknown();
  ASSERT(pBrowserApp);
  if (pBrowserApp)
  {
   CComVariant vEmpty;
   LPCTSTR szDoc = GetStartDocument();
   if (szDoc)
   {
    CComBSTR bstrStart(szDoc);
    if (S_OK == pBrowserApp->Navigate(bstrStart,
             &vEmpty,
             &vEmpty,
             &vEmpty,
             &vEmpty))
    {
     bRet = TRUE;
    }
   }
   else
    bRet = TRUE;

  }
 }

 if (!bRet)
  DestroyWindow();
 return bRet;
}
this是webbrowser2控件的父窗口
忘记CComPtr在哪里定义的了。去看一下MSDN
this应该是一个有窗口的CWnd
Do not create this control every time...place it on a CDialog/CFormView, or a controlbar.
Q请问利用IWebBrowser2的IWebBrowser2::get_Document怎样取得doc对象
T我想分析IWebBrowser2返回的网页,可是他返回的是 LPDISPATCH !这是什么数据机构?怎样才能得到HTML文本供我分析?
LPDISPATCH CWebBrowser2::GetDocument()
有谁做过类似程序吗? 请各位大侠支招!
Atwo way to get HTML interfaces
1 call CWnd::GetControlUnknown to get IWebbrowser2 Interface
LPUNKNOWN lpUnk = m_wndBrowser.GetControlUnknown();
 HRESULT hr = lpUnk->QueryInterface(IID_IWebBrowser2, (void**) &m_pBrowserApp);

2 call CHtmlView::GetHtmlDocument() or CWebBrowser2::GetDocument()
LPDISPATCH lpDisp = m_wndBrowser.GetDocument();
 HRESULT hr = lpDisp->QueryInterface(IID_IHTMLDocument2, (void**) &m_phtmlDoc);

note:objects which support IHTMLDocument2 may or may not support other interfaces,such as IHTMLDocument5 ,ICustomDoc  or IXMLDOMDocument.

void CSRWOnlineView::DocumentComplete(LPDISPATCH pDisp, VARIANT* URL)
{
 //UNUSED_ALWAYS(pDisp);
 ASSERT(V_VT(URL) == VT_BSTR);

 CString str(V_BSTR(URL));
 OnDocumentComplete(pDisp, str);
}

void CSRWOnlineView::OnDocumentComplete(LPDISPATCH pDisp, LPCTSTR lpszUrl)
{
 // make sure the main frame has the new URL.  This call also stops the animation
 ((CChildFrame*)GetParentFrame())->SetAddress(lpszUrl);
 CString strURL(lpszUrl);
 CComQIPtr<IWebBrowser2> pWebBrowser2(pDisp);
 CHTMLCodeDlg HTMLCodeDlg;
 if(pWebBrowser2){
  CComQIPtr<IDispatch> pqiDisp;
  pWebBrowser2->get_Document(&pqiDisp);
  HTMLCodeDlg.m_pdocument=pqiDisp;
 }
 HTMLCodeDlg.DoModal();
}
BOOL CHTMLCodeDlg::OnInitDialog()
{
 CDialog::OnInitDialog();
 USES_CONVERSION;
 if (m_pdocument){
  CComQIPtr<IHTMLElement> pBody;
  HRESULT hr = m_pdocument->get_body(&pBody);
  if (FAILED(hr))
   return FALSE;
  CComBSTR bstrHTMLText;
  hr = pBody->get_outerHTML(&bstrHTMLText);
  if (FAILED(hr))
   return FALSE;
  // Convert the text from Unicode to ANSI
  m_strText=OLE2T(bstrHTMLText);
 }

 UpdateData(FALSE);
 return TRUE;  // return TRUE unless you set the focus to a control
               // EXCEPTION: OCX Property Pages should return FALSE
}
void CHTMLCodeDlg::OnApply()
{
 if(!UpdateData())return;
 USES_CONVERSION;
 if (m_pdocument){
  CComQIPtr<IHTMLElement> pBody;
  HRESULT hr = m_pdocument->get_body(&pBody);
  if (FAILED(hr))
   return ;
  CComBSTR bstrHTMLText((LPCTSTR)m_strText);
  pBody->put_innerHTML(bstrHTMLText);
  // Convert the text from Unicode to ANSI
 }
 OnOK();
}

see Programming and Reusing the Browser Overviews and Tutorials
in Platform SDK
Qjiangsheng和masterz等高手请进!有关webbrowser控件和xml 
T我在CDhtmlDialog中载入一个xml文件,请问我有没有办法通过某种方法修改这个xml?并能在ie控件中响应这个修改?
A改MFCIE示例的mfcieVw.cpp
#include "stdafx.h"
#include "mfcie.h"
#include "MainFrm.h"

#include "mfcieDoc.h"
#include "mfcieVw.h"

#pragma warning(disable : 4192)
#pragma warning(disable : 4049)
#pragma warning(disable : 4146)
#import <mshtml.tlb>
#import <msxml4.dll>
#pragma warning(default: 4192)
#pragma warning(default: 4049)
#pragma warning(default: 4146)
// Include Microsoft HIML definitions...

#include <dispex.h>

//You may derive a class from CComModule and use it if you want to override
//something, but do not change the name of _Module
#include <atlbase.h>//for atlcom.h
extern CComModule _Module;//for atlbase.h
#include <atlcom.h>//for OLE2T

……
END_MESSAGE_MAP()

BEGIN_EVENTSINK_MAP(CMfcieView, CHtmlView)
 ON_EVENT(CMfcieView, AFX_IDW_PANE_FIRST, 259 /* DocumentComplete */, DocumentComplete, VTS_DISPATCH VTS_PVARIANT)
END_EVENTSINK_MAP()

/
// CMfcieView construction/destruction

……
//END OF MFC MEMORY LEAK BUG FIX

void CMfcieView::DocumentComplete(LPDISPATCH pDisp, VARIANT* URL)
{
 ASSERT(V_VT(URL) == VT_BSTR);
 IDispatchPtr   spDisp;
 HRESULT         hr;

   hr = m_pBrowserApp->QueryInterface(IID_IDispatch, (void**) &spDisp);
   // Is the IDispatch* passed to us for the top-level window ?
   if (pDisp == spDisp)
   {
   MSHTML::IHTMLDocument2Ptr spDoc;

      // Get the active document
      spDoc = GetHtmlDocument();
      if ( spDoc )
      {
      MSHTML::IHTMLWindow2Ptr spWin;

         // Get the top-level window
         spDisp = spDoc->Script;
         spWin = spDisp;
         if ( spWin )
         {
            // Get the document
            spDoc = spWin->document;
            if ( spDoc )
            {
            IDispatchExPtr spDispEx;

               // Get the document's IDispatchEx
               spDoc->QueryInterface( IID_IDispatchEx,
                                      (void**)&spDispEx );
               if ( spDispEx )
               {
               _bstr_t   bstrName("XMLDocument");
               DISPID dispid;

                  // Get the XMLDocument expando property
                  spDispEx->GetDispID( bstrName,
                                       fdexNameCaseSensitive,
                                       &dispid );
                  if ( SUCCEEDED(hr) && dispid != DISPID_UNKNOWN )
                  {
                  VARIANT var;
                  DISPPARAMS dpNoArgs = {NULL, NULL, 0, 0};

                     // Get the XMLDocument value
                     hr = spDispEx->Invoke( dispid,
                                       IID_NULL,
                                       LOCALE_USER_DEFAULT,
                                       DISPATCH_PROPERTYGET,
                                       &dpNoArgs,
                                       &var,
                                       NULL,
                                       NULL );
                     if ( SUCCEEDED(hr) && var.vt == VT_DISPATCH )
                     {
                     MSXML2::IXMLDOMDocument* pXMLDoc=NULL;

                        // Get the IXMLDOMDocument interface
                        var.pdispVal->QueryInterface(
                                       IID_IXMLDOMDocument,
                                       (void**)&pXMLDoc );
                        VariantClear( &var );
                        if ( pXMLDoc )
                        {
                        // Get the root element
                        MSXML2::IXMLDOMElement* pXMLElem=NULL;

                           pXMLDoc->get_documentElement( &pXMLElem );
                           if ( pXMLElem )
                           {
                           BSTR bstr;
                           USES_CONVERSION;

                              // Get/display the tag name
                              pXMLElem->get_tagName( &bstr );
                              AfxMessageBox( OLE2T(bstr) );
                              pXMLElem->Release();
                           }
                           pXMLDoc->Release();
                        }
                     }
                  }
               }
            }
         }
      }
   }
}
//end new code
QWebBrowser发生了NewWindow2消息,如何让它不产生新的窗口,而在原来的窗口中显示新的页面。 
T如题,对于帮助者致以真心的谢意。
如果有必要,我自己会UP。
混分的不要企图在这里混,我不会给的。
A你不会在NewWindow的时候做个标记,在BeforeNavigate的时候检察这个标记?
set ppDisp to the existing webbrowser object will result page to be opened in the same window
Knowledge Base 

BUG: Using NewWindow or NewWindow2 to Always Navigate in the Same Window Fails in Some Instances
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;
 }
}
 
Q从IHTMLDocument2到IWebBrowser2 
T现在有一个有效的IHTMLDocument2指针,请问怎样才能得到包含它的IWebBrowser2指针?
ACComQIPtr<IServiceProvider> isp = pIHTMLDocument2;

This does a QueryInterface on the document for IServiceProvider. Once you have it, you can get the browser like so.

CComQIPtr<IWebBrowser2> iwb2;
isp->QueryService(IID_IWebBrowserApp,
    IID_IWebBrowser2, (void**)&iwb2);
QWebBrowser 控件能不能放在一个对话框程序中使用?
T我用MFC APPWIZARD (exe)创建了一个DIALOG BASED程序
然后在假如 vc 自带的WebBrowser Control 这个控件

我在对话框中添加了一个文本框和一个按钮,我想在按下按钮后
得到指定网页的内容!

程序段如下:
m_Browser 为用WebBrowser Control 的一个对象
我在InitDialog()中用m_Browser.Create()把他初始化

void CHtml03Dlg::OnShow()
{
    m_URL = "http://devserver/tryocx01/try1.htm"; //指定的网址

    COleVariant varEmpty; // Default is VT_EMPTY
    CComPtr<IDispatch> m_IDsp;

    //连接指定的URL并获得文本指针
    m_Browser.Navigate(m_URL, &varEmpty, &varEmpty, &varEmpty, &varEmpty);
    m_IDsp = m_Browser.GetDocument();
   
    CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> m_pHtmlDocument;
    m_pHtmlDocument = m_IDsp; 
   
    if(m_pHtmlDocument == NULL)  //没有获得对应的对象,返回
        return;
   
    CComPtr<IHTMLElement> htmlbody;
        HRESULT hr;
 
    BSTR bstrBodyText;    //保存<body>....</body>之间的文本
    hr = m_pHtmlDocument->get_body(&htmlbody);
       if(FAILED(hr))
 return;
   
    if(htmlbody)
    {
         //得到<bode>...</body>之间的文本内容
 hr=htmlbody->get_outerHTML(&bstrBodyText);
            if(FAILED(hr))
          return;
 
        //convert the text from unicode to ansi
        //并把他付给文本框
         USES_CONVERSION;
   LPTSTR psz = new TCHAR[SysStringLen(bstrBodyText)];
   lstrcpy(psz, OLE2T(bstrBodyText));
 m_Contents = psz;   //m_Contents 是文本框对象,CString类型
         delete psz;
 UpdateData(false);
     }
}

当我调式上面的程序的时候,
m_Browser.Navigate(m_URL, &varEmpty, &varEmpty, &varEmpty, &varEmpty);
m_IDsp = m_Browser.GetDocument();
这两个语句得到的m_IDsp总是为NULL
我想是因为Navigate()是进行连接,
然后开始下载html文本,这时html document这个对象还没有产生
GetDocuemnt()当然就得不到所要的html document对象了

所以我又在调试完第一个语句
m_Browser.Navigate(m_URL, &varEmpty, &varEmpty, &varEmpty, &varEmpty);
等了几分钟后才执行
m_IDsp = m_Browser.GetDocument();
这时得到的m_IDsp就得到了文本对象的指针。

我想问的就是在这个程序中有没有可以判断文本对象是否
已经产生的函数?怎么实现?
我记得IDispatch::Invoke()接口就可以对对应的信息进行
处理,他处理的消息就有:
DISPID_DOCUMENTCOMPLETE
DISPID_DOWNLOADCOMPLETE

在我这个程序中能不能直接用WebBrowser Control里面的一些函数对
html document对象是否已经产生进行判断呢?


呵呵,各位大虾不好意思
小弟表达能力不好,罗嗦的写了这么多
还望给为抽空指点一下!
万分感谢!
AThe WebBrowser Control fires the DWebBrowserEvents2::DocumentComplete event when the document has completely loaded and the READYSTATE property has changed to READYSTATE_COMPLETE. Here are some important points regarding the firing of this event.

In pages with no frames, this event fires once after loading is complete.
In pages where multiple frames are loaded, this event fires for each frame where the DWebBrowserEvents2::DownloadBegin event has fired.
This event's pDisp parameter is the same as the IDispatch interface pointer of the frame in which this event fires.
In the loading process, the highest level frame (which is not necessarily the top-level frame) fires the final DWebBrowserEvents2::DocumentComplete event. At this time, the pDisp parameter will be the same as the IDispatch interface pointer of the highest level frame.

For specific code examples using Microsoft&reg; Visual Basic&reg; and Microsoft Foundation Classes (MFC), see Knowledge Base article Q180366 .

Currently, the DWebBrowserEvents2::DocumentComplete does not fire when the IWebBrowser2::Visible property of the WebBrowser Control is set to false. For more information, see Knowledge Base Article Q259935 .
Q如何动态修改浏览器中网页代码? 
T主要是动态修改网页中的javascript脚本。
我想实现用webbrowser2浏览网页。
对网页中的alert()等javasctipt函数禁止它运行。
用MSHTML如何实现。
应该在哪个事件(onDownloadcomplete , onBeforenavigage, ondocumentcomplete,ondocumentbegin...)里面添加代码?
谢谢。
A
http://www.csdn.net/develop/read_article.asp?id=19627
控制下载和执行
DLCTL_NO_SCRIPTS 和 DLCTL_NO_JAVA: 脚本和Java小程序将不被运行。
Q如何得到IFrame中的元素,快被折磨死了 
T我现在已经实现了用contentWindow获得IFrame中的元素
如果嵌入的iframe页面是普通页面,返回iframe 的 document正常
但是对某些嵌入的iframe页面(一般该iframe页面包含有javascript或者iframe),则无法取得iframe的document,返回iframe 的 document是null
这样我就无法获得iframe内的元素
请高手指教。谢谢
A你是什么时候去访问iframe的document的?检查一下IHTMLFrameBase2::readyState

换用IWebBrowser2看看
// Get the IDispatch of the document
LPDISPATCH lpDisp = NULL;
lpDisp = m_webBrowser.GetDocument();

if (lpDisp)
{
   IOleContainer* pContainer;

   // Get the container
   HRESULT hr = lpDisp->QueryInterface(IID_IOleContainer,
                                       (void**)&pContainer);
   lpDisp->Release();

   if (FAILED(hr))
      return hr;

   IEnumUnknown* pEnumerator;

   // Get an enumerator for the frames
   hr = pContainer->EnumObjects(OLECONTF_EMBEDDINGS, &pEnumerator);
   pContainer->Release();

   if (FAILED(hr))
      return hr;

   IUnknown* pUnk;
   ULONG uFetched;

   // Enumerate all the frames
   for (UINT i = 0; S_OK == pEnumerator->Next(1, &pUnk, &uFetched); i++)
   {
      // QI for IWebBrowser here to see if we have an embedded browser
      IWebBrowser2* pBrowser;

      hr = pUnk->QueryInterface(IID_IWebBrowser2, (void**)&pBrowser);
      pUnk->Release();

      if (SUCCEEDED(hr))
      {
         hr = pBrowser->get_document(&pDocument2);
         ……
         pDocument2->Release();
         pBrowser->Release();
      }
   }

   pEnumerator->Release();
}
Q关于OnBeforeNavigate2运行后无相应的问题
T
在 我的应用程序里面,调用网页时用Navigate2启动网页,其后会转到OnBeforeNavigate2中,但是有时(偶尔不是经常),到了 OnBeforeNavigate2后,就再无消息转出了,即OnNavigateComplete2无法进入,但是 OnNavigateComplete2对我的应用是很重要的,下一步动作的触发就靠它了,所以现在真个应用就停在那了,有那位大侠知道解决办法吗??
谢谢!
ADWebBrowserEvents::NavigateComplete和DWebBrowserEvents2::NavigateComplete2 只在成功浏览到一个URL才会触发。

你可以捕获DownloadComplete(如果下栽没有被取消)或者DocumentComplete(只应用于在浏览器中直接打开的文档类型的下载)

看看调试窗口的输出
Navigate的确有内存泄漏

http://www.csdn.net/Develop/read_article.asp?id=21702
Q谁能解释一下CWebBrowser2的OnBeforeNavigate2 
T
谁能解释一下CWebBrowser2的

OnBeforeNavigate2(LPDISPATCH pDisp, VARIANT FAR* URL, VARIANT FAR* Flags, VARIANT FAR* TargetFrameName, VARIANT FAR* PostData, VARIANT FAR* Headers, BOOL FAR* Cancel)


其中PostData的内容是不是?a=1&b=2之类的,怎么得到其中的内容,谢了先!
A
In Visual C++

#include "Shlwapi.h"
STDMETHODIMP CWebOCWindow::BeforeNavigate2(IDispatch *pDisp, VARIANT *URL,
 VARIANT *Flags, VARIANT *TargetFrameName,
 VARIANT *PostData, VARIANT *Headers,
 VARIANT_BOOL *Cancel)
{
         if (PostData != NULL && PostData->vt == (VT_VARIANT|VT_BYREF) && PostData->pvarVal->vt != VT_EMPTY )
 {
 
  char *szTemp = NULL, *szPostData = NULL;
  long plLbound, plUbound;
 
  SAFEARRAY *parrTemp = PostData -> pvarVal->parray;
  SafeArrayAccessData(parrTemp , (void HUGEP **) &szTemp);
 
  SafeArrayGetLBound(parrTemp , 1, &plLbound);
  SafeArrayGetUBound(parrTemp , 1, &plUbound);
 
  szPostData = new char[plUbound - plLbound + 2];
          StrCpyN(szPostData, szTemp, plUbound - plLbound + 1);
  szPostData[plUbound-plLbound] = '/0';
  SafeArrayUnaccessData(parrTemp);
    
  MessageBox(szPostData);
 
  delete[] szPostData;
 }
 return S_OK;
}

Qjiangsheng(蒋晟) 你能再解释一下CWebBrowser2的参数问题吗?这140分诚表谢意!
T
你能再解释一下CWebBrowser2的

OnBeforeNavigate2(LPDISPATCH pDisp, VARIANT FAR* URL, VARIANT FAR* Flags, VARIANT FAR* TargetFrameName, VARIANT FAR* PostData, VARIANT FAR* Headers, BOOL FAR* Cancel)

中其它的参数是怎么操作吗?
比如说得到URL,把Cancel置false 等
A
1
void CHtmlView::BeforeNavigate2(LPDISPATCH /* pDisp */, VARIANT* URL,
         VARIANT* Flags, VARIANT* TargetFrameName,
         VARIANT* PostData, VARIANT* Headers, BOOL* Cancel)
 {
     ASSERT(V_VT(URL) == VT_BSTR);
     ASSERT(V_VT(TargetFrameName) == VT_BSTR);
     ASSERT(V_VT(PostData) == (VT_VARIANT | VT_BYREF));
     ASSERT(V_VT(Headers) == VT_BSTR);
     ASSERT(Cancel != NULL);
 
     USES_CONVERSION;
 
     VARIANT* vtPostedData = V_VARIANTREF(PostData);
     CByteArray array;
     if (V_VT(vtPostedData) & VT_ARRAY)
     {
         // must be a vector of bytes
         ASSERT(vtPostedData->parray->cDims == 1 &&
                vtPostedData->parray->cbElements == 1);
 
         vtPostedData->vt |= VT_UI1;
         COleSafeArray safe(vtPostedData);
 
         DWORD dwSize = safe.GetOneDimSize();
         LPVOID pVoid;
         safe.AccessData(&pVoid);
 
         array.SetSize(dwSize);
         LPBYTE lpByte = array.GetData();
 
         memcpy(lpByte, pVoid, dwSize);
         safe.UnaccessData();
     }
     // make real parameters out of the notification
 
     CString strTargetFrameName(V_BSTR(TargetFrameName));
     CString strURL = V_BSTR(URL);
     CString strHeaders = V_BSTR(Headers);
     DWORD nFlags = V_I4(Flags);
 
     // notify the user's class
     OnBeforeNavigate2(strURL, nFlags, strTargetFrameName,
         array, strHeaders, Cancel);
 }
 2
*Cancel=TRUE;
Q还是CWebBrowser2的问题,麻烦各位了,特别是jiangsheng(蒋晟),送上150分先! 
T
在OnBeforeNavigate2(LPDISPATCH pDisp, VARIANT FAR* URL, VARIANT FAR* Flags, VARIANT FAR* TargetFrameName, VARIANT FAR* PostData, VARIANT FAR* Headers, BOOL FAR* Cancel)

我怎样把我的数据,比如"T1=a&T2=b",放到 PostData 里???
A
建立一个临时的COleVariant对象保存字符串,然后复制它的值到需要的位置。
VariantCopy
This function frees the destination variant and makes a copy of the source variant.

HRESULT VariantCopy(
VARIANTARG FAR *pvargDest,
VARIANTARG FAR *pvargSrc );
Parameters
pvargDest
Pointer to the VARIANTARG to receive the copy.
pvargSrc
Pointer to the VARIANTARG to be copied.
Return Values
One of the values obtained from the returned HRESULT and described in the following table is returned.


Value Description
S_OK Success.
DISP_E_ARRAYISLOCKED The variant contains an array that is locked.
DISP_E_BADVARTYPE The source and destination have an invalid variant type (usually uninitialized).
E_OUTOFMEMORY Memory could not be allocated for the copy.
E_INVALIDARG One of the arguments is invalid.



Remarks
Passing into this function any invalid and, under some circumstances, NULL pointers will result in unexpected termination of the application.

First, free any memory that is owned by pvargDest, such as VariantClear (pvargDest must point to a valid initialized variant, and not simply to an uninitialized memory location). Then pvargDest receives an exact copy of the contents of pvargSrc.

If pvargSrc is a VT_BSTR, a copy of the string is made. If pvargSrc is a VT_ARRAY, the entire array is copied. If pvargSrc is a VT_DISPATCH or VT_UNKNOWN, AddRef is called to increment the object’s reference count.



在OnBeforeNavigate2(LPDISPATCH pDisp, VARIANT FAR* URL, VARIANT FAR* Flags, VARIANT FAR* TargetFrameName, VARIANT FAR* PostData, VARIANT FAR* Headers, BOOL FAR* Cancel)函数中

VARIANT *PostData;??
你重新申明了一个和参数同名的变量,当然会出错了。
把VARIANT *PostData;这一句删掉!
Qjiangsheng(蒋晟)请进
T
前 天偶然发现m_Web.ExecWB(OLECMDID_SAVEAS,OLECMDEXECOPT_PROMPTUSER,& va_inVal,&va_outVal); 能够调出ie的对话框,而且还可以保存为*.mht格式,但试尽了参数,也没法使对话框不被弹出而保存该文件为*.mht,请问各位有什么高招?

A
IDM_SAVEAS Command ID

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

Saves the current Web page to a file.

C++ Information

Command group CGID_MSHTML (defined in mshtmhst.h) 
Symbolic constant IDM_SAVEAS 
User interface Optional. This command displays a dialogue box if the nCmdExecOpt argument of IOleCommandTarget::Exec  is set to MSOCMDEXECOPT_DODEFAULT, MSOCMDEXECOPT_PROMPTUSER, or NULL. It does not display a dialogue box if the argument is set to MSOCMDEXECOPT_DONTPROMPTUSER.
IOleCommandTarget::Exec parameters pvaIn VARIANT of type VT_BSTR that specifies the path and file name of the file to which to save the Web page. When the path contains more than one folder name, separate the folder names with two backward slashes (//).
pvaOut Set to NULL.
 
Header file mshtmcid.h 
Applies to IHTMLDocument2::execCommand, IHTMLDocument2::queryCommandEnabled, IHTMLDocument2::queryCommandIndeterm, IHTMLDocument2::queryCommandState, IHTMLDocument2::queryCommandSupported, IHTMLDocument2::queryCommandValue, emit_hlink;, IOleCommandTarget::QueryStatus . 

保存到一个.mht文件,并且设置DONTPROMPTUSER看看


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.mht";
 pFile->Save(file,TRUE);
       }
   }

Q我用WebBrowser来显示对话框的网页文件,用了m_Browser.ModifyStyle(WS_HSCROLL&WS_VSCROLL,0);好像不起作用呀,还是会出现滚动条
T
http://person.zj.cninfo.net/~lhb/HtmlTest/HtmlTest.zip

我用WebBrowser来显示对话框的网页文件,用了m_Browser.ModifyStyle(WS_HSCROLL&WS_VSCROLL,0);好像不起作用呀,还是会出现滚动条,你看看怎么回事,谢谢?


A
IHTMLBodyElement::scroll Property

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

This is preliminary documentation and is subject to change.
Sets or retrieves a value that indicates whether the scroll bars are turned on or off.

Syntax

HRESULT IHTMLBodyElement::get_scroll(BSTR *p);HRESULT IHTMLBodyElement::put_scroll(BSTR v);
Parameters

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

yes Default. Scroll bars are turned on.
no Scroll bars are turned off.
auto Scroll bars are shown when the page content exceeds the client area.

Return Value

Returns S_OK if successful, or an error value otherwise.
See Also

CSS Enhancements in Internet Explorer 6 Public Preview

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

&copy; 2001 Microsoft Corporation. All rights reserved. Terms of use.
Qjiangsheng老先生,请问如何在程序中修改WebBrowser的语言设置?
T我是用VC写的一个程序,用了CHtmlView,想在程序中修改语言设置,请问如何做?
A
IHTMLDocument2::charset Property

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

Sets or retrieves the character set used to encode the object.

Syntax

HRESULT IHTMLDocument2::get_charset(BSTR *p);HRESULT IHTMLDocument2::put_charset(BSTR v);

CHtmlView::GetHtmlDocument
LPDISPATCH GetHtmlDocument( ) const;
看来以后要定时搜索jiangsheng了,不然找人的贴都看不到

还有,偶刚刚大学毕业几年,不要叫偶老先生比较好吧


How to Enumerate Code Pages and Locales

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

MLang provides two enumeration objects that can be used to retrieve the code pages and locales that are recognized by the system from the MIME database.

To use this functionality to enable end users to invoke their preference:


Make sure the Component Object Library has been initialized.
Before you can use any of the functionality provided by MLang, you must first initialize the Component Object Library through a call to CoInitialize. Every call to CoInitialize must be accompanied by a call to CoUninitialize when the application terminates. CoUninitialize ensures that the application does not quit until it has received all of its pending messages.

Obtain a pointer to an IMultiLanguage interface.
If no MultiLanguage object exists, this can be accomplished through a call to CoCreateInstance, using CLSID_CMultiLanguage and IID_IMultiLanguage for the first and fourth parameters, respectively. If a MultiLanguage object already exists, this can be accomplished by calling QueryInterface through the current MultiLanguage object interface.

Obtain an interface to an enumerator object through a call to the IMultiLanguage::EnumCodePages or IMultiLanguage::EnumRfc1766 method.
If you are enumerating code pages, you need to decide which of the MIMECONTF constants you want to use as the flag for the call. These constants specify the uses of a code page and can be used to tailor the list of code pages returned to suit your needs.

Call the Next method of the enumeration interface you have obtained.
This method retrieves an array of MIMECPINFO or RFC1766INFO structures, depending on whether you are enumerating code pages or locales, respectively. You must allocate memory for these arrays by using the task allocator. The following code sample demonstrates how to do this for code pages. It should be noted, however, that there is no function for locales that corresponds to IMultiLanguage::GetNumberOfCodePageInfo.

Hide Example

// IMultiLanguage *pMultiLanguage;
// IEnumCodePage *pEnumCodePage;

UINT cnum = 0;
PMIMECPINFO pcpInfo;
long ccpInfo;

pMultiLanguage->GetNumberOfCodePageInfo(&cnum);

pcpInfo = (PMIMECPINFO)CoTaskMemAlloc(sizeof(MIMECPINFO)*cnum);

hr = pEnumCodePage->Next(cnum, pcpInfo, &ccpInfo);

if(SUCCEEDED)hr))
{
    // Use the MIMECPINFO structures returned to allow the
    // user to select his or her own preferences.
}
Dynamically add the code pages or locales to a menu or list box.
The MIMECPINFO and RFC1766INFO structures contain a description of the code page or locale in a wide-character string. The MLang Conversion object can be used to convert these strings to the proper code page for output (in this case, 1252). The following code shows how to add the code pages in an array of MIMECPINFO structures to a dynamically created pop-up menu.

Hide Example

// IMultiLanguage *pMultiLanguage;
// pcpInfo - pointer to an array of MIMECPINFO structures.
// ccpInfo - number of structures in pcpInfo.

HMENU hmenu, hsubmenu;
static HMENU hpopup;
IMLangConvertCharset* pMLCC;
char pszDescription[100];
UINT SrcLen;
UINT DstLen;

hmenu = GetMenu(hwnd);
hsubmenu = GetSubMenu(hmenu, 0);
hpopup = CreatePopupMenu();

pMultiLanguage->CreateConvertCharset(1200, 1252, 0, &pMLCC);

for(int i = 0; i < ccpInfo; i++)
{
    DstLen = 99;
    size_t cchMax = MAX_MIMECP_NAME;
    size_t cchLength;
    HRESULT hr = StringCchLengthW(pcpInfo[i].wszDescription, cchMax, &cchLength);

    if(SUCCEEDED(hr))
    {
        SrcLen = cchLength;

        pMLCC->DoConversionFromUnicode(pcpInfo[i].wszDescription,
           &SrcLen, pszDescription, &DstLen);
        pszDescription[DstLen] = '/0';

        AppendMenu(hpopup, MF_ENABLED, IDM_CP + i, pszDescription);
     }
     else
     {
        //  TODO: Insert error handling code here.
     }
}

AppendMenu(hsubmenu, MF_POPUP, UINT (hpopup), "&Code Pages");
Remember to reallocate the memory for the arrays, release the interfaces, and uninitialize the Component Object Library before your program terminates.
The memory for the arrays must be reallocated by using the task allocator. Although the IEnumCodePage, IEnumRfc1766, and IMLangConvertCharset interfaces are obtained through the IMultiLanguage interface, all must be released individually.


Related Topics

MLang Reference
Code Page Enumeration Object
Locale Enumeration Object
QWebBrowser/CHtmlView: how to disable "http-quive=refresh" feature?
T
在浏览页面时,错误的<META>可能导致ie 5.0崩溃。代码如下:
<META HTTP-EQUIV="REFRESH" CONTENT="0; URL=xxx">
当URL指向的xxx为不存在的本地文件时,ie连续报警直至崩溃。
但是在资源管理器中预览时并不报警。
请问:
1.此问题在ie高版本中是否存在?
2.如何禁止ie自动执行refresh?
A
IHTMLMetaElement::httpEquiv Property

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

Sets or retrieves information used to bind the META tag's IHTMLMetaElement::content to an HTTP response header.

Syntax

HRESULT IHTMLMetaElement::get_httpEquiv(BSTR* p);
HRESULT IHTMLMetaElement::put_httpEquiv(BSTR v);


Q浏览器编程中:怎忙获得多框架网页的一个框架内的页面的标题?
T我在IHTMLFrameSetElement等接口好像都没找到这样的函数。。。请指点
AIHTMLFrameBase2
Query IHtmlWindow2 Interface for early version of IE
Q求救:如何使CWebBrowser2不是从URL或文件中读取内容,而是通过数据流传递内容。在线等待。
T如何使CWebBrowser2不是从URL或文件中读取内容,而是通过数据流传递内容。不胜感激!
A
>如果数据含有指向其它的URL或图片怎么办?
你通过HTML格式的数据流传递内容之后浏览器肯定还是要去下载Flash,控件,图片什么的,除非你用MHT格式的数据流
相关链接:
http://www.csdn.net/Expert/topicview.asp?id=351580
http://www.csdn.net/Expert/topicview.asp?id=786376
http://www.csdn.net/Expert/topicview.asp?id=783799
http://www.csdn.net/Expert/topicview.asp?id=934618

http://www.csdn.net/Expert/topicview.asp?id=351580
see IMark****

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);
 
 
 //这里把创建文档的操作换成IWebbrowser2的GetDocument就可以
 IHTMLDocument2 *pDoc1 = NULL;
 

 CoCreateInstance(CLSID_HTMLDocument,
  NULL,
  CLSCTX_INPROC_SERVER,
  IID_IHTMLDocument2,
  (LPVOID *) &pDoc1);
 
 if (pDoc1)
 {
  IPersistStreamInit *pPersist = NULL;
 
  pDoc1->QueryInterface(IID_IPersistStreamInit,
   (LPVOID *) &pPersist);
 
  if (pPersist)
  {
   IMarkupServices *pMS = NULL;
  
   pPersist->InitNew();
   pPersist->Release();
  
   pDoc1->QueryInterface(IID_IMarkupServices,
    (LPVOID *) &pMS);
  
   if (pMS)
   {
    IMarkupContainer *pMC = NULL;
    IMarkupPointer *pMkStart = NULL;
    IMarkupPointer *pMkFinish = NULL;
   
    pMS->CreateMarkupPointer(&pMkStart);
    pMS->CreateMarkupPointer(&pMkFinish);
   
    pMS->ParseString(szHTML,
     0,
     &pMC,
     pMkStart,
     pMkFinish);
   
    if (pMC)
    {
     IHTMLDocument3 *pDoc = NULL;
    
     IHTMLElementCollection  * pAllElem = NULL; 
     IHTMLElement *pElem = NULL; 
     IHTMLTable* pTable = NULL;
     IHTMLElementCollection* pCells = NULL;  //link's text
     IHTMLElementCollection* pTableCol = NULL;  //tag =>"table"
     long p;
     BSTR bstrSrc,tag;
     // BSTR tag = "TABLE";
     VARIANT name,index;
     name.vt = VT_I4;
     index.vt = VT_I4;
     //name.bstrVal = "TABLE";
     COleVariant tags(_T("a"));
     //get IHTMLDocument2's pointer
     pMC->QueryInterface(IID_IHTMLDocument3,
      (LPVOID *) &pDoc);
    
    
     if(pDoc!=NULL)
     {
 
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值