www.pudn.com > m016_aviplay.zip > AviPlay.frm
VERSION 5.00
Begin VB.Form frmMain
Caption = "利用Windows API 播放AVI文件"
ClientHeight = 4875
ClientLeft = 60
ClientTop = 345
ClientWidth = 6225
LinkTopic = "Form1"
ScaleHeight = 4875
ScaleWidth = 6225
StartUpPosition = 3 '窗口缺省
Begin VB.PictureBox Picture1
Height = 3495
Left = 2160
ScaleHeight = 3435
ScaleWidth = 3795
TabIndex = 6
Top = 1080
Width = 3855
End
Begin VB.CommandButton Command1
Caption = "播放(占满整个PictureBox)"
Height = 495
Left = 2160
TabIndex = 5
Top = 480
Width = 2535
End
Begin VB.CommandButton Command2
Caption = "停止播放"
Height = 495
Left = 4920
TabIndex = 4
Top = 480
Width = 1095
End
Begin VB.FileListBox File1
Height = 1710
Left = 240
Pattern = "*.avi"
TabIndex = 2
Top = 2640
Width = 1815
End
Begin VB.DirListBox Dir1
Height = 1560
Left = 240
TabIndex = 1
Top = 960
Width = 1815
End
Begin VB.DriveListBox Drive1
Height = 300
Left = 240
TabIndex = 0
Top = 480
Width = 1815
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "请选择.avi文件"
Height = 180
Left = 120
TabIndex = 3
Top = 120
Width = 1284
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub Command1_Click()
Dim PathName As String, S As String, ShortPathName As String
Dim mciCommand As String
PathName = File1.Path
If Right(PathName, 1) <> "\" Then PathName = PathName & "\"
PathName = PathName & File1.FileName
S = String(LenB(PathName), Chr(0))
GetShortPathName PathName, S, Len(S)
ShortPathName = Left(S, InStr(S, Chr(0)) - 1)
mciSendString "close MyAVI", vbNullString, 0, 0
mciCommand = "open " & ShortPathName & " alias MyAVI"
mciCommand = mciCommand & " parent " & Picture1.hWnd & " style child"
mciSendString mciCommand, vbNullString, 0, 0
With Picture1
.ScaleMode = vbPixels
mciCommand = "put MyAVI window at 0 0 " & _
.ScaleWidth & " " & .ScaleHeight
mciSendString mciCommand, vbNullString, 0, 0
End With
mciSendString "play MyAVI", vbNullString, 0, 0
End Sub
Private Sub Command2_Click()
mciSendString "close MyAVI", vbNullString, 0, 0
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub Form_Unload(Cancel As Integer)
mciSendString "close MyAVI", vbNullString, 0, 0
End Sub