求助!!急!视频指定在在Picture1控件上播放,当Picture1大小随窗体大小变化而变化时,视频的播放该怎么实现适应Picture1大小变化???
视频指定在在Picture1控件上播放,当Picture1大小随窗体大小变化而变化时,视频的播放该怎么实现适应Picture1大小变化???
以下是Picture1固定大小时,使视频适应Picture1固定大小时的代码,请问当我实现Picture1大小随窗体大小变化而变化时,这视频的播放该怎么实现适应Picture1大小变化???是在这段代码中来实现吗??非常感谢!!!
Public Function PutMPEG(Left As Long, Top As Long, Width As Long, Height As Long) As String
Dim dwReturn As Long
Dim ret As String * 255
If Width = 0 Or Height = 0 Then
Dim rec As RECT
Call GetWindowRect(Form1.Picture1.Hwnd, rec)
Width = rec.Right - rec.Left
Height = rec.Bottom - rec.Top
End If
dwReturn = mciSendString("put NOWMUSIC window at " & Left & " " & Top & " " & Width & " " & Height, 0&, 0&, 0&)
PutMPEG = "Success"
End Function
Public Function PlayMusic() As Boolean
If RefInt = 0 Then
Result = PutMPEG(Val(O), Val(0), Val(0), Val(0))
End If
End Function
[解决办法]
没有返回值。
call mciVideoStretch(MCIfile, Pict)
Private Sub Form_Resize()
Picture1.Move Form1.Left, Form1.Top, Form1.Width, Form1.Height
Call mciVideoStretch(MCIfile, Pict)
End Sub
Private Sub Form_Resize()
Picture1.Move Form1.Left, Form1.Top, Form1.Width, Form1.Height
Call mciVideoStretch(MCIfile, Picture1)
End Sub
'窗体上放一个控件Picture1
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
On Error Resume Next
Form1.ScaleMode = 3
Picture1.ScaleMode = 3
mciSendString "stop MEDIA", vbNullString, 0, 0
mciSendString "close MEDIA", vbNullString, 0, 0
MCIfile = "E:\其它\录像\永恒的吻_Vitas.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)
'开始播放
mciSendString "play MEDIA", vbNullString, 0, 0
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
mciSendString "stop MEDIA", vbNullString, 0, 0
mciSendString "close MEDIA", vbNullString, 0, 0
End Sub