前端之家收集整理的这篇文章主要介绍了
VB利用PictureBox控件播放GIF动画,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
'改了一下,限定图像缩放到Picture1的大小
'在PictureBox控件中显示GIF动画(图片),凡有句柄hwnd的窗体控件均可以
Option Explicit
'调用运动图像播放类型库Quartz.dll,在c:\windows\system32目录下
Private pMC As FilgraphManager '定义pMC为FilgraphManager对象
Private pVW As IVideoWindow '定义pVW为IVideoWindow对象
'Public pVP As IMediaPosition
'Public pBV As IBasicVideo
'播放GIF动画
Private Sub Command1_Click()
On Error Resume Next
Set pMC = New FilgraphManager
pMC.Stop
'Set pVP = pMC
'pVP.StopTime = 0
pMC.RenderFile ""
On Error GoTo Lhandle
pMC.RenderFile "E:\offline.gif" '加载GIF动画,并在PictureBox中播放
'Set pVP = pMC
's = Str(pVP.Duration)
On Error Resume Next
Set pVW = pMC
pVW.WindowStyle = CLng(&H6000000)
'限定图像在Picture1的大小中
pVW.Left = 0: pVW.Top = 0
pVW.Width = Picture1.ScaleWidth
pVW.Height = Picture1.ScaleHeight
pVW.Owner = Picture1.hWnd '在Picture1中播放
pVW.MessageDrain = Picture1.hWnd '此行非常重要,用来定义图像的右键菜单所必须
pMC.Run '一直播放
Exit Sub
Lhandle:
MsgBox ("加载文件错误!")
End Sub
'停止播放GIF动画
Private Sub Command2_Click()
pMC.Stop
Set pVW = Nothing
Set pMC = Nothing
End Sub
Private Sub Form_Load()
Me.ScaleMode = 3
Picture1.ScaleMode = 3
End Sub
原文链接:https://www.f2er.com/vb/256802.html