home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / VBSamples / DirectShow / Builder / builder.FRM (.txt) next >
Encoding:
Visual Basic Form  |  2001-10-08  |  52.0 KB  |  1,160 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
  3. Begin VB.Form frmMain 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Filter and Pin Viewer"
  6.    ClientHeight    =   6060
  7.    ClientLeft      =   60
  8.    ClientTop       =   615
  9.    ClientWidth     =   8025
  10.    Icon            =   "builder.frx":0000
  11.    LinkTopic       =   "frmMain"
  12.    LockControls    =   -1  'True
  13.    MaxButton       =   0   'False
  14.    PaletteMode     =   1  'UseZOrder
  15.    ScaleHeight     =   6060
  16.    ScaleWidth      =   8025
  17.    Begin VB.Frame frameFilter 
  18.       Caption         =   "Filter Graph"
  19.       Height          =   2652
  20.       Left            =   75
  21.       TabIndex        =   18
  22.       Top             =   75
  23.       Width           =   7875
  24.       Begin VB.CommandButton cmdStop 
  25.          Caption         =   "Stop"
  26.          Height          =   315
  27.          Left            =   2175
  28.          TabIndex        =   3
  29.          Top             =   2175
  30.          Width           =   840
  31.       End
  32.       Begin VB.CommandButton cmdPause 
  33.          Caption         =   "Pause"
  34.          Height          =   315
  35.          Left            =   1200
  36.          TabIndex        =   2
  37.          Top             =   2175
  38.          Width           =   840
  39.       End
  40.       Begin VB.CommandButton cmdRun 
  41.          Caption         =   "Run"
  42.          Height          =   315
  43.          Left            =   225
  44.          TabIndex        =   1
  45.          Top             =   2175
  46.          Width           =   840
  47.       End
  48.       Begin VB.CommandButton cmdSource 
  49.          Caption         =   "Add &Source Filter..."
  50.          Height          =   315
  51.          Left            =   3960
  52.          TabIndex        =   6
  53.          Top             =   2175
  54.          Width           =   1572
  55.       End
  56.       Begin VB.ListBox listFilters 
  57.          Height          =   1620
  58.          ItemData        =   "builder.frx":0442
  59.          Left            =   3960
  60.          List            =   "builder.frx":0444
  61.          Sorted          =   -1  'True
  62.          TabIndex        =   5
  63.          Top             =   480
  64.          Width           =   3675
  65.       End
  66.       Begin VB.CommandButton cmdAddRegFilter 
  67.          Caption         =   "&Add ->"
  68.          Height          =   315
  69.          Left            =   3120
  70.          TabIndex        =   4
  71.          Top             =   480
  72.          Width           =   732
  73.       End
  74.       Begin VB.ListBox listRegFilters 
  75.          Height          =   1620
  76.          ItemData        =   "builder.frx":0446
  77.          Left            =   240
  78.          List            =   "builder.frx":0448
  79.          Sorted          =   -1  'True
  80.          TabIndex        =   0
  81.          Top             =   480
  82.          Width           =   2775
  83.       End
  84.       Begin VB.Label lblFilters 
  85.          Caption         =   "Filters in current filter &graph"
  86.          Height          =   252
  87.          Left            =   3960
  88.          TabIndex        =   13
  89.          Top             =   240
  90.          Width           =   2052
  91.       End
  92.       Begin VB.Label lblRegFilters 
  93.          Caption         =   "&Registered filters"
  94.          Height          =   252
  95.          Left            =   240
  96.          TabIndex        =   12
  97.          Top             =   240
  98.          Width           =   2052
  99.       End
  100.    End
  101.    Begin VB.Frame framePinInfo 
  102.       Caption         =   "Filter"
  103.       Height          =   3132
  104.       Left            =   75
  105.       TabIndex        =   11
  106.       Top             =   2850
  107.       Width           =   7875
  108.       Begin VB.TextBox txtPinInfo 
  109.          Height          =   1620
  110.          Left            =   3975
  111.          Locked          =   -1  'True
  112.          MultiLine       =   -1  'True
  113.          ScrollBars      =   3  'Both
  114.          TabIndex        =   10
  115.          Top             =   1200
  116.          Width           =   3675
  117.       End
  118.       Begin VB.CommandButton cmdConnect 
  119.          Caption         =   "Co&nnect One Pin..."
  120.          Height          =   315
  121.          Left            =   2025
  122.          TabIndex        =   9
  123.          Top             =   2500
  124.          Width           =   1692
  125.       End
  126.       Begin VB.CommandButton cmdRender 
  127.          Caption         =   "&Connect Downstream"
  128.          Height          =   315
  129.          Left            =   225
  130.          TabIndex        =   8
  131.          Top             =   2500
  132.          Width           =   1692
  133.       End
  134.       Begin VB.ListBox listPins 
  135.          Height          =   1230
  136.          ItemData        =   "builder.frx":044A
  137.          Left            =   225
  138.          List            =   "builder.frx":044C
  139.          Sorted          =   -1  'True
  140.          TabIndex        =   7
  141.          Top             =   1200
  142.          Width           =   3480
  143.       End
  144.       Begin VB.Label lblFilterName 
  145.          Height          =   255
  146.          Left            =   1425
  147.          TabIndex        =   20
  148.          Top             =   225
  149.          Width           =   4815
  150.       End
  151.       Begin VB.Label lblFilter 
  152.          Caption         =   "Filter name:"
  153.          Height          =   255
  154.          Left            =   240
  155.          TabIndex        =   19
  156.          Top             =   240
  157.          Width           =   975
  158.       End
  159.       Begin VB.Label lblVendor 
  160.          Caption         =   "Vendor: "
  161.          Height          =   255
  162.          Left            =   240
  163.          TabIndex        =   17
  164.          Top             =   480
  165.          Width           =   735
  166.       End
  167.       Begin VB.Label lblVendorInfo 
  168.          Height          =   255
  169.          Left            =   1440
  170.          TabIndex        =   16
  171.          Top             =   480
  172.          Width           =   4935
  173.       End
  174.       Begin VB.Label lblPinListbox 
  175.          Caption         =   "&Pins in selected filter"
  176.          Height          =   255
  177.          Left            =   240
  178.          TabIndex        =   14
  179.          Top             =   940
  180.          Width           =   2055
  181.       End
  182.       Begin VB.Label lblPinInfo 
  183.          Caption         =   "Information for selected pin"
  184.          Height          =   255
  185.          Left            =   3975
  186.          TabIndex        =   15
  187.          Top             =   940
  188.          Width           =   2175
  189.       End
  190.    End
  191.    Begin MSComDlg.CommonDialog ctrlCommonDlg 
  192.       Left            =   8760
  193.       Top             =   -120
  194.       _ExtentX        =   847
  195.       _ExtentY        =   847
  196.       _Version        =   393216
  197.       CancelError     =   -1  'True
  198.       Flags           =   4096
  199.    End
  200.    Begin VB.Menu mnuFilterGraph 
  201.       Caption         =   "&FilterGraph"
  202.       Begin VB.Menu mnu_FilterGraphNew 
  203.          Caption         =   "&New (empty)"
  204.       End
  205.       Begin VB.Menu mnu_FilterGraphGenerate 
  206.          Caption         =   "&Generate from input file..."
  207.       End
  208.       Begin VB.Menu mnu_Separator1 
  209.          Caption         =   "-"
  210.       End
  211.       Begin VB.Menu mnu_FilterGraphRun 
  212.          Caption         =   "&Run"
  213.       End
  214.       Begin VB.Menu mnu_FilterGraphPause 
  215.          Caption         =   "&Pause"
  216.       End
  217.       Begin VB.Menu mnu_FilterGraphStop 
  218.          Caption         =   "&Stop"
  219.       End
  220.       Begin VB.Menu mnu_Separator2 
  221.          Caption         =   "-"
  222.       End
  223.       Begin VB.Menu mnu_FilterGraphExit 
  224.          Caption         =   "E&xit"
  225.       End
  226.    End
  227.    Begin VB.Menu mnu_Options 
  228.       Caption         =   "&Options"
  229.       Begin VB.Menu mnu_BuildCustomGraph 
  230.          Caption         =   "&Build custom graph"
  231.       End
  232.    End
  233. Attribute VB_Name = "frmMain"
  234. Attribute VB_GlobalNameSpace = False
  235. Attribute VB_Creatable = False
  236. Attribute VB_PredeclaredId = True
  237. Attribute VB_Exposed = False
  238. '*******************************************************************************
  239. '*       This is a part of the Microsoft DXSDK Code Samples.
  240. '*       Copyright (C) 1999-2001 Microsoft Corporation.
  241. '*       All rights reserved.
  242. '*       This source code is only intended as a supplement to
  243. '*       Microsoft Development Tools and/or SDK documentation.
  244. '*       See these sources for detailed information regarding the
  245. '*       Microsoft samples programs.
  246. '*******************************************************************************
  247. Option Explicit
  248. Option Base 0
  249. Option Compare Text
  250. Private Enum GraphState
  251. StateStopped = 0
  252. StatePaused = 1
  253. StateRunning = 2
  254. End Enum
  255. Private m_objFilterInfo As Object        'IFilterInfo interface represents all filters in the current graph
  256. Private m_objRegFilterInfo As Object ' IFilterInfo interface represents all registered filters on the system
  257. Private m_objSelectedPin As Object  ' IPinInfo interface represents the pin the user opted for from listbox
  258. Private m_objLocalFilterInfo As Object ' IFilterInfo interface represents the local working filter
  259. Private m_objMediaControl As IMediaControl  'IMediaControl interface provided by IFilgraphManager
  260. Private m_GraphState As GraphState  'enum value indicating whether the video is running, paused, or stopped
  261. ' **************************************************************************************************************************************
  262. ' * PRIVATE INTERFACE- PROCEDURES
  263.             ' ******************************************************************************************************************************
  264.             ' * procedure name: AppendFilter
  265.             ' * procedure description:    appends a filter to the current working graph
  266.             ' *
  267.             ' ******************************************************************************************************************************
  268.             Private Sub AppendFilter(bstrFilterName As String, objFilter As IFilterInfo)
  269.             Dim nCount As Long
  270.             Dim LocalRegFilters As Object
  271.             Dim objRegFilter As IRegFilterInfo
  272.             On Local Error GoTo ErrLine
  273.             
  274.             'obtain reference to an IAMCollection containing the registered filters
  275.             If Not m_objMediaControl Is Nothing Then
  276.                If Not m_objMediaControl.RegFilterCollection Is Nothing Then
  277.                   Set LocalRegFilters = m_objMediaControl.RegFilterCollection
  278.                End If
  279.             End If
  280.             
  281.             'step through each registered filter for verification
  282.             'and proceed to append the filter if the filter is in fact valid..
  283.             For nCount = 0 To (LocalRegFilters.Count - 1) Step 1
  284.                 LocalRegFilters.Item nCount, objRegFilter
  285.                 If LCase(objRegFilter.Name) = LCase(bstrFilterName) Then
  286.                     objRegFilter.filter objFilter
  287.                     Exit For
  288.                 End If
  289.             Next
  290.             
  291.              'refresh the filter list
  292.             Call RefreshFilters
  293.             
  294.             'clean-up & dereference local data
  295.             If Not objRegFilter Is Nothing Then Set objRegFilter = Nothing
  296.             If Not LocalRegFilters Is Nothing Then Set LocalRegFilters = Nothing
  297.             Exit Sub
  298.             
  299. ErrLine:
  300.             Err.Clear
  301.             Exit Sub
  302.             End Sub
  303.             
  304.             
  305.             ' ******************************************************************************************************************************
  306.             ' * procedure name: RefreshRegFilters
  307.             ' * procedure description:   update the listbox of registered filters (listbox listRegFilters)
  308.             ' *
  309.             ' ******************************************************************************************************************************
  310.             Private Sub RefreshRegFilters()
  311.             Dim objRegFilter As IRegFilterInfo
  312.             On Local Error GoTo ErrLine
  313.                 
  314.             'clear the collection
  315.             listRegFilters.Clear
  316.             
  317.             'verify that we have a valid pointer
  318.             If Not m_objRegFilterInfo Is Nothing Then
  319.                 'enumerate through each filter in the registered filters collection..
  320.                 For Each objRegFilter In m_objRegFilterInfo
  321.                     'append the filtername to the listbox
  322.                     listRegFilters.AddItem objRegFilter.Name
  323.                 Next
  324.             End If
  325.             
  326.             'reset selected item in the listbox..
  327.             If listRegFilters.ListCount > 0 Then
  328.                listRegFilters.ListIndex = 0  ' select first in list
  329.             End If
  330.             
  331.             'clean-up & dereference local data
  332.             If Not objRegFilter Is Nothing Then Set objRegFilter = Nothing
  333.             Exit Sub
  334.             
  335. ErrLine:
  336.             Err.Clear
  337.             Exit Sub
  338.             End Sub
  339.             
  340.             
  341.             
  342.             
  343.             
  344.             
  345. ' **************************************************************************************************************************************
  346. ' * PRIVATE INTERFACE- INTRINSIC VBFORM EVENT HANDLERS
  347.             ' ******************************************************************************************************************************
  348.             ' * procedure name: Form_Initalize
  349.             ' * procedure description:   fired intrinsically by visual basic when the class initalizes
  350.             ' *
  351.             ' ******************************************************************************************************************************
  352.             Private Sub Form_Initalize()
  353.             On Local Error GoTo ErrLine
  354.             ' instantiate the FilgraphManager
  355.             Set m_objMediaControl = New FilgraphManager
  356.             'obtain an IAMCollection reference for the registered filters
  357.             If Not m_objMediaControl Is Nothing Then
  358.                If Not m_objMediaControl.RegFilterCollection Is Nothing Then
  359.                   Set m_objRegFilterInfo = m_objMediaControl.RegFilterCollection
  360.                End If
  361.             End If
  362.             Exit Sub
  363.             
  364. ErrLine:
  365.             Err.Clear
  366.             Exit Sub
  367.             End Sub
  368.             
  369.             
  370.             ' ******************************************************************************************************************************
  371.             ' * procedure name: Form_Terminate
  372.             ' * procedure description:   fired intrinsically by visual basic when the form terminates
  373.             ' *
  374.             ' ******************************************************************************************************************************
  375.             Private Sub Form_Terminate()
  376.             On Local Error GoTo ErrLine
  377.             
  378.             'clean-up & dereference
  379.             If Not m_objFilterInfo Is Nothing Then Set m_objFilterInfo = Nothing
  380.             If Not m_objSelectedPin Is Nothing Then Set m_objSelectedPin = Nothing
  381.             If Not m_objMediaControl Is Nothing Then Set m_objMediaControl = Nothing
  382.             If Not m_objRegFilterInfo Is Nothing Then Set m_objRegFilterInfo = Nothing
  383.             If Not m_objLocalFilterInfo Is Nothing Then Set m_objLocalFilterInfo = Nothing
  384.             Exit Sub
  385.             
  386. ErrLine:
  387.             Err.Clear
  388.             Exit Sub
  389.             End Sub
  390.             
  391.             
  392.             ' ******************************************************************************************************************************
  393.             ' * procedure name: Form_Load
  394.             ' * procedure description:   fired intrinsically by visual basic when the form loads
  395.             ' *
  396.             ' ******************************************************************************************************************************
  397.             Private Sub Form_Load()
  398.             On Local Error GoTo ErrLine
  399.             ' initialize the display
  400.             listFilters.Clear: listPins.Clear: txtPinInfo.Text = vbNullString
  401.             ' update the display for registered filters
  402.             Call RefreshRegFilters
  403.             Exit Sub
  404.             
  405. ErrLine:
  406.             Err.Clear
  407.             Exit Sub
  408.             End Sub
  409.             
  410.             
  411.             
  412.             
  413. ' **************************************************************************************************************************************
  414. ' * PRIVATE INTERFACE- INTRINSIC CONTROL EVENT HANDLERS
  415.             ' ******************************************************************************************************************************
  416.             ' * procedure name: cmdAddRegFilter_Click
  417.             ' * procedure description:  occures when the user manually appends a filter to the graph
  418.             ' *
  419.             ' ******************************************************************************************************************************
  420.             Private Sub cmdAddRegFilter_Click()
  421.             Dim objFilter As IFilterInfo
  422.             Dim objRegFilter As IRegFilterInfo
  423.             On Local Error GoTo ErrLine
  424.             
  425.             If Not m_objRegFilterInfo Is Nothing Then
  426.                'enumerate all registered filters
  427.                For Each objRegFilter In m_objRegFilterInfo ' listRegFilters
  428.                    If LCase(objRegFilter.Name) = LCase(listRegFilters.Text) Then
  429.                        objRegFilter.filter objFilter
  430.                        If objFilter.IsFileSource Then
  431.                           'display the common dialog
  432.                           ctrlCommonDlg.CancelError = False
  433.                           ctrlCommonDlg.ShowOpen
  434.                           'assign the filter a filename
  435.                           If ctrlCommonDlg.FileName <> vbNullString Then
  436.                              objFilter.FileName = ctrlCommonDlg.FileName
  437.                           Else: Exit Sub
  438.                           End If
  439.                        End If
  440.                        Exit For
  441.                    End If
  442.                Next
  443.             End If
  444.             
  445.             'refresh the filter list
  446.             Call RefreshFilters
  447.             
  448.             'clean-up & dereference local data
  449.             If Not objFilter Is Nothing Then Set objFilter = Nothing
  450.             If Not objRegFilter Is Nothing Then Set objRegFilter = Nothing
  451.             Exit Sub
  452.             
  453. ErrLine:
  454.             Err.Clear
  455.             Exit Sub
  456.             End Sub
  457.             
  458.             
  459.             
  460.             ' ******************************************************************************************************************************
  461.             ' * procedure name: cmdConnect_Click
  462.             ' * procedure description:  occures when the user manually makes a connection
  463.             ' *                                       connects the current selected pin, indicated by m_objSelectedPin , m_objMediaControl, and m_objFilterInfo
  464.             ' ******************************************************************************************************************************
  465.             Private Sub cmdConnect_Click()
  466.             Dim objPI As IPinInfo
  467.             On Local Error GoTo ErrLine ' if already connected, connect fails
  468.             
  469.             'set direction
  470.             frmSelectPin.OtherDir = m_objSelectedPin.Direction
  471.             Set frmSelectPin.g_objMC = m_objMediaControl
  472.             Set frmSelectPin.g_objFI = m_objFilterInfo
  473.             'refresh the filters & display the dialog
  474.             frmSelectPin.RefreshFilters: frmSelectPin.Show 1
  475.             
  476.             If frmSelectPin.bOK Then
  477.                 If Not frmSelectPin.g_objPI Is Nothing Then _
  478.                    Set objPI = frmSelectPin.g_objPI
  479.                 m_objSelectedPin.Connect objPI
  480.                 RefreshFilters  ' refresh the filters in the ui
  481.             End If
  482.             
  483.             'clean-up & dereference local data
  484.             If Not objPI Is Nothing Then Set objPI = Nothing
  485.             Exit Sub
  486.             
  487. ErrLine:
  488.             Err.Clear
  489.             Exit Sub
  490.             End Sub
  491.             
  492.             
  493.             
  494.             ' ******************************************************************************************************************************
  495.             ' * procedure name: cmdRender_Click
  496.             ' * procedure description:   occures when the user opts to connect the current graph, causing downstream pins to render
  497.             ' *
  498.             ' ******************************************************************************************************************************
  499.             Private Sub cmdRender_Click()
  500.             On Local Error GoTo ErrLine
  501.             'render the selected pin
  502.             m_objSelectedPin.Render
  503.             'update the ui
  504.             RefreshFilters
  505.             Exit Sub
  506.             
  507. ErrLine:
  508.             Err.Clear
  509.             Exit Sub
  510.             End Sub
  511.             
  512.             
  513.             
  514.             ' ******************************************************************************************************************************
  515.             ' * procedure name: cmdRender_Click
  516.             ' * procedure description:   Appends a source filter to the graph that can read the given filename.
  517.             ' *                                        Calls IMediaControl::AddSourceFilter
  518.             ' ******************************************************************************************************************************
  519.             Private Sub cmdSource_Click()
  520.             Dim nCount As Long
  521.             Dim objFilter As Object
  522.             On Local Error GoTo ErrLine
  523.             
  524.             'display the common dialog
  525.             ctrlCommonDlg.CancelError = False
  526.             ctrlCommonDlg.filter = "Media files (*.mpg;*.avi;*.mov)|*.mpg;*.avi;*.mov|"
  527.             ctrlCommonDlg.ShowOpen  ' open the source filter
  528.             'append the source filter given the file
  529.             If ctrlCommonDlg.FileName <> vbNullString Then
  530.                'verify that the filter has not already been appended to the list
  531.                For nCount = 0 To Me.listFilters.ListCount
  532.                      If LCase(listFilters.List(nCount)) = LCase(ctrlCommonDlg.FileName) Then
  533.                         'the item has already been appended to the list, so exit
  534.                         Exit Sub
  535.                      End If
  536.                Next
  537.                Call m_objMediaControl.AddSourceFilter(ctrlCommonDlg.FileName, objFilter)
  538.                RefreshFilters  ' update all info displayed by this VB app
  539.             End If
  540.             Exit Sub
  541.             
  542. ErrLine:
  543.             If Err.Number = 32755 Then Exit Sub
  544.             Err.Clear
  545.             Exit Sub
  546.             End Sub
  547.             
  548.             
  549.             
  550.             ' ******************************************************************************************************************************
  551.             ' * procedure name: RefreshFilters
  552.             ' * procedure description:   Refresh the contents of the "Filters" combo box using the current IMediaControl interface
  553.             ' *                                        Calls IMediaControl::AddSourceFilter
  554.             ' ******************************************************************************************************************************
  555.             Public Sub RefreshFilters()
  556.             Dim objFilter As IFilterInfo
  557.             On Local Error GoTo ErrLine
  558.             
  559.             'clear the listed filters
  560.             listFilters.Clear
  561.             'enumerate the current filters in the collection
  562.             For Each objFilter In m_objMediaControl.FilterCollection
  563.                 listFilters.AddItem objFilter.Name 'append the filter's name
  564.             Next
  565.             'select the filter
  566.             If listFilters.ListCount > 0 Then
  567.                 listFilters.ListIndex = 0  ' select first in list
  568.             End If
  569.             
  570.             'clean-up & dereference local data
  571.             If Not objFilter Is Nothing Then Set objFilter = Nothing
  572.             Exit Sub
  573.             
  574. ErrLine:
  575.             Err.Clear
  576.             Exit Sub
  577.             End Sub
  578.             
  579.             
  580.             
  581.             ' ******************************************************************************************************************************
  582.             ' * procedure name: listFilters_Click
  583.             ' * procedure description:   user clicked on a filter in the filters combo box or index; proceed to update pins..
  584.             ' *                                        when filling the listfilters listbox
  585.             ' ******************************************************************************************************************************
  586.             Private Sub listFilters_Click()
  587.             Dim objPinInfo As IPinInfo
  588.             Dim objFilterInfo As IFilterInfo
  589.             On Local Error GoTo ErrLine
  590.             
  591.             'update the pins listbox to show all of its pins
  592.             For Each objFilterInfo In m_objMediaControl.FilterCollection
  593.                 If objFilterInfo.Name = listFilters.Text Then
  594.                     Set m_objFilterInfo = objFilterInfo
  595.                     lblFilterName.Caption = objFilterInfo.Name
  596.                     lblVendorInfo.Caption = objFilterInfo.VendorInfo
  597.                     'clear the listbox
  598.                     listPins.Clear
  599.                     'append all of this filter's pins to the list box
  600.                     For Each objPinInfo In objFilterInfo.Pins
  601.                         listPins.AddItem objPinInfo.Name
  602.                     Next
  603.                 End If
  604.             Next
  605.             
  606.             ' select the first in the list
  607.             If listPins.ListCount > 0 Then
  608.                listPins.ListIndex = 0
  609.             End If
  610.             
  611.             'clean-up & dereference local data
  612.             If Not objPinInfo Is Nothing Then Set objPinInfo = Nothing
  613.             If Not objFilterInfo Is Nothing Then Set objFilterInfo = Nothing
  614.             Exit Sub
  615.             
  616. ErrLine:
  617.             Err.Clear
  618.             Exit Sub
  619.             End Sub
  620.             
  621.             
  622.             
  623.             ' ******************************************************************************************************************************
  624.             ' * procedure name: listPins_Click
  625.             ' * procedure description:   Proceed to Append detailed information on the selected pin to the textbox
  626.             ' *                                        This procedure is designed whereas it will encapsulate the error if the pin
  627.             ' *                                        cannot be connectedto, and still set the correct text.  This is by design.
  628.             ' ******************************************************************************************************************************
  629.             Private Sub listPins_Click()
  630.             Dim strSnippet As String
  631.             Dim objPinInfo As IPinInfo
  632.             Dim objPeerFilter As IFilterInfo
  633.             Dim objConnPinInfo As IPinInfo
  634.             Dim objMediaTypeInfo As IMediaTypeInfo
  635.             On Local Error GoTo ErrLine
  636.             
  637.             'enumerate throuch each pin
  638.             For Each objPinInfo In m_objFilterInfo.Pins
  639.                     
  640.                     If LCase(objPinInfo.Name) = LCase(listPins.Text) Then
  641.                        'reset the selected pin
  642.                        Set m_objSelectedPin = objPinInfo
  643.                        
  644.                        'attempt to obtain a reference to the connected pin;
  645.                        'always anticipating that an error could occure..
  646.                        Set objConnPinInfo = objPinInfo.ConnectedTo
  647.                        
  648.                        If Not objConnPinInfo Is Nothing Then
  649.                          'the above method completed without error, list the pin info..
  650.                          strSnippet = "Connected to pin: " + objConnPinInfo.Name + " "
  651.                          If Not objConnPinInfo Is Nothing Then
  652.                             If Not objConnPinInfo.FilterInfo Is Nothing Then
  653.                                Set objPeerFilter = objConnPinInfo.FilterInfo
  654.                                strSnippet = strSnippet + " on filter: " + objPeerFilter.Name + " "
  655.                                Set objMediaTypeInfo = objPinInfo.ConnectionMediaType
  656.                                strSnippet = strSnippet + vbCrLf + "Media Type: " + objMediaTypeInfo.Type
  657.                             End If
  658.                          End If
  659.                        End If
  660.                        
  661.                        'append info based upon pin direction..
  662.                        If objPinInfo.Direction = 0 Then
  663.                          strSnippet = strSnippet + " " + vbCrLf + "Direction: Input"
  664.                        Else:  strSnippet = strSnippet + " " + vbCrLf + "Direction: Output"
  665.                        End If
  666.                      'set the information to the textbox..
  667.                      txtPinInfo.Text = strSnippet
  668.                      End If
  669.             Next
  670.             
  671.             'clean-up & dereference local data
  672.             If Not objPinInfo Is Nothing Then Set objPinInfo = Nothing
  673.             If Not objPeerFilter Is Nothing Then Set objPeerFilter = Nothing
  674.             If Not objConnPinInfo Is Nothing Then Set objConnPinInfo = Nothing
  675.             If Not objMediaTypeInfo Is Nothing Then Set objMediaTypeInfo = Nothing
  676.             Exit Sub
  677.              
  678. ErrLine:
  679.             Err.Clear
  680.             Resume Next
  681.             End Sub
  682.             
  683.             
  684.             
  685.             ' ******************************************************************************************************************************
  686.             ' * procedure name: listRegFilters_DblClick
  687.             ' * procedure description:  Double click event for registered filters listbox; appends the filter to the current graph
  688.             ' *
  689.             ' ******************************************************************************************************************************
  690.             Private Sub listRegFilters_DblClick()
  691.             On Local Error GoTo ErrLine
  692.             cmdAddRegFilter_Click
  693.             Exit Sub
  694.              
  695. ErrLine:
  696.             Err.Clear
  697.             Resume Next
  698.             End Sub
  699.             
  700.             
  701.             ' ******************************************************************************************************************************
  702.             ' * procedure name: cmdPause_Click
  703.             ' * procedure description:  duplicates the functionality of "Pause" under the FilterGraph menu
  704.             ' *
  705.             ' ******************************************************************************************************************************
  706.             Private Sub cmdPause_Click()
  707.             On Local Error GoTo ErrLine
  708.             Call mnu_FilterGraphPause_Click
  709.             Exit Sub
  710.             
  711. ErrLine:
  712.             Err.Clear
  713.             Exit Sub
  714.             End Sub
  715.             
  716.             
  717.             ' ******************************************************************************************************************************
  718.             ' * procedure name: cmdRun_Click
  719.             ' * procedure description:   duplicates the functionality of "Run" under the FilterGraph menu
  720.             ' *
  721.             ' ******************************************************************************************************************************
  722.             Private Sub cmdRun_Click()
  723.             On Local Error GoTo ErrLine
  724.             Call mnu_FilterGraphRun_Click
  725.             Exit Sub
  726.             
  727. ErrLine:
  728.             Err.Clear
  729.             Exit Sub
  730.             End Sub
  731.             
  732.             
  733.             ' ******************************************************************************************************************************
  734.             ' * procedure name: cmdStop_Click
  735.             ' * procedure description:   duplicates the functionality of "Stop" under the FilterGraph menu
  736.             ' *
  737.             ' ******************************************************************************************************************************
  738.             Private Sub cmdStop_Click()
  739.             On Local Error GoTo ErrLine
  740.             Call mnu_FilterGraphStop_Click
  741.             Exit Sub
  742.             
  743. ErrLine:
  744.             Err.Clear
  745.             Exit Sub
  746.             End Sub
  747.             
  748.             
  749.             
  750.             
  751. ' **************************************************************************************************************************************
  752. ' * PRIVATE INTERFACE- INTRINSIC MENU EVENT HANDLERS
  753.             ' ******************************************************************************************************************************
  754.             ' * procedure name: mnu_FilterGraphExit_Click
  755.             ' * procedure description:
  756.             ' *
  757.             ' ******************************************************************************************************************************
  758.             Private Sub mnu_FilterGraphExit_Click()
  759.             Dim frm As Form
  760.             On Local Error GoTo ErrLine
  761.             
  762.             'exit application
  763.             For Each frm In Forms
  764.                frm.Visible = False: Unload frm
  765.             Next
  766.             Exit Sub
  767.             
  768. ErrLine:
  769.             Err.Clear
  770.             Exit Sub
  771.             End Sub
  772.             
  773.             
  774.             ' ******************************************************************************************************************************
  775.             ' * procedure name: mnu_FilterGraphGenerate_Click
  776.             ' * procedure description:    User is initializing the filter graph based on a source file
  777.             ' *                                         Create a new filter graph and then get all filters, connections
  778.             ' ******************************************************************************************************************************
  779.             Private Sub mnu_FilterGraphGenerate_Click()
  780.             On Local Error GoTo ErrLine
  781.             
  782.             ' reset the application's module-level objects
  783.             If Not m_objFilterInfo Is Nothing Then Set m_objFilterInfo = Nothing
  784.             If Not m_objSelectedPin Is Nothing Then Set m_objSelectedPin = Nothing
  785.             If Not m_objRegFilterInfo Is Nothing Then Set m_objRegFilterInfo = Nothing
  786.             If Not m_objMediaControl Is Nothing Then Set m_objMediaControl = Nothing
  787.             
  788.             ' reinitialize the display
  789.             listFilters.Clear: listPins.Clear: txtPinInfo.Text = ""
  790.             
  791.             ' create a new IMediaControl object
  792.             Set m_objMediaControl = New FilgraphManager
  793.             
  794.             ' refresh the display for registered filters
  795.             If Not m_objMediaControl Is Nothing Then
  796.                If Not m_objMediaControl.RegFilterCollection Is Nothing Then
  797.                   Set m_objRegFilterInfo = m_objMediaControl.RegFilterCollection
  798.                   Call RefreshRegFilters
  799.                End If
  800.             End If
  801.            
  802.             ' use the common dialog to let the user select the input file
  803.             ctrlCommonDlg.CancelError = False
  804.             ctrlCommonDlg.filter = "Media files (*.mpg;*.avi;*.mov;*.wav)|*.mpg;*.avi;*.mov;*.wav|"
  805.             ctrlCommonDlg.ShowOpen
  806.            
  807.             ' call IMediaControl::RenderFile to add all filters and connect all pins
  808.             If ctrlCommonDlg.FileName <> vbNullString Then
  809.                m_objMediaControl.RenderFile ctrlCommonDlg.FileName
  810.                Call RefreshFilters  'update the ui
  811.             End If
  812.             Exit Sub
  813.            
  814. ErrLine:
  815.             Err.Clear
  816.             Exit Sub
  817.             End Sub
  818.             
  819.             
  820.             ' ******************************************************************************************************************************
  821.             ' * procedure name: mnu_FilterGraphNew_Click
  822.             ' * procedure description:    User wants to start with a fresh filter graph so proceed to reset the app.
  823.             ' *                                         Create a new filter graph and then reset all filters, pins, and connections
  824.             ' ******************************************************************************************************************************
  825.             Private Sub mnu_FilterGraphNew_Click()
  826.             On Local Error GoTo ErrLine
  827.             
  828.             ' reset the application's module-level objects
  829.             If Not m_objFilterInfo Is Nothing Then Set m_objFilterInfo = Nothing
  830.             If Not m_objSelectedPin Is Nothing Then Set m_objSelectedPin = Nothing
  831.             If Not m_objRegFilterInfo Is Nothing Then Set m_objRegFilterInfo = Nothing
  832.             If Not m_objMediaControl Is Nothing Then Set m_objMediaControl = Nothing
  833.            
  834.            ' create a new IMediaControl object
  835.            Set m_objMediaControl = New FilgraphManager
  836.            
  837.             ' refresh the display for registered filters
  838.             If Not m_objMediaControl Is Nothing Then
  839.                If Not m_objMediaControl.RegFilterCollection Is Nothing Then
  840.                   Set m_objRegFilterInfo = m_objMediaControl.RegFilterCollection
  841.                   Call RefreshRegFilters
  842.                End If
  843.             End If
  844.             
  845.             ' clear the contents of the listboxes, textboxes, and labels
  846.             listFilters.Clear: listPins.Clear
  847.             txtPinInfo.Text = vbNullString: lblFilterName.Caption = vbNullString: lblVendorInfo.Caption = vbNullString
  848.             
  849.             ' set the current playback state to stopped
  850.             m_GraphState = StateStopped
  851.             Exit Sub
  852.            
  853. ErrLine:
  854.             Err.Clear
  855.             Exit Sub
  856.             End Sub
  857.             
  858.             
  859.             
  860.             ' ******************************************************************************************************************************
  861.             ' * procedure name: mnu_FilterGraphPause_Click
  862.             ' * procedure description:    Pauses rendering using the IMediaControl interface
  863.             ' *
  864.             ' ******************************************************************************************************************************
  865.             Private Sub mnu_FilterGraphPause_Click()
  866.             On Local Error GoTo ErrLine
  867.             If Not m_objMediaControl Is Nothing Then
  868.                If m_GraphState = StateStopped Then Exit Sub
  869.                Call m_objMediaControl.Pause
  870.                m_GraphState = StatePaused
  871.             End If
  872.             Exit Sub
  873.            
  874. ErrLine:
  875.             Err.Clear
  876.             Exit Sub
  877.             End Sub
  878.             
  879.             
  880.             
  881.             ' ******************************************************************************************************************************
  882.             ' * procedure name: mnu_FilterGraphRun_Click
  883.             ' * procedure description:   Sets the playback state dependent on the current rendering state of the graph
  884.             ' *
  885.             ' ******************************************************************************************************************************
  886.             Private Sub mnu_FilterGraphRun_Click()
  887.             Dim objPosition As IMediaPosition
  888.             On Local Error GoTo ErrLine
  889.             
  890.             
  891.             Select Case m_GraphState
  892.             
  893.                    Case GraphState.StateStopped
  894.                             If Not m_objMediaControl Is Nothing Then
  895.                                'obtain the current position
  896.                                Set objPosition = m_objMediaControl
  897.                                'reset the position to zero
  898.                                objPosition.CurrentPosition = 0
  899.                                'set state to running
  900.                                m_objMediaControl.Run
  901.                                'reset module-level variable
  902.                                m_GraphState = StateRunning
  903.                             End If
  904.                    
  905.                    
  906.                    Case GraphState.StatePaused
  907.                             If Not m_objMediaControl Is Nothing Then
  908.                                'set state back to running
  909.                                m_objMediaControl.Run
  910.                                'reset module-level variable
  911.                                m_GraphState = StateRunning
  912.                             End If
  913.                             
  914.                             
  915.                    Case GraphState.StateRunning
  916.                             If Not m_objMediaControl Is Nothing Then
  917.                                'obtain the current position
  918.                                Set objPosition = m_objMediaControl
  919.                                
  920.                                If CLng(objPosition.CurrentPosition) = CLng(objPosition.Duration) Then
  921.                                   'end of media reached, restart
  922.                                   objPosition.CurrentPosition = 0
  923.                                   'set state to running
  924.                                   m_objMediaControl.Run
  925.                                   'reset module-level variable
  926.                                   m_GraphState = StateRunning
  927.                                   
  928.                                ElseIf CLng(objPosition.CurrentPosition) <> CLng(objPosition.Duration) Then
  929.                                   'playback in progress, restart
  930.                                   objPosition.CurrentPosition = 0
  931.                                   'set state to running
  932.                                   m_objMediaControl.Run
  933.                                   'reset module-level variable
  934.                                   m_GraphState = StateRunning
  935.                                   
  936.                                ElseIf CLng(objPosition.CurrentPosition) = 0 Then
  937.                                   'playback ready, start
  938.                                   m_objMediaControl.Run
  939.                                   'reset module-level variable
  940.                                   m_GraphState = StateRunning
  941.                                End If
  942.                             End If
  943.                             
  944.             End Select
  945.             
  946.             'clean-up & dereference local data
  947.             If Not objPosition Is Nothing Then Set objPosition = Nothing
  948.             Exit Sub
  949.             
  950. ErrLine:
  951.             Err.Clear
  952.             Exit Sub
  953.             End Sub
  954.             
  955.             
  956.             ' ******************************************************************************************************************************
  957.             ' * procedure name: mnu_FilterGraphStop_Click
  958.             ' * procedure description:    Stops rendering using the IMediaControl interface
  959.             ' *
  960.             ' ******************************************************************************************************************************
  961.             Private Sub mnu_FilterGraphStop_Click()
  962.             On Local Error GoTo ErrLine
  963.             If Not m_objMediaControl Is Nothing Then
  964.                Call m_objMediaControl.Stop
  965.                m_GraphState = StateStopped
  966.             End If
  967.             Exit Sub
  968.            
  969. ErrLine:
  970.             Err.Clear
  971.             Exit Sub
  972.             End Sub
  973.             
  974.             
  975.             
  976.             ' ******************************************************************************************************************************
  977.             ' * procedure name: mnu_BuildCustomGraph_Click
  978.             ' * procedure description:  allows the user to build a custom graph
  979.             ' *
  980.             ' *                                       This routine demonstrates a likely common use
  981.             ' *                                       of these methods in Visual Basic applications:
  982.             ' *                                       Directly creating the filter graph needed
  983.             ' *                                       for a specific multimedia file.
  984.             ' *                                       The graph has the following filters: AVI Source, AVI Decompressor,
  985.             ' *                                       Video Renderer, AVI Splitter, and Audio Renderer.
  986.             ' *                                       Note that these filters can be connected by reusing just
  987.             ' *                                       two pin object variables, but for clarity of the example,
  988.             ' *                                       all are defined using names that reflect their position
  989.             ' *                                       in the filter graph.
  990.             ' *                                       The filters are declared with their pins, as follows:
  991.             ' *
  992.             ' ******************************************************************************************************************************
  993.             Private Sub mnu_BuildCustomGraph_Click()
  994.             Dim pPin As IPinInfo
  995.             Dim pSourceFilter As IFilterInfo  ' AVI source filter; has two pins
  996.             Dim SourceOutputPin As IPinInfo  'Source Filter output pin
  997.             Dim pAVISplitter As IFilterInfo ' AVI splitter
  998.             Dim SplitterInPin As IPinInfo   ' AVI splitter pin "Input"
  999.             Dim SplitterOut00Pin As IPinInfo  ' AVI splitter pin "Stream 00"
  1000.             Dim SplitterOut01Pin As IPinInfo  ' AVI splitter pin "Stream 01"
  1001.             Dim pDECFilter As IFilterInfo  ' AVI Decompressor; has two pins
  1002.             Dim DECInPin As IPinInfo   'AVI Decompressor pin "XForm In"
  1003.             Dim DECOutPin As IPinInfo   ' AVI Decompressor pin "XForm Out"
  1004.             Dim pVidRenderer As IFilterInfo ' Video renderer, has one pin
  1005.             Dim VidRendInPin As IPinInfo  ' Video Renderer pin "Input"
  1006.             Dim pAudioRenderer As IFilterInfo 'Audio renderer, has one pin
  1007.             Dim AudioRendInPin As IPinInfo ' Audio Renderer pin "Input"
  1008.             On Local Error GoTo ErrLine
  1009.             
  1010.             ' reinitialize all global variables
  1011.             If Not m_objRegFilterInfo Is Nothing Then Set m_objRegFilterInfo = Nothing
  1012.             If Not m_objFilterInfo Is Nothing Then Set m_objFilterInfo = Nothing
  1013.             If Not m_objSelectedPin Is Nothing Then Set m_objSelectedPin = Nothing
  1014.             If Not m_objMediaControl Is Nothing Then Set m_objMediaControl = Nothing
  1015.             
  1016.             ' create a new IMediaControl object
  1017.             Set m_objMediaControl = New FilgraphManager
  1018.             ' reset the listRegFilters again
  1019.             Set m_objRegFilterInfo = m_objMediaControl.RegFilterCollection
  1020.             
  1021.             'refresh reg filter list
  1022.             RefreshRegFilters
  1023.             
  1024.             ' reinitialize the display
  1025.             listFilters.Clear: listPins.Clear
  1026.             lblFilterName.Caption = vbNullString: lblVendorInfo.Caption = vbNullString
  1027.             txtPinInfo.Text = vbNullString: m_GraphState = StateStopped 'update state
  1028.                 
  1029.             'Add source filter for an AVI file
  1030.             ctrlCommonDlg.CancelError = False
  1031.             ctrlCommonDlg.filter = "AVI files (*.avi)|*.avi"
  1032.             ctrlCommonDlg.ShowOpen  ' get the name of the source or filter graph file
  1033.             
  1034.             'verify the user's input and proceed..
  1035.             If ctrlCommonDlg.FileName <> vbNullString Then
  1036.                 m_objMediaControl.AddSourceFilter ctrlCommonDlg.FileName, pSourceFilter
  1037.             Else:  Exit Sub
  1038.             End If
  1039.             
  1040.             ' Get the pins we need to connect
  1041.             For Each pPin In pSourceFilter.Pins
  1042.               Debug.Print pPin.Name
  1043.               If pPin.Name = "Output" Then
  1044.                   Set SourceOutputPin = pPin
  1045.               End If
  1046.             Next
  1047.             
  1048.             'Add DEC filter
  1049.             If Not pDECFilter Is Nothing Then
  1050.                AppendFilter "AVI Decompressor", pDECFilter
  1051.             End If
  1052.             
  1053.             'Print out list of pins on decompressor filter
  1054.             If Not pDECFilter Is Nothing Then
  1055.                If Not pDECFilter.Pins Is Nothing Then
  1056.                   For Each pPin In pDECFilter.Pins
  1057.                     Debug.Print pPin.Name
  1058.                     ' save specific pins to connect them
  1059.                     If pPin.Name = "XForm In" Then
  1060.                         Set DECInPin = pPin
  1061.                     End If
  1062.                     If pPin.Name = "XForm Out" Then
  1063.                         Set DECOutPin = pPin
  1064.                     End If
  1065.                   Next
  1066.               End If
  1067.             End If
  1068.             
  1069.             'Add AVI Splitter
  1070.             If Not pAVISplitter Is Nothing Then
  1071.                AppendFilter "AVI Splitter", pAVISplitter
  1072.             End If
  1073.             
  1074.             'Print out list of pins on decompressor filter
  1075.             If Not pAVISplitter Is Nothing Then
  1076.                If Not pAVISplitter.Pins Is Nothing Then
  1077.                   For Each pPin In pAVISplitter.Pins
  1078.                     Debug.Print pPin.Name
  1079.                     ' save specific pins to connect them
  1080.                     ' pin 0, pin 1
  1081.                     If pPin.Name = "input pin" Then
  1082.                         Set SplitterInPin = pPin
  1083.                     ElseIf pPin.Name = "Stream 00" Then
  1084.                         Set SplitterOut00Pin = pPin
  1085.                     ElseIf pPin.Name = "Stream 01" Then
  1086.                         Set SplitterOut01Pin = pPin
  1087.                     End If
  1088.                   Next
  1089.               End If
  1090.             End If
  1091.             
  1092.             'Connect Source video output pin to AVI splitter input pin
  1093.             If Not SourceOutputPin Is Nothing And Not SplitterInPin Is Nothing Then
  1094.                 SourceOutputPin.Connect SplitterInPin
  1095.             End If
  1096.          
  1097.             ' Splitter now knows how many output pins it needs
  1098.             If Not pAVISplitter Is Nothing Then
  1099.                If Not pAVISplitter.Pins Is Nothing Then
  1100.                   For Each pPin In pAVISplitter.Pins
  1101.                     Debug.Print pPin.Name
  1102.                     ' save specific pins to connect them
  1103.                     ' pin 0, pin 1
  1104.                     If pPin.Name = "Stream 00" Then
  1105.                         Set SplitterOut00Pin = pPin
  1106.                     ElseIf pPin.Name = "Stream 01" Then
  1107.                         Set SplitterOut01Pin = pPin
  1108.                     End If
  1109.                   Next
  1110.                End If
  1111.             End If
  1112.             
  1113.             'Add Video Renderer filter and set its pin variables
  1114.             AppendFilter "Video Renderer", pVidRenderer
  1115.             'Print out list of pins on video renderer filter
  1116.             For Each pPin In pVidRenderer.Pins
  1117.               Debug.Print pPin.Name
  1118.               If pPin.Name = "Input" Then
  1119.                   Set VidRendInPin = pPin
  1120.               End If
  1121.             Next
  1122.             
  1123.             'Add Audio Renderer filter and set its pin variables
  1124.             AppendFilter "Audio Renderer", pAudioRenderer
  1125.             'Print out list of pins on audioo renderer filter
  1126.             For Each pPin In pAudioRenderer.Pins
  1127.               Debug.Print pPin.Name
  1128.               If InStr(pPin.Name, "Input") Then
  1129.                   Set AudioRendInPin = pPin
  1130.               End If
  1131.             Next
  1132.             
  1133.             
  1134.             ' Connect AVI splitter stream 01 to AVI decompressor
  1135.             If Not DECInPin Is Nothing And SplitterOut00Pin Is Nothing Then
  1136.                 SplitterOut00Pin.Connect DECInPin
  1137.             End If
  1138.             
  1139.             'Connect DEC filter output pin to Video Renderer input pin
  1140.             If Not DECOutPin Is Nothing And Not VidRendInPin Is Nothing Then
  1141.                 DECOutPin.Connect VidRendInPin
  1142.             End If
  1143.             
  1144.             ' Connect AVI splitter stream 01 to audio renderer
  1145.             ' continue if there is no audio connection for the source AVI file
  1146.             If Not AudioRendInPin Is Nothing And SplitterOut01Pin Is Nothing Then
  1147.                 SplitterOut01Pin.Connect AudioRendInPin
  1148.             End If
  1149.             
  1150.             'refresh
  1151.             RefreshFilters
  1152.             Exit Sub
  1153.             
  1154.             
  1155. ErrLine:
  1156.             If Err.Number = 32755 Then Exit Sub
  1157.             MsgBox "Could not create the custom filter graph. Please select an .AVI file that uses the AVI splitter and AVI decompressor filters."
  1158.             Exit Sub
  1159.             End Sub
  1160.