想SaveAs一个网页:
在.h中:
        IHTMLDocument2* m_pMSHTML;在.cpp中:
        if (m_pMSHTML != NULL ) {
                VARIANT_BOOL bDisp;
                VARIANT var;
                VARIANT_BOOL bRet;                bDisp = VARIANT_FALSE;
                var.vt = VT_BSTR;
                var.bstrVal = _bstr_t("e:\\test\\test.htm");
                bRet = VARIANT_FALSE;                m_pMSHTML->execCommand( _bstr_t("SaveAs"), bDisp, var, &bRet );                return;
        }在MSDN的帮助中关于参数的说明:User interface:
Optional. This command displays a dialogue box if the bUserInterface
argument of execCommand is set to true or omitted. It does not display
a dialogue box if the argument is set to false or null and the vValue
parameter is present (even if it's null).execCommand vValue:
Optional. String 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 (\\).奇怪的是上面代码设置的产数已经满足要求了, 为什么每次执行到这里
还是要显示SaveAs的对话框呢?

解决方案 »

  1.   

    http://www.csdn.net/Develop/Article/18/18465.shtm
      

  2.   

    Save the Last GIF for Me
    Dear Web Team:I am using VB6 [Visual Basic® 6.0] on a Windows® 2000 Advanced Server PC to create an application hosting the WebBrowser control to AUTOMATICALLY select and save to the local hard disk certain HTM, JPG, and GIF files in the document window. I can use the DHTML method:document.execCommand("saveas",false,path&filename) To save the main HTML page to disk, but despite using the "False" argument, an unwanted dialog box is always displayed. This of course demands user input, which I don't know how to provide by program, and in any case does not save any embedded images. I would like to use a similar command to save selected JPGs and GIFs embedded in the document to hard disk, without requesting them again from the server, but I can't find the right syntax. Could you advise the best way to save these files efficiently and automatically, without any user intervention? Many thanks,
    Donald CruttendenThe Web Team Replies:Boy, security is a double-edged sword, isn't it? Though the execCommand method can be used on images (via the controlRange object or IHTMLControlRange), as well as the document, the SaveAs command will ignore the showUI parameter and always prompt the user. This is, as you may have guessed, designed to prevent evil pages from saving 500,000 pictures of, let's say, our smiling faces to your hard drive without prompting you. However, it's going to prompt the user in this case too, even though you have only the best intentions (right?). As it turns out, the execCommand method is actually a wrapper of sorts for IOleCommandTarget::Exec() which also prompts the user when it's called on to save an item programmatically (via either OLECMDID_SAVE or OLECMDID_SAVEAS) as does another wrapper for this method IWebBrowser2::ExecWB. Now that we've eliminated practically every function on the site with 'save' in the description, is all hope lost? Far from it—we just need to call on our friend URLMON to save us. If we can't ask the WebBrowser control to save these items silently, we'll just have do it ourselves, and we're going to use an URLMON API, UrlDownloadToFile, to help. As described in Q244757 - HOWTO: Download a File Without Prompting, we can use this function to silently download a file to a specific location on a disk given only a URL. So to illustrate how this can be done, here's a quick Visual Basic sample that shows how to programmatically save all the images on the page without prompting the user. To test out this code, just start a new VB EXE project, add a WebBrowser control, name it wbMain, and then paste the following code into your form:Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
        "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal _
        szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As LongConst BASE_DIR = "C:\images\"Private Sub Form_Load()
        wbMain.Navigate "http://msdn.microsoft.com/ie"
    End SubPrivate Sub wbMain_DocumentComplete(ByVal pDisp As Object, URL As Variant)
        
        Dim collImages As IHTMLElementCollection
        Dim img As IHTMLImgElement
        Dim strFileName As String
        Dim strExtension As String
        Dim lResult As Long
        Dim i As Long
        Dim nAnomalies As Long
        
        Set collImages = pDisp.Document.getElementsByTagName("IMG")
        
        For i = 0 To collImages.length - 1
            Set img = collImages.Item(i)
            strFileName = Right(img.src, Len(img.src) - InStrRev(img.src, "/"))
            strExtension = LCase(Right(strFileName, Len(strFileName) - InStrRev(strFileName, ".")))
            If strExtension = "gif" Or strExtension = "jpg" Or strExtension = "jpeg" Then
                lResult = URLDownloadToFile(0, img.src, BASE_DIR & strFileName, 0, 0)
            Else
                ' The file may be dynamically generated or may have
                ' a file name without an extension.  We'll inspect
                ' the mimeType property as a last ditch effort and
                ' invent our own filename.
                If InStr(1, img.mimeType, "GIF", vbTextCompare) Then
                    lResult = URLDownloadToFile(0, img.src, BASE_DIR & "anomaly" & nAnomalies & ".gif", 0, 0)
                ElseIf InStr(1, img.mimeType, "JPG", vbTextCompare) Then
                    lResult = URLDownloadToFile(0, img.src, BASE_DIR & "anomaly" & nAnomalies & ".jpg", 0, 0)
                End If
            End If
            Set img = Nothing
        Next i
        Set collImages = Nothing
    End SubAs indicated by the last else clause, images generated dynamically by server-side code (ASP pages or ISAPI DLLs) could pose a problem from the filename perspective, but the mimeType property will rescue us in most cases.[The implementation of code to fetch INPUT TYPE=IMAGE elements is left as an exercise to the reader.]
      

  3.   

    不要用activex,还是如下:
    void OnSaveToFile() 
    {

    CFileDialog dlg(FALSE, NULL, NULL,
    OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
    NULL, NULL);
    if(dlg.DoModal()==IDCANCEL)
    return;
    _bstr_t path=dlg.GetPathName(); HRESULT hr;
    IWebBrowser2* piWeb = 0;
    IDispatch* piDisp = 0;
    IPersistFile* piPF = 0;
    IUnknown* piUnk = m_wndBrowser.GetControlUnknown();
    hr = piUnk->QueryInterface(IID_IWebBrowser2, (void**)&piWeb);
    if(FAILED(hr))
    {
    AfxMessageBox("QueryInterface for IWebBrowser2");
    return;
    }
    hr = piWeb->get_Document(&piDisp);
    if(SUCCEEDED(hr))
    {
    hr = piDisp->QueryInterface(IID_IPersistFile, (void**)&piPF);
    if(SUCCEEDED(hr))
    {
    piPF->Save(path, TRUE);
    piPF->Release();
    }
    piDisp->Release();
    }
    }