天天看点

VB 使用Webbrowser控件下载图片 源码

Private Sub webSky_DownloadComplete()

    On Error Resume Next

    WebSky.Silent = True

    Me.MousePointer = vbDefault

    Dim x, CtrlRange

    Dim sPath As String

    sPath = App.Path

    sPath = Left(sPath, InStr(sPath, vbNullChar) - 1)

    If Len(sPath) > 3 Then sPath = sPath & "/"

    If Trim(txtUser.Text) <> "" Then

        gstrFileName = sPath & Trim(txtUser.Text) & "Code.bmp"

    Else

        gstrFileName = sPath & "TempCode.bmp"

    End If

    For Each x In WebSky.Document.All

        If x.tagName = "IMG" Then

                WebSky.Stop

                Set CtrlRange = WebSky.Document.body.createControlRange()

                CtrlRange.Add (x)

                CtrlRange.execCommand ("Copy")

                SavePicture Clipboard.GetData, gstrFileName

                'getCodeForSky

            End If

        End If

    Next

End Sub