807
社区成员
发帖
与我相关
我的任务
分享注意里面的格
ErrorCode = mciSendString("open " & Trim(MCIfile) & " Type " & "MPEGVideo" & _
" alias MEDIA parent " & Picture1.hwnd & " style " & WS_CHILD & " WAIT", ReturnString, 256, 0'取得播放图像的句柄mciHWnd
ErrorCode = mciSendString("STATUS MEDIA WINDOW HANDLE WAIT", ReturnString, 256, 0)Option Explicit
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Const GWL_WNDPROC As Long = -4
Public Const WM_RBUTTONDOWN As Long = &H204&
Public prevWndProc As Long, mciHwnd As Long
'回调函数
'自定义窗口处理程序,用于截获右击视频播放窗口的Windows消息系统
Public Function WndProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
On Error Resume Next
Select Case Msg
Case WM_RBUTTONDOWN '弹出右键菜单
Form1.PopupMenu Form1.File
Case Else '操作系统预定义窗口处理程序
WndProc = CallWindowProc(prevWndProc, hwnd, Msg, wParam, lParam)
End Select
End Function'窗体上放一个控件Picture1
'建立一个“文件”菜单,名称是“File”。再建立一个子菜单“打开文件”,名称是“Openfile”
Option Explicit
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.dll" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Private Const WS_CHILD As Long = &H40000000
Dim MCIfile As String '要播放的多媒体文件名
Dim sMCI As String '转换后的短文件名
'MCIfile:多媒体文件
'Pict:图片框PictureBox
'MCI视频图像缩放函数
Private Function mciVideoStretch(ByVal MCIfile As String, Pict As PictureBox)
On Error Resume Next
Dim strMCI As String
strMCI = "put " & MCIfile & " window at 0 0 " & Pict.ScaleWidth & " " & Pict.ScaleHeight
Call mciSendString(strMCI, vbNullString, 0, 0)
End Function
Private Sub Form_Load()
Dim ErrorCode As Long, ReturnString As String * 256
On Error Resume Next
Form1.ScaleMode = 3
Picture1.ScaleMode = 3
mciSendString "stop MEDIA", vbNullString, 0, 0
mciSendString "close MEDIA", vbNullString, 0, 0
MCIfile = "E:\TDDOWNLOAD\[朝鲜经典电影之二十九.看不见的战线].Invisible.Front.1970.DVDRip.XviD-tslhh.avi" '事先加载一个多媒体文件
'将长文件名转换成短文件名,mciSendString不支持长文件名
sMCI = String(LenB(MCIfile), Chr(0))
GetShortPathName MCIfile, sMCI, Len(sMCI)
MCIfile = Left(sMCI, InStr(sMCI, Chr(0)) - 1)
'注意里面的格
ErrorCode = mciSendString("open " & Trim(MCIfile) & " Type " & "MPEGVideo" & _
" alias MEDIA parent " & Picture1.hwnd & " style " & WS_CHILD & " WAIT", ReturnString, 256, 0)
'取得播放图像的句柄mciHWnd
ErrorCode = mciSendString("STATUS MEDIA WINDOW HANDLE WAIT", ReturnString, 256, 0)
ReturnString = Left$(ReturnString, InStr(1, ReturnString, vbNullChar) - 1)
If ErrorCode = 0 Then
If Val(ReturnString) <> 0 Then
mciHwnd = CLng(ReturnString) '得到播放图像句柄mciHWnd
End If
End If
'开始播放
mciSendString "play MEDIA", vbNullString, 0, 0
prevWndProc = GetWindowLong(mciHwnd, GWL_WNDPROC)
Call SetWindowLong(mciHwnd, GWL_WNDPROC, AddressOf WndProc)
End Sub
Private Sub Form_Resize()
Picture1.Move 0, 0, Form1.ScaleWidth, Form1.ScaleHeight
Call mciVideoStretch("MEDIA", Picture1)
End Sub
'关闭窗体停止播放
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
SetWindowLong mciHwnd, GWL_WNDPROC, prevWndProc
prevWndProc = 0
mciSendString "stop MEDIA", vbNullString, 0, 0
mciSendString "close MEDIA", vbNullString, 0, 0
End Sub