home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Game Programming for Teens / VBGPFT.cdr / DirectX8 / dx8a_sdk.exe / samples / multimedia / directshow / baseclasses / ddmm.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-02  |  3.1 KB  |  130 lines

  1. //------------------------------------------------------------------------------
  2. // File: DDMM.cpp
  3. //
  4. // Desc: DirectShow base classes - implements routines for using DirectDraw
  5. //       on a multimonitor system.
  6. //
  7. // Copyright (c) 1995 - 2000, Microsoft Corporation.  All rights reserved.
  8. //------------------------------------------------------------------------------
  9.  
  10.  
  11. #include <streams.h>
  12. #include <ddraw.h>
  13. #include "ddmm.h"
  14.  
  15. /*
  16.  * FindDeviceCallback
  17.  */
  18. typedef struct {
  19.     LPSTR   szDevice;
  20.     GUID*   lpGUID;
  21.     GUID    GUID;
  22.     BOOL    fFound;
  23. }   FindDeviceData;
  24.  
  25. BOOL CALLBACK FindDeviceCallback(GUID* lpGUID, LPSTR szName, LPSTR szDevice, LPVOID lParam)
  26. {
  27.     FindDeviceData *p = (FindDeviceData*)lParam;
  28.  
  29.     if (lstrcmpiA(p->szDevice, szDevice) == 0) {
  30.         if (lpGUID) {
  31.         p->GUID = *lpGUID;
  32.         p->lpGUID = &p->GUID;
  33.         } else {
  34.         p->lpGUID = NULL;
  35.         }
  36.         p->fFound = TRUE;
  37.         return FALSE;
  38.     }
  39.     return TRUE;
  40. }
  41.  
  42.  
  43. BOOL CALLBACK FindDeviceCallbackEx(GUID* lpGUID, LPSTR szName, LPSTR szDevice, LPVOID lParam, HMONITOR hMonitor)
  44. {
  45.     FindDeviceData *p = (FindDeviceData*)lParam;
  46.  
  47.     if (lstrcmpiA(p->szDevice, szDevice) == 0) {
  48.         if (lpGUID) {
  49.         p->GUID = *lpGUID;
  50.         p->lpGUID = &p->GUID;
  51.         } else {
  52.         p->lpGUID = NULL;
  53.         }
  54.         p->fFound = TRUE;
  55.         return FALSE;
  56.     }
  57.     return TRUE;
  58. }
  59.  
  60.  
  61. /*
  62.  * DirectDrawCreateFromDevice
  63.  *
  64.  * create a DirectDraw object for a particular device
  65.  */
  66. IDirectDraw * DirectDrawCreateFromDevice(LPSTR szDevice, PDRAWCREATE DirectDrawCreateP, PDRAWENUM DirectDrawEnumerateP)
  67. {
  68.     IDirectDraw*    pdd = NULL;
  69.     FindDeviceData  find;
  70.  
  71.     if (szDevice == NULL) {
  72.         DirectDrawCreateP(NULL, &pdd, NULL);
  73.         return pdd;
  74.     }
  75.  
  76.     find.szDevice = szDevice;
  77.     find.fFound   = FALSE;
  78.     DirectDrawEnumerateP(FindDeviceCallback, (LPVOID)&find);
  79.  
  80.     if (find.fFound)
  81.     {
  82.         //
  83.         // In 4bpp mode the following DDraw call causes a message box to be popped
  84.         // up by DDraw (!?!).  It's DDraw's fault, but we don't like it.  So we
  85.         // make sure it doesn't happen.
  86.         //
  87.         UINT ErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
  88.         DirectDrawCreateP(find.lpGUID, &pdd, NULL);
  89.         SetErrorMode(ErrorMode);
  90.     }
  91.  
  92.     return pdd;
  93. }
  94.  
  95.  
  96. /*
  97.  * DirectDrawCreateFromDeviceEx
  98.  *
  99.  * create a DirectDraw object for a particular device
  100.  */
  101. IDirectDraw * DirectDrawCreateFromDeviceEx(LPSTR szDevice, PDRAWCREATE DirectDrawCreateP, LPDIRECTDRAWENUMERATEEXA DirectDrawEnumerateExP)
  102. {
  103.     IDirectDraw*    pdd = NULL;
  104.     FindDeviceData  find;
  105.  
  106.     if (szDevice == NULL) {
  107.         DirectDrawCreateP(NULL, &pdd, NULL);
  108.         return pdd;
  109.     }
  110.  
  111.     find.szDevice = szDevice;
  112.     find.fFound   = FALSE;
  113.     DirectDrawEnumerateExP(FindDeviceCallbackEx, (LPVOID)&find,
  114.                     DDENUM_ATTACHEDSECONDARYDEVICES);
  115.  
  116.     if (find.fFound)
  117.     {
  118.         //
  119.         // In 4bpp mode the following DDraw call causes a message box to be popped
  120.         // up by DDraw (!?!).  It's DDraw's fault, but we don't like it.  So we
  121.         // make sure it doesn't happen.
  122.         //
  123.         UINT ErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
  124.         DirectDrawCreateP(find.lpGUID, &pdd, NULL);
  125.         SetErrorMode(ErrorMode);
  126.     }
  127.  
  128.     return pdd;
  129. }
  130.