home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Game Programming for Teens / VBGPFT.cdr / DirectX8 / dx8vbsdk.exe / samples / multimedia / vbsamples / directshow / editing / slideshowvb / modgeneral.bas < prev    next >
Encoding:
BASIC Source File  |  2000-09-22  |  22.1 KB  |  454 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.             ' * procedure name: TransitionFriendlyNameToProgID
  228.             ' * procedure description:  Returns the programmatic identifier for the given transition friendly name
  229.             ' *
  230.             ' ******************************************************************************************************************************
  231.             Public Function TransitionFriendlyNameToProgID(bstrTransitionFriendlyName As String) As String
  232.             On Local Error GoTo ErrLine
  233.             
  234.             Select Case LCase(Trim(bstrTransitionFriendlyName))
  235.                 Case "default"
  236.                          TransitionFriendlyNameToProgID = "DxtJpegDll.DxtJpeg"
  237.                 Case "slide"
  238.                          TransitionFriendlyNameToProgID = "DXImageTransform.Microsoft.CrSlide"
  239.                 Case "fade"
  240.                          TransitionFriendlyNameToProgID = "DXImageTransform.Microsoft.Fade"
  241.                 Case "ripple"
  242.                          TransitionFriendlyNameToProgID = "DXImageTransform.MetaCreations.Water"
  243.                 Case "circle"
  244.                          TransitionFriendlyNameToProgID = "DXImageTransform.MetaCreations.Grid"
  245.                 Case "burn film"
  246.                          TransitionFriendlyNameToProgID = "DXImageTransform.MetaCreations.BurnFilm"
  247.                 Case "barn doors"
  248.                          TransitionFriendlyNameToProgID = "DXImageTransform.Microsoft.CrBarn"
  249.             End Select
  250.             Exit Function
  251.             
  252. ErrLine:
  253.             Err.Clear
  254.             Exit Function
  255.             End Function
  256.  
  257.  
  258.  
  259.             
  260.             
  261.             
  262. ' **************************************************************************************************************************************
  263. ' * PUBLIC INTERFACE- GENERAL PROCEDURES
  264. ' *
  265. ' *
  266.             ' ******************************************************************************************************************************
  267.             ' * procedure name: Buffer_ParseEx
  268.             ' * procedure description:   Parse's a fixed length string buffer of all vbNullCharacters AND vbNullStrings.
  269.             ' *                                        Argument bstrBuffer evaluates to either an ANSII or Unicode BSTR string buffer.
  270.             ' *                                        (bstrBuffer is almost always the output from a windows api call which needs parsed)
  271.             ' *
  272.             ' ******************************************************************************************************************************
  273.             Public Function Buffer_ParseEx(bstrBuffer As String) As String
  274.             Dim iCount As Long, bstrChar As String, bstrReturn As String
  275.             On Local Error GoTo ErrLine
  276.             
  277.             For iCount = 1 To Len(bstrBuffer) 'set up a loop to remove the vbNullChar's from the buffer.
  278.                   bstrChar = Strings.Mid(bstrBuffer, iCount, 1)
  279.                   If bstrChar <> vbNullChar And bstrChar <> vbNullString Then bstrReturn = (bstrReturn + bstrChar)
  280.             Next
  281.             Buffer_ParseEx = bstrReturn
  282.             Exit Function
  283.             
  284. ErrLine:
  285.             Err.Clear
  286.             Exit Function
  287.             End Function
  288.             
  289.             
  290.             ' ******************************************************************************************************************************
  291.             ' * procedure name: GetTempDirectory
  292.             ' * procedure description:  Returns a bstr String representing the fully qualified path to the system's temp directory
  293.             ' *
  294.             ' ******************************************************************************************************************************
  295.             Public Function GetTempDirectory() As String
  296.             Dim bstrBuffer As String * MAX_PATH
  297.             On Local Error GoTo ErrLine
  298.             
  299.             'call the win32api
  300.             Call GetTempPath(MAX_PATH, bstrBuffer)
  301.             'parse & return the value to the client
  302.             GetTempDirectory = Buffer_ParseEx(bstrBuffer)
  303.             Exit Function
  304.             
  305. ErrLine:
  306.             Err.Clear
  307.             Exit Function
  308.             End Function
  309.             
  310.             
  311.             
  312.             ' ******************************************************************************************************************************
  313.             ' * procedure name: File_Exists
  314.             ' * procedure description:  Returns true if the specified file does in fact exist.
  315.             ' *
  316.             ' ******************************************************************************************************************************
  317.             Public Function File_Exists(bstrFileName As String) As Boolean
  318.             Dim WFD As WIN32_FIND_DATA, hFile As Long
  319.             On Local Error GoTo ErrLine
  320.             
  321.             WFD.cFileName = bstrFileName & vbNullChar
  322.             hFile = FindFirstFile(bstrFileName, WFD)
  323.             File_Exists = hFile <> INVALID_HANDLE_VALUE
  324.             Call FindClose(hFile)
  325.             Exit Function
  326.             
  327. ErrLine:
  328.             Err.Clear
  329.             Exit Function
  330.             End Function
  331.             
  332.             
  333.             ' ******************************************************************************************************************************
  334.             ' * procedure name: File_Delete
  335.             ' * procedure description:  This will delete a File. Pass any of the specified optionals to invoke those particular features.
  336.             ' *
  337.             ' ******************************************************************************************************************************
  338.             Public Function File_Delete(bstrFileName As String, Optional SendToRecycleBin As Boolean = True, Optional Confirm As Boolean = True, Optional ShowProgress As Boolean = True) As Long
  339.             Dim fileop As SHFILEOPSTRUCT
  340.             Dim WFD As WIN32_FIND_DATA, hFile As Long
  341.             On Local Error GoTo ErrLine
  342.             
  343.             'check argument
  344.             If Right(bstrFileName, 1) = "\" Then bstrFileName = Left(bstrFileName, (Len(bstrFileName) - 1))
  345.             'ensure the file exists
  346.             WFD.cFileName = bstrFileName & vbNullChar
  347.             hFile = FindFirstFile(bstrFileName, WFD)
  348.             If hFile = INVALID_HANDLE_VALUE Then
  349.                Call FindClose(hFile)
  350.                Exit Function
  351.             Else: Call FindClose(hFile)
  352.             End If
  353.             'set the error mode
  354.             Call SetErrorMode(SEM_NOOPENFILEERRORBOX + SEM_FAILCRITICALERRORS)
  355.             'set up the file operation by the specified optionals
  356.             With fileop
  357.                 .hWnd = 0: .wFunc = FO_DELETE
  358.                 .pFrom = UCase(bstrFileName) & vbNullChar & vbNullChar
  359.                 If SendToRecycleBin Then   'goes to recycle bin
  360.                    .fFlags = FOF_ALLOWUNDO
  361.                    If Confirm = False Then .fFlags = .fFlags + FOF_NOCONFIRMATION  'do not confirm
  362.                    If ShowProgress = False Then .fFlags = .fFlags + FOF_SILENT  'do not show progress
  363.                 Else 'just delete the file
  364.                    If Confirm = False Then .fFlags = .fFlags + FOF_NOCONFIRMATION  'do not confirm
  365.                    If ShowProgress = False Then .fFlags = .fFlags + FOF_SILENT  'do not show progress
  366.                 End If
  367.             End With
  368.             'execute the file operation, return any errors..
  369.             File_Delete = SHFileOperation(fileop)
  370.             Exit Function
  371.             
  372. ErrLine:
  373.             File_Delete = Err.Number  'if there was a abend in the procedure, return that too..
  374.             Err.Clear
  375.             Exit Function
  376.             End Function
  377.             
  378.             
  379.             
  380.             
  381.             ' ******************************************************************************************************************************
  382.             ' * procedure name: ShowCommonDlgOpen
  383.             ' * procedure description:
  384.             ' *
  385.             ' ******************************************************************************************************************************
  386.             Public Function ShowCommonDlgOpen(Optional bstrCurrentDirectory As String, Optional bstrDefaultExtension As String, Optional bstrFilter As String) As String
  387.             Dim ctrl As Object
  388.             On Local Error GoTo ErrLine
  389.             
  390.             'instantiate control
  391.             If ObjPtr(CreateObject("MSComDlg.CommonDialog.1")) > 0 Then
  392.                Set ctrl = CreateObject("MSComDlg.CommonDialog.1")
  393.             ElseIf ObjPtr(CreateObject("MSComDlg.CommonDialog")) > 0 Then
  394.                Set ctrl = CreateObject("MSComDlg.CommonDialog")
  395.             End If
  396.             
  397.             If ObjPtr(ctrl) > 0 Then
  398.                'set properties
  399.                ctrl.Filter = bstrFilter
  400.                ctrl.DefaultExt = bstrDefaultExtension
  401.                ctrl.InitDir = bstrCurrentDirectory
  402.                ctrl.ShowOpen
  403.                'return to client
  404.                ShowCommonDlgOpen = ctrl.FileName
  405.             End If
  406.             
  407.             'clean-up & dereference
  408.             If ObjPtr(ctrl) > 0 Then Set ctrl = Nothing
  409.             Exit Function
  410.             
  411. ErrLine:
  412.  
  413.             Err.Clear
  414.             Exit Function
  415.             End Function
  416.             
  417.             
  418.             
  419.             ' ******************************************************************************************************************************
  420.             ' * procedure name: ShowCommonDlgSave
  421.             ' * procedure description:
  422.             ' *
  423.             ' ******************************************************************************************************************************
  424.             Public Function ShowCommonDlgSave(Optional bstrCurrentDirectory As String, Optional bstrDefaultExtension As String, Optional bstrFilter As String) As String
  425.             Dim ctrl As Object
  426.             On Local Error GoTo ErrLine
  427.             
  428.             'instantiate control
  429.             If ObjPtr(CreateObject("MSComDlg.CommonDialog.1")) > 0 Then
  430.                Set ctrl = CreateObject("MSComDlg.CommonDialog.1")
  431.             ElseIf ObjPtr(CreateObject("MSComDlg.CommonDialog")) > 0 Then
  432.                Set ctrl = CreateObject("MSComDlg.CommonDialog")
  433.             End If
  434.             
  435.             If ObjPtr(ctrl) > 0 Then
  436.                'set properties
  437.                ctrl.Filter = bstrFilter
  438.                ctrl.DefaultExt = bstrDefaultExtension
  439.                ctrl.InitDir = bstrCurrentDirectory
  440.                ctrl.ShowSave
  441.                'return to client
  442.                ShowCommonDlgSave = ctrl.FileName
  443.             End If
  444.             
  445.             'clean-up & dereference
  446.             If ObjPtr(ctrl) > 0 Then Set ctrl = Nothing
  447.             Exit Function
  448.             
  449. ErrLine:
  450.  
  451.             Err.Clear
  452.             Exit Function
  453.             End Function
  454.