VideoOutputChildDDraw.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "main.h"
  2. #include "VideoOutputChildDDraw.h"
  3. #include <ddraw.h>
  4. class MonitorFinder
  5. {
  6. public:
  7. MonitorFinder(HMONITOR hm) : m_monitor_to_find(hm), m_found_devguid(0)
  8. {}
  9. HMONITOR m_monitor_to_find;
  10. int m_found_devguid;
  11. GUID m_devguid;
  12. };
  13. static BOOL WINAPI DDEnumCallbackEx(GUID FAR *lpGUID, LPSTR lpDriverDescription, LPSTR lpDriverName, LPVOID lpContext, HMONITOR hm)
  14. {
  15. MonitorFinder *ovo = (MonitorFinder *)lpContext;
  16. if (ovo->m_found_devguid) return 1;
  17. if (hm == ovo->m_monitor_to_find)
  18. {
  19. ovo->m_devguid = *lpGUID;
  20. ovo->m_found_devguid = 1;
  21. }
  22. return 1;
  23. }
  24. void VideoOutputChildDDraw::update_monitor_coords()
  25. {
  26. //find the correct monitor if multiple monitor support is present
  27. m_mon_x = 0;
  28. m_mon_y = 0;
  29. HMONITOR hm = MonitorFromWindow(parent, 0);
  30. if (hm)
  31. {
  32. HINSTANCE hdd = LoadLibraryW(TEXT("ddraw.dll"));
  33. if (hdd)
  34. {
  35. typedef BOOL (FAR PASCAL * LPDDENUMCALLBACKEXA)(GUID FAR *, LPSTR, LPSTR, LPVOID, HMONITOR);
  36. typedef HRESULT (WINAPI * LPDIRECTDRAWENUMERATEEX)( LPDDENUMCALLBACKEXA lpCallback, LPVOID lpContext, DWORD dwFlags);
  37. LPDIRECTDRAWENUMERATEEX lpDDEnumEx;
  38. lpDDEnumEx = (LPDIRECTDRAWENUMERATEEX) GetProcAddress(hdd, "DirectDrawEnumerateExW");
  39. if (lpDDEnumEx)
  40. {
  41. MonitorFinder finder(hm);
  42. lpDDEnumEx(&DDEnumCallbackEx, &finder, DDENUM_ATTACHEDSECONDARYDEVICES | DDENUM_NONDISPLAYDEVICES);
  43. foundGUID=!!finder.m_found_devguid;
  44. if (foundGUID)
  45. {
  46. m_devguid=finder.m_devguid;
  47. MONITORINFOEXW mi;
  48. memset(&mi, 0, sizeof(mi));
  49. mi.cbSize = sizeof(mi);
  50. if (GetMonitorInfoA(hm, &mi))
  51. {
  52. m_mon_x = mi.rcMonitor.left;
  53. m_mon_y = mi.rcMonitor.top;
  54. }
  55. }
  56. }
  57. FreeLibrary(hdd);
  58. }
  59. }
  60. }