1
0

VideoOutputChildDDraw.cpp 2.3 KB

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