multimon.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * Multimonitor APIs
  3. *
  4. * Copyright 1998 Turchanov Sergey
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <stdarg.h>
  21. #include <string.h>
  22. #include "windef.h"
  23. #include "winbase.h"
  24. #include "wingdi.h"
  25. #include "winuser.h"
  26. #include "wine/unicode.h"
  27. /**********************************************************************/
  28. #define xPRIMARY_MONITOR ((HMONITOR)0x12340042)
  29. /***********************************************************************
  30. * MonitorFromPoint (USER32.@)
  31. */
  32. HMONITOR WINAPI MonitorFromPoint(POINT ptScreenCoords, DWORD dwFlags)
  33. {
  34. if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
  35. ((ptScreenCoords.x >= 0) &&
  36. (ptScreenCoords.x < GetSystemMetrics(SM_CXSCREEN)) &&
  37. (ptScreenCoords.y >= 0) &&
  38. (ptScreenCoords.y < GetSystemMetrics(SM_CYSCREEN))))
  39. {
  40. return xPRIMARY_MONITOR;
  41. }
  42. return NULL;
  43. }
  44. /***********************************************************************
  45. * MonitorFromRect (USER32.@)
  46. */
  47. HMONITOR WINAPI MonitorFromRect(LPRECT lprcScreenCoords, DWORD dwFlags)
  48. {
  49. if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
  50. ((lprcScreenCoords->right > 0) &&
  51. (lprcScreenCoords->bottom > 0) &&
  52. (lprcScreenCoords->left < GetSystemMetrics(SM_CXSCREEN)) &&
  53. (lprcScreenCoords->top < GetSystemMetrics(SM_CYSCREEN))))
  54. {
  55. return xPRIMARY_MONITOR;
  56. }
  57. return NULL;
  58. }
  59. /***********************************************************************
  60. * MonitorFromWindow (USER32.@)
  61. */
  62. HMONITOR WINAPI MonitorFromWindow(HWND hWnd, DWORD dwFlags)
  63. {
  64. WINDOWPLACEMENT wp;
  65. if (dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST))
  66. return xPRIMARY_MONITOR;
  67. if (IsIconic(hWnd) ?
  68. GetWindowPlacement(hWnd, &wp) :
  69. GetWindowRect(hWnd, &wp.rcNormalPosition)) {
  70. return MonitorFromRect(&wp.rcNormalPosition, dwFlags);
  71. }
  72. return NULL;
  73. }
  74. /***********************************************************************
  75. * GetMonitorInfoA (USER32.@)
  76. */
  77. BOOL WINAPI GetMonitorInfoA(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
  78. {
  79. RECT rcWork;
  80. if ((hMonitor == xPRIMARY_MONITOR) &&
  81. lpMonitorInfo &&
  82. (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
  83. SystemParametersInfoA(SPI_GETWORKAREA, 0, &rcWork, 0))
  84. {
  85. SetRect( &lpMonitorInfo->rcMonitor, 0, 0,
  86. GetSystemMetrics(SM_CXSCREEN),
  87. GetSystemMetrics(SM_CYSCREEN) );
  88. lpMonitorInfo->rcWork = rcWork;
  89. lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
  90. if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEXA))
  91. strcpy(((MONITORINFOEXA*)lpMonitorInfo)->szDevice, "DISPLAY");
  92. return TRUE;
  93. }
  94. return FALSE;
  95. }
  96. /***********************************************************************
  97. * GetMonitorInfoW (USER32.@)
  98. */
  99. BOOL WINAPI GetMonitorInfoW(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
  100. {
  101. static const WCHAR displayW[] = {'D','I','S','P','L','A','Y',0};
  102. RECT rcWork;
  103. if ((hMonitor == xPRIMARY_MONITOR) &&
  104. lpMonitorInfo &&
  105. (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
  106. SystemParametersInfoW(SPI_GETWORKAREA, 0, &rcWork, 0))
  107. {
  108. SetRect( &lpMonitorInfo->rcMonitor, 0, 0,
  109. GetSystemMetrics(SM_CXSCREEN),
  110. GetSystemMetrics(SM_CYSCREEN) );
  111. lpMonitorInfo->rcWork = rcWork;
  112. lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
  113. if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEXW))
  114. strcpyW(((MONITORINFOEXW*)lpMonitorInfo)->szDevice, displayW);
  115. return TRUE;
  116. }
  117. return FALSE;
  118. }
  119. /***********************************************************************
  120. * EnumDisplayMonitors (USER32.@)
  121. */
  122. BOOL WINAPI EnumDisplayMonitors(
  123. HDC hdcOptionalForPainting,
  124. LPRECT lprcEnumMonitorsThatIntersect,
  125. MONITORENUMPROC lpfnEnumProc,
  126. LPARAM dwData)
  127. {
  128. RECT rcLimit;
  129. SetRect( &rcLimit, 0, 0, GetSystemMetrics(SM_CXSCREEN),
  130. GetSystemMetrics(SM_CYSCREEN) );
  131. if (!lpfnEnumProc)
  132. return FALSE;
  133. if (hdcOptionalForPainting)
  134. {
  135. RECT rcClip;
  136. POINT ptOrg;
  137. switch (GetClipBox(hdcOptionalForPainting, &rcClip))
  138. {
  139. default:
  140. if (!GetDCOrgEx(hdcOptionalForPainting, &ptOrg))
  141. return FALSE;
  142. OffsetRect(&rcLimit, -ptOrg.x, -ptOrg.y);
  143. if (IntersectRect(&rcLimit, &rcLimit, &rcClip) &&
  144. (!lprcEnumMonitorsThatIntersect ||
  145. IntersectRect(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect))) {
  146. break;
  147. }
  148. /* fall through */
  149. case NULLREGION:
  150. return TRUE;
  151. case ERROR:
  152. return FALSE;
  153. }
  154. } else {
  155. if ( lprcEnumMonitorsThatIntersect &&
  156. !IntersectRect(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect)) {
  157. return TRUE;
  158. }
  159. }
  160. return lpfnEnumProc(
  161. xPRIMARY_MONITOR,
  162. hdcOptionalForPainting,
  163. &rcLimit,
  164. dwData);
  165. }