Yet another small self-loader fix.
[wine/multimedia.git] / windows / multimon.c
blobe7a9fface95cd13c120d5fa9c24c2458b64f3fe1
1 /*
2 * Multimonitor APIs
4 * Copyright 1998 Turchanov Sergey
5 */
7 #include "windows.h"
8 #include "multimon.h"
11 #define xPRIMARY_MONITOR ((HMONITOR)0x12340042)
13 HMONITOR WINAPI MonitorFromPoint(POINT32 ptScreenCoords, DWORD dwFlags)
15 if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
16 ((ptScreenCoords.x >= 0) &&
17 (ptScreenCoords.x < GetSystemMetrics32(SM_CXSCREEN)) &&
18 (ptScreenCoords.y >= 0) &&
19 (ptScreenCoords.y < GetSystemMetrics32(SM_CYSCREEN))))
21 return xPRIMARY_MONITOR;
23 return NULL;
26 HMONITOR WINAPI MonitorFromRect(LPRECT32 lprcScreenCoords, DWORD dwFlags)
28 if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
29 ((lprcScreenCoords->right > 0) &&
30 (lprcScreenCoords->bottom > 0) &&
31 (lprcScreenCoords->left < GetSystemMetrics32(SM_CXSCREEN)) &&
32 (lprcScreenCoords->top < GetSystemMetrics32(SM_CYSCREEN))))
34 return xPRIMARY_MONITOR;
36 return NULL;
39 HMONITOR WINAPI MonitorFromWindow(HWND32 hWnd, DWORD dwFlags)
41 WINDOWPLACEMENT32 wp;
43 if (dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST))
44 return xPRIMARY_MONITOR;
46 if (IsIconic32(hWnd) ?
47 GetWindowPlacement32(hWnd, &wp) :
48 GetWindowRect32(hWnd, &wp.rcNormalPosition)) {
50 return MonitorFromRect(&wp.rcNormalPosition, dwFlags);
53 return NULL;
56 BOOL32 WINAPI GetMonitorInfo32A(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
58 RECT32 rcWork;
60 if ((hMonitor == xPRIMARY_MONITOR) &&
61 lpMonitorInfo &&
62 (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
63 SystemParametersInfo32A(SPI_GETWORKAREA, 0, &rcWork, 0))
65 lpMonitorInfo->rcMonitor.left = 0;
66 lpMonitorInfo->rcMonitor.top = 0;
67 lpMonitorInfo->rcMonitor.right = GetSystemMetrics32(SM_CXSCREEN);
68 lpMonitorInfo->rcMonitor.bottom = GetSystemMetrics32(SM_CYSCREEN);
69 lpMonitorInfo->rcWork = rcWork;
70 lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
72 if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEX32A))
73 lstrcpy32A(((MONITORINFOEX32A*)lpMonitorInfo)->szDevice, "DISPLAY");
75 return TRUE;
78 return FALSE;
81 BOOL32 WINAPI GetMonitorInfo32W(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
83 RECT32 rcWork;
85 if ((hMonitor == xPRIMARY_MONITOR) &&
86 lpMonitorInfo &&
87 (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
88 SystemParametersInfo32W(SPI_GETWORKAREA, 0, &rcWork, 0))
90 lpMonitorInfo->rcMonitor.left = 0;
91 lpMonitorInfo->rcMonitor.top = 0;
92 lpMonitorInfo->rcMonitor.right = GetSystemMetrics32(SM_CXSCREEN);
93 lpMonitorInfo->rcMonitor.bottom = GetSystemMetrics32(SM_CYSCREEN);
94 lpMonitorInfo->rcWork = rcWork;
95 lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
97 if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEX32W))
98 lstrcpy32W(((MONITORINFOEX32W*)lpMonitorInfo)->szDevice, "D\0I\0S\0P\0L\0A\0Y\0\0");
100 return TRUE;
103 return FALSE;
106 BOOL32 WINAPI EnumDisplayMonitors(
107 HDC32 hdcOptionalForPainting,
108 LPRECT32 lprcEnumMonitorsThatIntersect,
109 MONITORENUMPROC lpfnEnumProc,
110 LPARAM dwData)
112 RECT32 rcLimit;
114 if (!lpfnEnumProc)
115 return FALSE;
117 rcLimit.left = 0;
118 rcLimit.top = 0;
119 rcLimit.right = GetSystemMetrics32(SM_CXSCREEN);
120 rcLimit.bottom = GetSystemMetrics32(SM_CYSCREEN);
122 if (hdcOptionalForPainting)
124 RECT32 rcClip;
125 POINT32 ptOrg;
127 switch (GetClipBox32(hdcOptionalForPainting, &rcClip))
129 default:
130 if (!GetDCOrgEx(hdcOptionalForPainting, &ptOrg))
131 return FALSE;
133 OffsetRect32(&rcLimit, -ptOrg.x, -ptOrg.y);
134 if (IntersectRect32(&rcLimit, &rcLimit, &rcClip) &&
135 (!lprcEnumMonitorsThatIntersect ||
136 IntersectRect32(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect))) {
138 break;
140 //fall thru
141 case NULLREGION:
142 return TRUE;
143 case ERROR:
144 return FALSE;
146 } else {
147 if ( lprcEnumMonitorsThatIntersect &&
148 !IntersectRect32(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect)) {
150 return TRUE;
154 return lpfnEnumProc(
155 xPRIMARY_MONITOR,
156 hdcOptionalForPainting,
157 &rcLimit,
158 dwData);