VB中 Image或PictureBox 显示网络图片问题

VB中Image或PictureBox显示网络图片PrivateDeclareFunctionOleLoadPicturePathLib"oleaut32.dll"(By... VB中 Image或PictureBox 显示网络图片

Private Declare Function OleLoadPicturePath Lib "oleaut32.dll" (ByVal szURLorPath As Long, ByVal punkCaller As Long, ByVal dwReserved As Long, ByVal clrReserved As OLE_COLOR, ByRef riid As TGUID, ByRef ppvRet As IPicture) As Long

Private Type TGUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type

'加载函数
Public Function LoadPicture(ByVal strFileName As String) As Picture
Dim IID As TGUID
With IID
.Data1 = &H7BF80980
.Data2 = &HBF32
.Data3 = &H101A
.Data4(0) = &H8B
.Data4(1) = &HBB
.Data4(2) = &H0
.Data4(3) = &HAA
.Data4(4) = &H0
.Data4(5) = &H30
.Data4(6) = &HC
.Data4(7) = &HAB
End With

On Error GoTo LocalErr

OleLoadPicturePath StrPtr(strFileName), 0&, 0&, 0&, IID, LoadPicture
Exit Function
LocalErr:
Set LoadPicture = VB.LoadPicture(strFileName)
Err.Clear
End Function

Private Sub Command1_Click()

Set Image1.Picture = LoadPicture("http://img.baidu.com/img/logo-zhidao.gif")
End Sub

这里的代码是可以的,但是有时候加载得慢会让程序定住,不能进行任何操作,要加载完毕才能继续操作。

好象DoEvents这个不行哦。。
有什么方法可以在加载的同时,也可以进行其他操作呢??

请教~~请教~~
还是会卡着的哦,还有其他方法么?
展开
 我来答
yfdyh000f99834
2008-02-26 · TA获得超过5033个赞
知道大有可为答主
回答量:1578
采纳率:0%
帮助的人:2303万
展开全部
Private Declare Function OleLoadPicturePath Lib "oleaut32.dll" (ByVal szURLorPath As Long, ByVal punkCaller As Long, ByVal dwReserved As Long, ByVal clrReserved As OLE_COLOR, ByRef riid As TGUID, ByRef ppvRet As IPicture) As Long

Private Type TGUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type

'加载函数
Public Function LoadPicture(ByVal strFileName As String) As Picture
Dim IID As TGUID
With IID
.Data1 = &H7BF80980
.Data2 = &HBF32
.Data3 = &H101A
.Data4(0) = &H8B
.Data4(1) = &HBB
.Data4(2) = &H0
.Data4(3) = &HAA
.Data4(4) = &H0
.Data4(5) = &H30
.Data4(6) = &HC
.Data4(7) = &HAB
DoEvents
End With

On Error GoTo LocalErr

OleLoadPicturePath StrPtr(strFileName), 0&, 0&, 0&, IID, LoadPicture
Exit Function
LocalErr:
Set LoadPicture = VB.LoadPicture(strFileName)
Err.Clear
End Function

Private Sub Command1_Click()
Set Image1.Picture = LoadPicture("https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/img/logo-zhidao.gif")
End Sub

我这里很快,不知道你加载的是什么图片。。。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
lyglay
2008-02-26 · TA获得超过1137个赞
知道大有可为答主
回答量:975
采纳率:0%
帮助的人:0
展开全部
试试这个

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 Long

Private Sub Command1_Click()
LoadPictureFromURL Image1, "http://blog.txtbbs.com/attachments/2007/07/31347_200707232052203.jpg"
Image1.Refresh
End Sub

Sub LoadPictureFromURL(PicCtrl As Control, URL As String)
URLDownloadToFile 0&, URL, "c:\tmppp", 0&, 0&
Do Until Len(Dir("c:\tmppp"))
DoEvents
Loop
PicCtrl.Picture = LoadPicture("c:\tmppp")
Kill "c:\tmppp"
End Sub
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式