视频指定在在Picture1控件上播放,当Picture1大小随窗体大小变化而变化时,视频的播放该怎么实现适应Picture1大小变化???
以下是Picture1固定大小时,使视频适应Picture1固定大小时的代码,请问当我实现Picture1大小随窗体大小变化而变化时,这视频的播放该怎么实现适应Picture1大小变化???是在这段代码中来实现吗??非常感谢!!!Public Function PutMPEG(Left As Long, Top As Long, Width As Long, Height As Long) As StringDim 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 IfdwReturn = mciSendString("put NOWMUSIC window at " & Left & " " & Top & " " & Width & " " & Height, 0&, 0&, 0&)
PutMPEG = "Success"
End FunctionPublic Function PlayMusic() As BooleanIf RefInt = 0 Then
    Result = PutMPEG(Val(O), Val(0), Val(0), Val(0))
  End If
End Function

解决方案 »

  1.   

    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'MCIfile:多媒体文件
    'Pict:图片框PictureBox
    Public Function mciVideoStretch(ByVal MCIfile As String, Pict As PictureBox) 'MCI视频图像缩放函数
           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
      

  2.   

    非常感谢!请问一下,调用这函数时是这样写的吗? 
    Public Function PlayMusic() As Booleandim t as string
    t=mciVideoStretch(MCIfile, Pict)End Function
    可是好像没有效果???请问我是调用错了吗?求高手指点!!
      

  3.   


    非常感谢!请问一下,调用这函数时是这样写的吗?  
    Public Function PlayMusic() As Booleandim t as string
    t=mciVideoStretch(MCIfile, Pict)End Function
    可是好像没有效果???请问我是调用错了吗?求高手指点!!
      

  4.   

    没有返回值。
    call mciVideoStretch(MCIfile, Pict)
      

  5.   

    这个函数用在Timer事件中或者窗体的resize事件中。
    Private Sub Form_Resize()
        Picture1.Move Form1.Left, Form1.Top, Form1.Width, Form1.Height
        Call mciVideoStretch(MCIfile, Pict)
    End Sub
      

  6.   


    大侠,在窗体的resize事件时,它说Call mciVideoStretch(MCIfile, Pict)中的“MCIfile”变量未定义
    请问是什么原因???
      

  7.   

    MCIfile是你要播放的多媒体文件,Pict就是Picture1:
    Private Sub Form_Resize()
        Picture1.Move Form1.Left, Form1.Top, Form1.Width, Form1.Height
        Call mciVideoStretch(MCIfile, Picture1)
    End Sub
      

  8.   

    是啊!我是这样做的,但是就是出错说我变量未定义,一个mciSendString函数模块那里有一段是这样的:
    Public Function PlayMusic() As Boolean
        Dim RefInt As Long
        PlayMusic = False
        RefInt = mciSendString("play NOWMUSIC", vbNull, 0, 0)
        If RefInt = 0 Then
        PlayMusic = True: DownloadLrc                               
        SetVolume ((MainForm.Button1(6).Left - 3250)) / 600 * 1000 
        End If
    End FunctionPublic Function mciVideoStretch(ByVal MCIfile As String, Pict As PictureBox)  'MCI视频图像缩放函数
           On Error Resume Next
           Dim strMCI As String
           strMCI = "put " & NOWMUSIC & " window at 0 0 " & Form1.Picture1.ScaleWidth & " " & Form1.Picture1.ScaleHeight
           Call mciSendString(strMCI, vbNullString, 0, 0)
    End Function
    Form1的Resize事件
    Private Sub Form_Resize()
    PaintPicture Picbackbuf, 0, 0, Me.ScaleWidth, Me.ScaleHeight, 0, 0, Picbackbuf.Width, Picbackbuf.Height    
    Picture1.Move 240, 450, Me.ScaleWidth - 490, Me.ScaleHeight - 600
    Call mciVideoStretch(NOWMUSIC, Picture1)
    End Sub
      

  9.   

    下面这个程序经过调试成功:
    '窗体上放一个控件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 = &H40000000Dim 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 FunctionPrivate 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 SubPrivate 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