Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
3.1 KiB

  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(GUID* lpGUID, LPSTR szName, LPSTR szDevice, 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(GUID* lpGUID, LPSTR szName, LPSTR szDevice, 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(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(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. }