1
0

ddmm.cpp 3.0 KB

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