27. august 2004 - 11:03Der er
11 kommentarer og 1 løsning
afspille et video klip i en form
hvordan afspiller jeg et videoklip i en form. Den skal ikke åbne en player i et nyt vindue, og man skal i formen ikke kunne se fx. knapperne som er på win meiaplayer komponenten?
du kan ogsaa bruge en picturebox og nogle api kald
blandt andet Private Declare Function mciSendCommand Lib "winmm.dll" Alias "mciSendCommandA" (ByVal wDeviceID As Long, ByVal uMessage As Long, ByVal dwParam1 As Long, ByRef dwParam2 As Any) As Long
du kan jo soege paa google efter mci api der er en masse eks. derude.
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 mciGetErrorString Lib "winmm.dll" Alias _ "mciGetErrorStringA" (ByVal dwError As Long, _ ByVal lpstrBuffer As String, ByVal uLength 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
Public deviceIsOpen As Boolean
Public Function PlayVideo(FileName As String, ByVal VideoBox As PictureBox) Dim RetVal As Long Dim CommandString As String Dim ShortFileName As String * 260
' Retrieve short file name format RetVal = GetShortPathName(FileName, ShortFileName, Len(ShortFileName)) FileName = Left$(ShortFileName, RetVal)
' Open the device CommandString = "Open " & FileName & " type AVIVideo alias AVIFile parent " & _ CStr(VideoBox.hWnd) & " style " & CStr(WS_CHILD) RetVal = mciSendString(CommandString, vbNullString, 0, 0&) If RetVal Then GoTo error ' remember that the device is now open deviceIsOpen = True ' Resize the movie to PictureBox size CommandString = "put AVIFile window at 0 0 " & CStr _ (VideoBox.ScaleWidth / Screen.TwipsPerPixelX) & " " & _ CStr(VideoBox.ScaleHeight / Screen.TwipsPerPixelY) RetVal = mciSendString(CommandString, vbNullString, 0, 0&) If RetVal <> 0 Then GoTo error
' Play the file CommandString = "Play AVIFile" 'wait" RetVal = mciSendString(CommandString, vbNullString, 0, 0&) If RetVal <> 0 Then GoTo error
' ' Close the device ' CommandString = "Close AVIFile" ' RetVal = mciSendString(CommandString, vbNullString, 0, 0&) ' If RetVal <> 0 Then GoTo error
Exit Function
error: ' An error occurred. ' Get the error description Dim ErrorString As String ErrorString = Space$(256) mciGetErrorString RetVal, ErrorString, Len(ErrorString) ErrorString = Left$(ErrorString, InStr(ErrorString, vbNullChar) - 1)
' close the device if necessary If deviceIsOpen Then CommandString = "Close AVIFile" mciSendString CommandString, vbNullString, 0, 0& End If
' raise a custom error, with the proper description Err.Raise 999, , ErrorString
i en form : ( du skal bruge en Picturebox og to buttons )
Private Declare Function BeginPath Lib "gdi32" (ByVal hdc As Long) As Long Private Declare Function EndPath Lib "gdi32" (ByVal hdc As Long) As Long Private Declare Function PathToRegion Lib "gdi32" (ByVal hdc As Long) As Long Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Sub cmdOpenPlay_Click() PlayVideo "c:\video1.mpg", Picture1 End Sub
Private Sub cmdStopClose_Click()
Call StopPlaying Call CloseVideo
End Sub
Private Sub Form_Load()
Const TXT = "CANKER!"
Dim i As Long Dim hRgn As Long
Picture1.AutoRedraw = True
' Select a big font. Picture1.Font.Name = "Times New Roman" Picture1.Font.Bold = True Picture1.Font.Size = 50
' Make the PictureBox big enough. Picture1.Width = Picture1.TextWidth(TXT) Picture1.Height = Picture1.TextHeight(TXT)
' Make the clipping path. BeginPath Picture1.hdc Picture1.CurrentX = 0 Picture1.CurrentY = 0 Picture1.Print TXT EndPath Picture1.hdc
' Convert the path into a region. hRgn = PathToRegion(Picture1.hdc)
' Constrain the PictureBox to the region. SetWindowRgn Picture1.hWnd, hRgn, False
End Sub
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.