Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe
#Dim All
#Debug Error On
#Debug Display On
#Include "win32api.inc"
#Include Once "dshow.inc"
#Include Once "ole2utils.inc" ' For IUnknown_Release
%IDC_Graphic = 500
%WM_GraphNotify = %WM_User+13
Global pGraph As IGraphBuilder 'Filter Graph Manager
Global pWindow As IVideoWindow 'Display Window
Global pEvents As IMediaEventEx
Global pControl As IMediaControl
Global pBuild As ICaptureGraphBuilder2 'Capture Graph Builder
Global pConfig As IAMStreamConfig 'video output format
Global pSysDevEnum As ICreateDevEnum 'enumeration object
Global pEnumCat As IEnumMoniker
Global pMoniker As IMoniker 'contains information about other objects
Global pPropBag As IPropertyBag
Global pbc As IBindCTX
Global pCap As IBaseFilter 'Video capture filter
Global pProcAmp As IAMVideoProcAmp 'backlight comp, brightness, contrast, gain, gamme, etc.
Global pCamControl As IAMCameraControl 'exposure, focus, zoom
Global pGrabber As ISamplerGrabber
Global pSample As IMediaSample
Global hDlg, hDC, hGraphic as Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Direct Show",300,300,400,300, %WS_OverlappedWindow Or %WS_ClipChildren To hDlg
Control add Graphic, hDlg, %IDC_Graphic, "", 100,0,200,300, %SSN_Notify
Control Handle hDlg, %IDC_Graphic to hGraphic
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local w,h As Long, PS as PaintStruct
Select Case Cb.Msg
Case %WM_InitDialog
pGraph = NewCom ClsId $CLSID_FilterGraph 'filter graph
pBuild = NewCom ClsId $CLSID_CaptureGraphBuilder2 'capture graph builder
pSysDevEnum = NewCom ClsId $CLSID_SystemDeviceEnum 'enumeration object
pGrabber = NewCom ClsId $CLSID_SampleGrabber
pWindow = pGraph
pControl = pGraph
pProcAmp = pCap
pCamControl = pCap
pWindow.Owner = hGraphic
pWindow.WindowStyle = %WS_Child or %WS_ClipChildren
pGraph.AddFilter(pGrabber,"Sample Grabber")
Case %WM_Size
Dialog Get Client hDlg To w,h
Control Set Size hDlg, %IDC_Graphic, w-100, h
pWindow.SetWindowPosition(0,0,w,h)
Case %WM_Paint
Dialog Get Client hDlg To w,h
hDC = BeginPaint(hDlg, PS)
hBorderBrush = CreateSolidBrush(%Black)
FillRect(hDC, CameraRC, hBorderBrush)
EndPaint hDlg, PS
Case %WM_Destroy
End Select
End Function
http://www.garybeene.com/sw/gbsnippets.htm