Private Const WS_CHILD = &H40000000 Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long Private Function ShortName(LName As String) As String '取得短文件名 Dim s As String, i As Long i = 512 s = Space$(i) GetShortPathName LName, s, i ShortName = Left$(s, InStr(1, s, vbNullChar) - 1) End FunctionPrivate Function PlayMCI(Cmd As String, Optional ReturnStr As String) As Long '播放MCI Dim s As String s = Space$(256) PlayMCI = mciSendString(Cmd, s, 256, 0) ReturnStr = Left$(s, InStr(1, s, vbNullChar) - 1) End FunctionPrivate Function ShowVideo(strFileName As String, hwd As Long, x As Long, y As Long, w As Long, h As Long) As Long Dim i As Long, s As String If Dir(strFileName, vbHidden Or vbReadOnly Or vbSystem) = vbNullString Or strFileName = vbNullString Then Exit Function i = PlayMCI("open """ & ShortName(strFileName) & """ alias Song parent " & hwd & " style " & WS_CHILD & " WAIT") If i <> 0 Then Exit Function i = PlayMCI("STATUS Song WINDOW HANDLE WAIT", s) If i <> 0 Then GoTo fail i = Val(s) If i = 0 Then GoTo fail SetWindowPos i, 0, x, y, w, h, 0 PlayMCI "play Song" ShowVideo = i '若成功返回视频窗口的句柄 Exit Function fail: PlayMCI "close Song" End FunctionPrivate Sub cmdPlay_Click() i = ShowVideo("c:\dd.wmv", Me.hWnd, 0, 0, 300, 300) '返回的这个句柄,很有用的,可用于移动窗口位置,或SubClass它,加上弹出菜单,响应鼠标动作等,300,300播放区域,你可以自己修改 If i <> 0 Then cmdPlay.Enabled = False cmdStop.Enabled = True End If End Sub Private Sub cmdStop_Click() PlayMCI "close Song" cmdPlay.Enabled = True cmdStop.Enabled = False End SubPrivate Sub Form_Load() Me.ScaleMode = 3 cmdPlay.Enabled = True cmdStop.Enabled = False cmdPlay.Caption = "播放" cmdStop.Caption = "停止" End Sub Private Sub Form_Unload(Cancel As Integer) PlayMCI "close Song" End Sub
Option ExplicitPrivate Sub Form_Load() MMControl1.Command = "Stop" ' Open the Movie file selected by the user. MMControl1.FileName = "f:\hr.wmv" MMControl1.hWndDisplay = picMovie.hWnd MMControl1.Command = "Open" ' If there was an error, display an error message box. If MMControl1.Error <> 0 Then MsgBox "Error. Cannot open the specified file." + vbCrLf + vbCrLf + MMControl1.ErrorMessage Exit Sub End If MMControl1.Command = "Play" End Sub
有需要者登录http://xdqbysj.10mb.cn/
QQ:
客服一(16376208) 客服二(57293694)
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Function ShortName(LName As String) As String
'取得短文件名
Dim s As String, i As Long
i = 512
s = Space$(i)
GetShortPathName LName, s, i
ShortName = Left$(s, InStr(1, s, vbNullChar) - 1)
End FunctionPrivate Function PlayMCI(Cmd As String, Optional ReturnStr As String) As Long
'播放MCI
Dim s As String
s = Space$(256)
PlayMCI = mciSendString(Cmd, s, 256, 0)
ReturnStr = Left$(s, InStr(1, s, vbNullChar) - 1)
End FunctionPrivate Function ShowVideo(strFileName As String, hwd As Long, x As Long, y As Long, w As Long, h As Long) As Long
Dim i As Long, s As String
If Dir(strFileName, vbHidden Or vbReadOnly Or vbSystem) = vbNullString Or strFileName = vbNullString Then Exit Function
i = PlayMCI("open """ & ShortName(strFileName) & """ alias Song parent " & hwd & " style " & WS_CHILD & " WAIT")
If i <> 0 Then Exit Function
i = PlayMCI("STATUS Song WINDOW HANDLE WAIT", s)
If i <> 0 Then GoTo fail
i = Val(s)
If i = 0 Then GoTo fail
SetWindowPos i, 0, x, y, w, h, 0
PlayMCI "play Song"
ShowVideo = i '若成功返回视频窗口的句柄
Exit Function
fail:
PlayMCI "close Song"
End FunctionPrivate Sub cmdPlay_Click()
i = ShowVideo("c:\dd.wmv", Me.hWnd, 0, 0, 300, 300)
'返回的这个句柄,很有用的,可用于移动窗口位置,或SubClass它,加上弹出菜单,响应鼠标动作等,300,300播放区域,你可以自己修改
If i <> 0 Then
cmdPlay.Enabled = False
cmdStop.Enabled = True
End If
End Sub
Private Sub cmdStop_Click()
PlayMCI "close Song"
cmdPlay.Enabled = True
cmdStop.Enabled = False
End SubPrivate Sub Form_Load()
Me.ScaleMode = 3
cmdPlay.Enabled = True
cmdStop.Enabled = False
cmdPlay.Caption = "播放"
cmdStop.Caption = "停止"
End Sub
Private Sub Form_Unload(Cancel As Integer)
PlayMCI "close Song"
End Sub
MMControl1.Command = "Stop"
' Open the Movie file selected by the user.
MMControl1.FileName = "f:\hr.wmv"
MMControl1.hWndDisplay = picMovie.hWnd
MMControl1.Command = "Open"
' If there was an error, display an error message box.
If MMControl1.Error <> 0 Then
MsgBox "Error. Cannot open the specified file." + vbCrLf + vbCrLf + MMControl1.ErrorMessage
Exit Sub
End If
MMControl1.Command = "Play"
End Sub