Added missing #include "config.h"
[wine/multimedia.git] / windows / multimon.c
blob4e582684a1051419b024454a7d12a5eb7f03cb94
1 /*
2 * Multimonitor APIs
4 * Copyright 1998 Turchanov Sergey
5 */
7 #include "windows.h"
9 #define xPRIMARY_MONITOR ((HMONITOR)0x12340042)
11 HMONITOR WINAPI MonitorFromPoint(POINT32 ptScreenCoords, DWORD dwFlags)
13 if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
14 ((ptScreenCoords.x >= 0) &&
15 (ptScreenCoords.x < GetSystemMetrics32(SM_CXSCREEN)) &&
16 (ptScreenCoords.y >= 0) &&
17 (ptScreenCoords.y < GetSystemMetrics32(SM_CYSCREEN))))
19 return xPRIMARY_MONITOR;
21 return NULL;
24 HMONITOR WINAPI MonitorFromRect(LPRECT32 lprcScreenCoords, DWORD dwFlags)
26 if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
27 ((lprcScreenCoords->right > 0) &&
28 (lprcScreenCoords->bottom > 0) &&
29 (lprcScreenCoords->left < GetSystemMetrics32(SM_CXSCREEN)) &&
30 (lprcScreenCoords->top < GetSystemMetrics32(SM_CYSCREEN))))
32 return xPRIMARY_MONITOR;
34 return NULL;
37 HMONITOR WINAPI MonitorFromWindow(HWND32 hWnd, DWORD dwFlags)
39 WINDOWPLACEMENT32 wp;
41 if (dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST))
42 return xPRIMARY_MONITOR;
44 if (IsIconic32(hWnd) ?
45 GetWindowPlacement32(hWnd, &wp) :
46 GetWindowRect32(hWnd, &wp.rcNormalPosition)) {
48 return MonitorFromRect(&wp.rcNormalPosition, dwFlags);
51 return NULL;
54 BOOL32 WINAPI GetMonitorInfo32A(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
56 RECT32 rcWork;
58 if ((hMonitor == xPRIMARY_MONITOR) &&
59 lpMonitorInfo &&
60 (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
61 SystemParametersInfo32A(SPI_GETWORKAREA, 0, &rcWork, 0))
63 lpMonitorInfo->rcMonitor.left = 0;
64 lpMonitorInfo->rcMonitor.top = 0;
65 lpMonitorInfo->rcMonitor.right = GetSystemMetrics32(SM_CXSCREEN);
66 lpMonitorInfo->rcMonitor.bottom = GetSystemMetrics32(SM_CYSCREEN);
67 lpMonitorInfo->rcWork = rcWork;
68 lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
70 if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEX32A))
71 lstrcpy32A(((MONITORINFOEX32A*)lpMonitorInfo)->szDevice, "DISPLAY");
73 return TRUE;
76 return FALSE;
79 BOOL32 WINAPI GetMonitorInfo32W(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
81 RECT32 rcWork;
83 if ((hMonitor == xPRIMARY_MONITOR) &&
84 lpMonitorInfo &&
85 (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
86 SystemParametersInfo32W(SPI_GETWORKAREA, 0, &rcWork, 0))
88 lpMonitorInfo->rcMonitor.left = 0;
89 lpMonitorInfo->rcMonitor.top = 0;
90 lpMonitorInfo->rcMonitor.right = GetSystemMetrics32(SM_CXSCREEN);
91 lpMonitorInfo->rcMonitor.bottom = GetSystemMetrics32(SM_CYSCREEN);
92 lpMonitorInfo->rcWork = rcWork;
93 lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
95 if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEX32W))
96 lstrcpy32W(((MONITORINFOEX32W*)lpMonitorInfo)->szDevice, "D\0I\0S\0P\0L\0A\0Y\0\0");
98 return TRUE;
101 return FALSE;
104 BOOL32 WINAPI EnumDisplayMonitors(
105 HDC32 hdcOptionalForPainting,
106 LPRECT32 lprcEnumMonitorsThatIntersect,
107 MONITORENUMPROC lpfnEnumProc,
108 LPARAM dwData)
110 RECT32 rcLimit;
112 if (!lpfnEnumProc)
113 return FALSE;
115 rcLimit.left = 0;
116 rcLimit.top = 0;
117 rcLimit.right = GetSystemMetrics32(SM_CXSCREEN);
118 rcLimit.bottom = GetSystemMetrics32(SM_CYSCREEN);
120 if (hdcOptionalForPainting)
122 RECT32 rcClip;
123 POINT32 ptOrg;
125 switch (GetClipBox32(hdcOptionalForPainting, &rcClip))
127 default:
128 if (!GetDCOrgEx(hdcOptionalForPainting, &ptOrg))
129 return FALSE;
131 OffsetRect32(&rcLimit, -ptOrg.x, -ptOrg.y);
132 if (IntersectRect32(&rcLimit, &rcLimit, &rcClip) &&
133 (!lprcEnumMonitorsThatIntersect ||
134 IntersectRect32(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect))) {
136 break;
138 //fall thru
139 case NULLREGION:
140 return TRUE;
141 case ERROR:
142 return FALSE;
144 } else {
145 if ( lprcEnumMonitorsThatIntersect &&
146 !IntersectRect32(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect)) {
148 return TRUE;
152 return lpfnEnumProc(
153 xPRIMARY_MONITOR,
154 hdcOptionalForPainting,
155 &rcLimit,
156 dwData);