home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Game Programming for Teens / VBGPFT.cdr / DirectX8 / dx8vbsdk.exe / samples / multimedia / vbsamples / directshow / editing / trimmervb / modgeneral.bas < prev    next >
Encoding:
BASIC Source File  |  2000-09-22  |  17.1 KB  |  339 lines

  1. Attribute VB_Name = "modGeneral"
  2. '*******************************************************************************
  3. '*       This is a part of the Microsoft DXSDK Code Samples.
  4. '*       Copyright (C) 1999-2000 Microsoft Corporation.
  5. '*       All rights reserved.
  6. '*       This source code is only intended as a supplement to
  7. '*       Microsoft Development Tools and/or SDK documentation.
  8. '*       See these sources for detailed information regarding the
  9. '*       Microsoft samples programs.
  10. '*******************************************************************************
  11. Option Explicit
  12. Option Base 0
  13. Option Compare Text
  14.  
  15.  
  16.  
  17. ' **************************************************************************************************************************************
  18. ' * PUBLIC INTERFACE- WIN32 API CONSTANTS
  19. ' *
  20. ' *
  21.             Public Const FO_COPY = &H2
  22.             Public Const FO_DELETE = &H3
  23.             Public Const FO_MOVE = &H1
  24.             Public Const FO_RENAME = &H4
  25.             Public Const FOF_ALLOWUNDO = &H40
  26.             Public Const FOF_CONFIRMMOUSE = &H2
  27.             Public Const FOF_FILESONLY = &H80      ''"" on *.*, do only files
  28.             Public Const FOF_MULTIDESTFILES = &H1
  29.             Public Const FOF_NOCONFIRMATION = &H10      ''"" Don't prompt the user.
  30.             Public Const FOF_NOCONFIRMMKDIR = &H200     ''"" don't confirm making any needed dirs
  31.             Public Const FOF_NOCOPYSECURITYATTRIBS = &H800     ''"" dont copy NT file Security Attributes
  32.             Public Const FOF_NOERRORUI = &H400     ''"" don't put up error UI
  33.             Public Const FOF_NORECURSION = &H1000    ''"" don't recurse into directories.
  34.             Public Const FOF_NO_CONNECTED_ELEMENTS = &H2000    ''"" don't operate on connected file elements.
  35.             Public Const FOF_RENAMEONCOLLISION = &H8
  36.             Public Const FOF_SILENT = &H4       ''"" don't create progress"report
  37.             Public Const FOF_SIMPLEPROGRESS = &H100     ''"" means don't show names of files
  38.             Public Const FOF_WANTMAPPINGHANDLE = &H20      ''"" Fill in SHFILEOPSTRUCT.hNameMappings
  39.             Private Const MAX_PATH As Long = 255
  40.             Private Const INVALID_HANDLE_VALUE = -1
  41.             Private Const SEM_FAILCRITICALERRORS = &H1
  42.             Private Const SEM_NOOPENFILEERRORBOX = &H8000
  43.  
  44.  
  45. ' **************************************************************************************************************************************
  46. ' * PUBLIC INTERFACE- WIN32 API DATA STRUCTURES
  47. ' *
  48. ' *
  49.             Private Type FILETIME
  50.                     dwLowDateTime As Long
  51.                     dwHighDateTime As Long
  52.             End Type
  53.             
  54.             Public Type WIN32_FIND_DATA
  55.                     dwFileAttributes As Long
  56.                     ftCreationTime As FILETIME
  57.                     ftLastAccessTime As FILETIME
  58.                     ftLastWriteTime As FILETIME
  59.                     nFileSizeHigh As Long
  60.                     nFileSizeLow As Long
  61.                     dwReserved0 As Long
  62.                     dwReserved1 As Long
  63.                     cFileName As String * MAX_PATH
  64.                     cAlternate As String * 14
  65.             End Type
  66.             
  67.             Private Type SHFILEOPSTRUCT
  68.                     hWnd As Long
  69.                     wFunc As Long
  70.                     pFrom As String
  71.                     pTo As String
  72.                     fFlags As Integer
  73.                     fAnyOperationsAborted As Long
  74.                     hNameMappings As Long
  75.                     lpszProgressTitle As String '  only used if FOF_SIMPLEPROGRESS
  76.             End Type
  77.  
  78.  
  79. ' **************************************************************************************************************************************
  80. ' * PUBLIC INTERFACE- WIN32 API DECLARATIONS
  81. ' *
  82. ' *
  83.             Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
  84.             Private Declare Function SetErrorMode Lib "kernel32" (ByVal wMode As Long) As Long
  85.             Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
  86.             Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
  87.             Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
  88.  
  89.  
  90.  
  91.  
  92.  
  93. ' **************************************************************************************************************************************
  94. ' * PUBLIC INTERFACE- DEXTER PROCEDURES
  95. ' *
  96. ' *
  97.             ' ******************************************************************************************************************************
  98.             ' * procedure name: GetPinInfo
  99.             ' * procedure description:  Returns an IPinInfo interface given a filtergraph manager and IPin object.
  100.             ' *                                       The derived IPinInfo interface can be utilized for gaining information on the elected pin.
  101.             ' ******************************************************************************************************************************
  102.             Public Function GetPinInfo(objFilterGraphManager As FilgraphManager, objPin As IPin) As IPinInfo
  103.             Dim objPin2 As IPin
  104.             Dim objPinInfo As IPinInfo
  105.             Dim objFilterInfo As IFilterInfo
  106.             Dim objPinCollection As Object
  107.             Dim objlFilterCollection As Object
  108.             On Local Error GoTo ErrLine
  109.             
  110.             'derive a filter collection from the filtergraph manager
  111.             Set objlFilterCollection = objFilterGraphManager.FilterCollection
  112.             
  113.             'enumerate through the filter(s) in the collection
  114.             For Each objFilterInfo In objlFilterCollection
  115.                 Set objPinCollection = objFilterInfo.Pins
  116.                 For Each objPinInfo In objPinCollection
  117.                     Set objPin2 = objPinInfo.Pin
  118.                     If objPin2 Is objPin Then
  119.                         Set GetPinInfo = objPinInfo
  120.                         Exit Function
  121.                     End If
  122.                 Next
  123.             Next
  124.             
  125.             'clean-up & dereference
  126.             If ObjPtr(objPin2) > 0 Then Set objPin2 = Nothing
  127.             If ObjPtr(objPinInfo) > 0 Then Set objPinInfo = Nothing
  128.             If ObjPtr(objFilterInfo) > 0 Then Set objFilterInfo = Nothing
  129.             If ObjPtr(objPinCollection) > 0 Then Set objPinCollection = Nothing
  130.             If ObjPtr(objlFilterCollection) > 0 Then Set objlFilterCollection = Nothing
  131.             Exit Function
  132.             
  133. ErrLine:
  134.             Err.Clear
  135.             Exit Function
  136.             End Function
  137.             
  138.             
  139.             ' ******************************************************************************************************************************
  140.             ' * procedure name: AddFileWriterAndMux
  141.             ' * procedure description:  Appends a filewriter and mux filter to the given filtergraph.
  142.             ' *                                       The FileName as required for the filewriter and evaluates to the output file destination.
  143.             ' ******************************************************************************************************************************
  144.             Public Sub AddFileWriterAndMux(objFilterGraphManager As FilgraphManager, bstrFileName As String)
  145.             Dim objFilterInfo As IFilterInfo
  146.             Dim objRegisteredFilters As Object
  147.             Dim objAVIMuxFilterInfo As IFilterInfo
  148.             Dim objRegFilterInfo As IRegFilterInfo
  149.             Dim objFileSinkFilterVB As IFileSinkFilterForVB
  150.             On Local Error GoTo ErrLine
  151.             
  152.             'derive a collection of registered filters from the filtergraph manager
  153.             Set objRegisteredFilters = objFilterGraphManager.RegFilterCollection
  154.             
  155.             'enumerate through the registered filters
  156.             For Each objRegFilterInfo In objRegisteredFilters
  157.                 If Trim(LCase(objRegFilterInfo.Name)) = "file writer" Then
  158.                     objRegFilterInfo.Filter objFilterInfo
  159.                 ElseIf Trim(LCase(objRegFilterInfo.Name)) = "avi mux" Then
  160.                     objRegFilterInfo.Filter objAVIMuxFilterInfo
  161.                 End If
  162.             Next
  163.             
  164.             'derive the file sink filter tailored for vb
  165.             Set objFileSinkFilterVB = objFilterInfo.Filter
  166.             'assign the filename to the sink filter
  167.             Call objFileSinkFilterVB.SetFileName(bstrFileName, Nothing)
  168.             
  169.             'clean-up & dereference
  170.             If ObjPtr(objFilterInfo) > 0 Then Set objFilterInfo = Nothing
  171.             If ObjPtr(objRegFilterInfo) > 0 Then Set objRegFilterInfo = Nothing
  172.             If ObjPtr(objFileSinkFilterVB) > 0 Then Set objFileSinkFilterVB = Nothing
  173.             If ObjPtr(objAVIMuxFilterInfo) > 0 Then Set objAVIMuxFilterInfo = Nothing
  174.             If ObjPtr(objRegisteredFilters) > 0 Then Set objRegisteredFilters = Nothing
  175.             Exit Sub
  176.             
  177. ErrLine:
  178.             Err.Clear
  179.             Exit Sub
  180.             End Sub
  181.             
  182.             
  183.             ' ******************************************************************************************************************************
  184.             ' * procedure name: RenderGroupPins
  185.             ' * procedure description:  Renders the Pins out for the given timeline using the given render engine.
  186.             ' *
  187.             ' ******************************************************************************************************************************
  188.             Public Sub RenderGroupPins(objRenderEngine As RenderEngine, objTimeline As AMTimeline)
  189.             Dim objPin As IPin
  190.             Dim nCount As Long
  191.             Dim nGroupCount As Long
  192.             Dim objPinInfo As IPinInfo
  193.             Dim objFilterGraphManager As FilgraphManager
  194.             On Local Error GoTo ErrLine
  195.             
  196.             If ObjPtr(objTimeline) > 0 Then
  197.                If ObjPtr(objRenderEngine) > 0 Then
  198.                   'obtain the group count
  199.                   objTimeline.GetGroupCount nGroupCount
  200.                   'exit the procedure if there are no group(s)
  201.                   If nGroupCount = 0 Then Exit Sub
  202.                   'obtain the filtergraph
  203.                   objRenderEngine.GetFilterGraph objFilterGraphManager
  204.                   'enumerate through the groups & render the pins
  205.                    For nCount = 0 To nGroupCount - 1
  206.                        objRenderEngine.GetGroupOutputPin nCount, objPin
  207.                        If ObjPtr(objPin) > 0 Then
  208.                            Set objPinInfo = GetPinInfo(objFilterGraphManager, objPin)
  209.                            If ObjPtr(objPinInfo) > 0 Then
  210.                                Call objPinInfo.Render
  211.                            End If
  212.                        End If
  213.                    Next
  214.                End If
  215.             End If
  216.             Exit Sub
  217.             
  218. ErrLine:
  219.             Err.Clear
  220.             Resume Next
  221.             Exit Sub
  222.             End Sub
  223.             
  224.             
  225.             
  226. ' **************************************************************************************************************************************
  227. ' * PUBLIC INTERFACE- GENERAL PROCEDURES
  228. ' *
  229. ' *
  230.             ' ******************************************************************************************************************************
  231.             ' * procedure name: Buffer_ParseEx
  232.             ' * procedure description:   Parse's a fixed length string buffer of all vbNullCharacters AND vbNullStrings.
  233.             ' *                                        Argument bstrBuffer evaluates to either an ANSII or Unicode BSTR string buffer.
  234.             ' *                                        (bstrBuffer is almost always the output from a windows api call which needs parsed)
  235.             ' *
  236.             ' ******************************************************************************************************************************
  237.             Public Function Buffer_ParseEx(bstrBuffer As String) As String
  238.             Dim iCount As Long, bstrChar As String, bstrReturn As String
  239.             On Local Error GoTo ErrLine
  240.             
  241.             For iCount = 1 To Len(bstrBuffer) 'set up a loop to remove the vbNullChar's from the buffer.
  242.                   bstrChar = Strings.Mid(bstrBuffer, iCount, 1)
  243.                   If bstrChar <> vbNullChar And bstrChar <> vbNullString Then bstrReturn = (bstrReturn + bstrChar)
  244.             Next
  245.             Buffer_ParseEx = bstrReturn
  246.             Exit Function
  247.             
  248. ErrLine:
  249.             Err.Clear
  250.             Exit Function
  251.             End Function
  252.             
  253.             
  254.             ' ******************************************************************************************************************************
  255.             ' * procedure name: GetTempDirectory
  256.             ' * procedure description:  Returns a bstr String representing the fully qualified path to the system's temp directory
  257.             ' *
  258.             ' ******************************************************************************************************************************
  259.             Public Function GetTempDirectory() As String
  260.             Dim bstrBuffer As String * MAX_PATH
  261.             On Local Error GoTo ErrLine
  262.             
  263.             'call the win32api
  264.             Call GetTempPath(MAX_PATH, bstrBuffer)
  265.             'parse & return the value to the client
  266.             GetTempDirectory = Buffer_ParseEx(bstrBuffer)
  267.             Exit Function
  268.             
  269. ErrLine:
  270.             Err.Clear
  271.             Exit Function
  272.             End Function
  273.             
  274.             
  275.             
  276.             ' ******************************************************************************************************************************
  277.             ' * procedure name: File_Exists
  278.             ' * procedure description:  Returns true if the specified file does in fact exist.
  279.             ' *
  280.             ' ******************************************************************************************************************************
  281.             Public Function File_Exists(bstrFileName As String) As Boolean
  282.             Dim WFD As WIN32_FIND_DATA, hFile As Long
  283.             On Local Error GoTo ErrLine
  284.             
  285.             hFile = FindFirstFile(bstrFileName, WFD)
  286.             File_Exists = hFile <> INVALID_HANDLE_VALUE
  287.             Call FindClose(hFile)
  288.             Exit Function
  289.             
  290. ErrLine:
  291.             Err.Clear
  292.             Exit Function
  293.             End Function
  294.             
  295.             
  296.             ' ******************************************************************************************************************************
  297.             ' * procedure name: File_Delete
  298.             ' * procedure description:  This will delete a File. Pass any of the specified optionals to invoke those particular features.
  299.             ' *
  300.             ' ******************************************************************************************************************************
  301.             Public Function File_Delete(bstrFileName As String, Optional SendToRecycleBin As Boolean = True, Optional Confirm As Boolean = True, Optional ShowProgress As Boolean = True) As Long
  302.             Dim fileop As SHFILEOPSTRUCT
  303.             Dim WFD As WIN32_FIND_DATA, hFile As Long
  304.             On Local Error GoTo ErrLine
  305.             
  306.             'check argument
  307.             If Right(bstrFileName, 1) = "\" Then bstrFileName = Left(bstrFileName, (Len(bstrFileName) - 1))
  308.             'ensure the file exists
  309.             hFile = FindFirstFile(bstrFileName, WFD)
  310.             If hFile = INVALID_HANDLE_VALUE Then
  311.                Call FindClose(hFile)
  312.                Exit Function
  313.             Else: Call FindClose(hFile)
  314.             End If
  315.             'set the error mode
  316.             Call SetErrorMode(SEM_NOOPENFILEERRORBOX + SEM_FAILCRITICALERRORS)
  317.             'set up the file operation by the specified optionals
  318.             With fileop
  319.                 .hWnd = 0: .wFunc = FO_DELETE
  320.                 .pFrom = UCase(bstrFileName) & vbNullChar & vbNullChar
  321.                 If SendToRecycleBin Then   'goes to recycle bin
  322.                    .fFlags = FOF_ALLOWUNDO
  323.                    If Confirm = False Then .fFlags = .fFlags + FOF_NOCONFIRMATION  'do not confirm
  324.                    If ShowProgress = False Then .fFlags = .fFlags + FOF_SILENT  'do not show progress
  325.                 Else 'just delete the file
  326.                    If Confirm = False Then .fFlags = .fFlags + FOF_NOCONFIRMATION  'do not confirm
  327.                    If ShowProgress = False Then .fFlags = .fFlags + FOF_SILENT  'do not show progress
  328.                 End If
  329.             End With
  330.             'execute the file operation, return any errors..
  331.             File_Delete = SHFileOperation(fileop)
  332.             Exit Function
  333.             
  334. ErrLine:
  335.             File_Delete = Err.Number  'if there was a abend in the procedure, return that too..
  336.             Err.Clear
  337.             Exit Function
  338.             End Function
  339.