Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes) DDT Version of Jose's Code
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode = 1
#Include "Win32API.inc"
#Include Once "dshow.inc"
#Include Once "ole2utils.inc" ' For IUnknown_Release
%IDC_Graphic = 500
%WM_GraphNotify = %WM_User+13
Global hDlg As Dword
Global bIsPlaying As Long
' Interface pointers
Global pGraph As IGraphBuilder
Global pControl As IMediaControl
Global pEvents As IMediaEventEx
Global pWindow As IVideoWindow
Function PBMain() As Long
Dialog New Pixels, 0, "Direct Show Tests",,,600,400, %WS_OverlappedWindow To hDlg
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local w,h As Long, rc As Rect
Select Case Cb.Msg
Case %WM_InitDialog
PlayMovieInWindow(hDlg, "bubbles.mov")
Case %WM_Size
GetClientRect hDlg, rc
If IsObject(pWindow) Then
pWindow.SetWindowPosition(rc.Left, rc.Top, rc.Right, rc.Bottom)
RedrawWindow hDlg, rc, 0, %RDW_INVALIDATE Or %RDW_UPDATENOW
End If
Case %WM_GraphNotify
Local lEventCode As Long
Local lParam1 As Long
Local lParam2 As Long
If IsObject(pEvents) Then
Do
pEvents.GetEvent(lEventCode, lParam1, lParam2, 0)
If ObjResult <> %S_Ok Then Exit Do
pEvents.FreeEventParams(lEventCode, lParam1, lParam2)
If lEventCode = %EC_COMPLETE Then
If IsObject(pWindow) Then
pWindow.Visible = %OAFALSE
pWindow.Owner = %NULL
pWindow = Nothing
End If
pControl = Nothing
pEvents = Nothing
pGraph = Nothing
bIsPlaying = %FALSE
Exit Do
End If
Loop
End If
Case %WM_Destroy
If IsObject(pControl) Then
pControl.Stop
pControl = Nothing
End If
If IsObject(pWindow) Then
pWindow.Visible = %OAFALSE
pWindow.Owner = %NULL
pWindow = Nothing
End If
pEvents = Nothing
pGraph = Nothing
End Select
End Function
Sub PlayMovieInWindow (ByVal hwnd As Dword, ByRef wszFileName As WStringZ)
Local hr As Long
' If there is a clip loaded, stop it
If IsObject(pControl) Then
pControl.Stop
pControl = Nothing
pWindow = Nothing
pEvents = Nothing
pGraph = Nothing
End If
' Create an instance of the IGraphBuilder object
pGraph = NewCom ClsId $CLSID_FilterGraph
If hr <> %S_Ok Or IsNothing(pGraph) Then Exit Sub
' Retrieve interafce pointers
pControl = pGraph
If IsNothing(pControl) Then Exit Sub
pEvents = pGraph
If IsNothing(pEvents) Then Exit Sub
pWindow = pGraph
If IsNothing(pWindow) Then Exit Sub
' Render the file
hr = pGraph.RenderFile(wszFileName)
If hr <> %S_Ok Then Exit Sub
' Set the window owner and style
pWindow.Visible = %OAFALSE
pWindow.Owner = hwnd
pWindow.WindowStyle = %WS_Child Or %WS_ClipSiblings Or %WS_ClipChildren
' Have the graph signal event via window callbacks for performance
pEvents.SetNotifyWindow(hwnd, %WM_GRAPHNOTIFY, 0)
' Set the window position
Local rc As RECT
GetClientRect hwnd, rc
pWindow.SetWindowPosition(rc.Left, rc.Top, rc.Right, rc.Bottom)
' Make the window visible
pWindow.Visible = %OATRUE
' Run the graph
pControl.Run
bIsPlaying = %TRUE
End Sub
http://www.garybeene.com/sw/gbsnippets.htm