home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / DirectShow / Common / mfcdmoutil.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-08  |  3.2 KB  |  113 lines

  1. //------------------------------------------------------------------------------
  2. // File: MFCDMOUtil.cpp
  3. //
  4. // Desc: DirectShow sample code - DMO utility functions used by MFC applications.
  5. //
  6. // Copyright (c) 2000-2001 Microsoft Corporation.  All rights reserved.
  7. //------------------------------------------------------------------------------
  8.  
  9. #include "stdafx.h"
  10. #include <dshow.h>
  11. #include <dmo.h>
  12.  
  13. #include "namedguid.h"
  14. #include "mfcdmoutil.h"
  15. #include "mfcutil.h"
  16.  
  17.  
  18. HRESULT AddDMOsToList(const GUID *clsid, CListBox& ListFilters, BOOL bIncludeKeyed) 
  19. {
  20.     HRESULT hr;    
  21.     IEnumDMO *pEnum = NULL;
  22.     int nFilters=0;
  23.     DWORD dwFlags = bIncludeKeyed ? DMO_ENUMF_INCLUDE_KEYED : 0;
  24.  
  25.     // Enumerate all DMOs of the selected category  
  26.     hr = DMOEnum(*clsid, dwFlags, 0, NULL, 0, NULL, &pEnum);
  27.     if (FAILED(hr))
  28.         return hr;
  29.  
  30.     // Enumerate all filters using the category enumerator
  31.     hr = EnumDMOsToList(pEnum, ListFilters, nFilters);
  32.  
  33.     // Now that the DMOs (if any) are enumerated and added 
  34.     // to the list, go ahead and select the first one.
  35.     ListFilters.SetCurSel(0);
  36.     pEnum->Release();
  37.     return hr;
  38. }
  39.  
  40.  
  41. HRESULT EnumDMOsToList(IEnumDMO *pEnumCat, CListBox& ListFilters, int& nFilters)
  42. {
  43.     HRESULT hr=S_OK;
  44.     ULONG cFetched;
  45.     WCHAR *wszName;
  46.     CLSID clsid;
  47.  
  48.     // Clear the current filter list
  49.     ClearFilterListWithCLSID(ListFilters);
  50.     nFilters = 0;
  51.  
  52.     // If there are no filters of a requested type, show default string
  53.     if (!pEnumCat)
  54.     {
  55.         ListFilters.AddString(TEXT("<< No entries >>"));
  56.         return S_FALSE;
  57.     }
  58.  
  59.     // Enumerate all items associated with the moniker
  60.     while(pEnumCat->Next(1, &clsid, &wszName, &cFetched) == S_OK)
  61.     {
  62.         nFilters++;
  63.         CString str(wszName);
  64.  
  65.         // Add filter's name and CLSID to the list box
  66.         AddFilterToListWithCLSID(str, &clsid, ListFilters);
  67.         CoTaskMemFree(wszName);
  68.     }
  69.  
  70.     // If no DMOs matched the query, show a default item
  71.     if (nFilters == 0)
  72.         ListFilters.AddString(TEXT("<< No entries >>"));
  73.  
  74.     return hr;
  75. }
  76.  
  77.  
  78. void DisplayDMOTypeInfo(const GUID *pCLSID, 
  79.                         ULONG& ulNumInputsSupplied,  CListBox& ListInputTypes,
  80.                         ULONG& ulNumOutputsSupplied, CListBox& ListOutputTypes)
  81. {
  82.     const int NUM_PAIRS=20;
  83.     HRESULT hr;
  84.     DMO_PARTIAL_MEDIATYPE aInputTypes[NUM_PAIRS]={0}, 
  85.                           aOutputTypes[NUM_PAIRS]={0};
  86.     ULONG ulNumInputTypes=NUM_PAIRS, ulNumOutputTypes=NUM_PAIRS, i;
  87.     TCHAR szCLSID[128];
  88.  
  89.     // Read type/subtype information
  90.     hr = DMOGetTypes(
  91.         *pCLSID,
  92.         ulNumInputTypes,  &ulNumInputsSupplied,  aInputTypes,
  93.         ulNumOutputTypes, &ulNumOutputsSupplied, aOutputTypes);
  94.  
  95.     if (FAILED(hr))
  96.         return;
  97.  
  98.     // Show input type/subtype pairs
  99.     for (i=0; i<ulNumInputsSupplied; i++)
  100.     {
  101.         GetTypeSubtypeString(szCLSID, aInputTypes[i]);
  102.         ListInputTypes.AddString(szCLSID);
  103.     }
  104.  
  105.     // Show output type/subtype pairs
  106.     for (i=0; i<ulNumOutputsSupplied; i++)
  107.     {
  108.         GetTypeSubtypeString(szCLSID, aOutputTypes[i]);
  109.         ListOutputTypes.AddString(szCLSID);
  110.     }
  111. }
  112.  
  113.