Das nachfolgende Beispiel zeigt, wie sich ein AVI-Datei (Video) ohne zusätzliches Player-Control in einem PictureBox-Control abspielen lässt. Alles was man dazu braucht, ist die universelle SendMCIString API-Funktion! Erstellen Sie ein neues Projekt und platzieren Sie eine PictureBox (picAVI) auf die Form. Weiterhin werden noch zwei CommandButtons benötigt (btnPlay und btnStop). Und hier der Code: Public Class Form1 ' benötigte API-Funktionen Private Declare Function mciSendString Lib "winmm.dll" _ Alias "mciSendStringA" ( _ ByVal lpstrCommand As String, _ ByVal lpstrReturnString As String, _ ByVal uReturnLength As Integer, _ ByVal hwndCallback As IntPtr) As Integer Private Declare Function GetShortPathName Lib "kernel32" _ Alias "GetShortPathNameA" ( _ ByVal lpszLongPath As String, _ ByVal lpszShortPath As String, _ ByVal cchBuffer As Integer) As Integer ' AVI-File öffnen Private Sub AVI_Open(ByVal sFile As String, ByVal Handle As IntPtr) Dim sBuffer As String = Space(256) Dim nResult As Integer ' DOS-Namen ermitteln (8.3-Format) nResult = GetShortPathName(sFile, sBuffer, sBuffer.Length) sFile = sBuffer.Substring(0, nResult) ' AVI öffnen ' öffnet ein Gerät und eine Multimedia-Datei mciSendString("open " & sFile & " type avivideo alias myAVI", 0, 0, 0) ' Anzeige in der PictureBox mciSendString("window myAVI handle " & CStr(Handle), 0, 0, 0) End Sub ' AVI in PictureBox abspielen Private Sub AVI_Play() mciSendString("play myAVI from 0", 0, 0, 0) End Sub ' Abspielvorgang stoppen Private Sub AVI_Stop() mciSendString("close myAVI", 0, 0, 0) End Sub ' MCI Schließen Private Sub AVI_Close() mciSendString("close myAVI", 0, 0, 0) End Sub Private Sub btnPlay_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnPlay.Click ' AVI abspielen picAVI.Image = Nothing AVI_Open("d:\avi-datei.avi", picAVI.Handle) AVI_Play() btnStop.Enabled = True End Sub Private Sub btnStop_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnStop.Click ' Wiedergabe beenden AVI_Stop() btnStop.Enabled = False End Sub End Class |