Release 20030408.
[wine/gsoc-2012-control.git] / windows / multimon.c
blobe909538228e101b55a69ff6b4074fc05579d1b5d
1 /*
2 * Multimonitor APIs
4 * Copyright 1998 Turchanov Sergey
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.
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.
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
21 #include <string.h>
22 #include "windef.h"
23 #include "wingdi.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "wine/unicode.h"
28 /**********************************************************************/
30 #define xPRIMARY_MONITOR ((HMONITOR)0x12340042)
32 /***********************************************************************
33 * MonitorFromPoint (USER32.@)
35 HMONITOR WINAPI MonitorFromPoint(POINT ptScreenCoords, DWORD dwFlags)
37 if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
38 ((ptScreenCoords.x >= 0) &&
39 (ptScreenCoords.x < GetSystemMetrics(SM_CXSCREEN)) &&
40 (ptScreenCoords.y >= 0) &&
41 (ptScreenCoords.y < GetSystemMetrics(SM_CYSCREEN))))
43 return xPRIMARY_MONITOR;
45 return NULL;
48 /***********************************************************************
49 * MonitorFromRect (USER32.@)
51 HMONITOR WINAPI MonitorFromRect(LPRECT lprcScreenCoords, DWORD dwFlags)
53 if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
54 ((lprcScreenCoords->right > 0) &&
55 (lprcScreenCoords->bottom > 0) &&
56 (lprcScreenCoords->left < GetSystemMetrics(SM_CXSCREEN)) &&
57 (lprcScreenCoords->top < GetSystemMetrics(SM_CYSCREEN))))
59 return xPRIMARY_MONITOR;
61 return NULL;
64 /***********************************************************************
65 * MonitorFromWindow (USER32.@)
67 HMONITOR WINAPI MonitorFromWindow(HWND hWnd, DWORD dwFlags)
69 WINDOWPLACEMENT wp;
71 if (dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST))
72 return xPRIMARY_MONITOR;
74 if (IsIconic(hWnd) ?
75 GetWindowPlacement(hWnd, &wp) :
76 GetWindowRect(hWnd, &wp.rcNormalPosition)) {
78 return MonitorFromRect(&wp.rcNormalPosition, dwFlags);
81 return NULL;
84 /***********************************************************************
85 * GetMonitorInfoA (USER32.@)
87 BOOL WINAPI GetMonitorInfoA(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
89 RECT rcWork;
91 if ((hMonitor == xPRIMARY_MONITOR) &&
92 lpMonitorInfo &&
93 (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
94 SystemParametersInfoA(SPI_GETWORKAREA, 0, &rcWork, 0))
96 SetRect( &lpMonitorInfo->rcMonitor, 0, 0,
97 GetSystemMetrics(SM_CXSCREEN),
98 GetSystemMetrics(SM_CYSCREEN) );
99 lpMonitorInfo->rcWork = rcWork;
100 lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
102 if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEXA))
103 strcpy(((MONITORINFOEXA*)lpMonitorInfo)->szDevice, "DISPLAY");
105 return TRUE;
108 return FALSE;
111 /***********************************************************************
112 * GetMonitorInfoW (USER32.@)
114 BOOL WINAPI GetMonitorInfoW(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
116 RECT rcWork;
118 if ((hMonitor == xPRIMARY_MONITOR) &&
119 lpMonitorInfo &&
120 (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
121 SystemParametersInfoW(SPI_GETWORKAREA, 0, &rcWork, 0))
123 SetRect( &lpMonitorInfo->rcMonitor, 0, 0,
124 GetSystemMetrics(SM_CXSCREEN),
125 GetSystemMetrics(SM_CYSCREEN) );
126 lpMonitorInfo->rcWork = rcWork;
127 lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
129 if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEXW))
130 strcpyW(((MONITORINFOEXW*)lpMonitorInfo)->szDevice, (LPCWSTR)"D\0I\0S\0P\0L\0A\0Y\0\0");
132 return TRUE;
135 return FALSE;
138 /***********************************************************************
139 * EnumDisplayMonitors (USER32.@)
141 BOOL WINAPI EnumDisplayMonitors(
142 HDC hdcOptionalForPainting,
143 LPRECT lprcEnumMonitorsThatIntersect,
144 MONITORENUMPROC lpfnEnumProc,
145 LPARAM dwData)
147 RECT rcLimit;
148 SetRect( &rcLimit, 0, 0, GetSystemMetrics(SM_CXSCREEN),
149 GetSystemMetrics(SM_CYSCREEN) );
151 if (!lpfnEnumProc)
152 return FALSE;
154 if (hdcOptionalForPainting)
156 RECT rcClip;
157 POINT ptOrg;
159 switch (GetClipBox(hdcOptionalForPainting, &rcClip))
161 default:
162 if (!GetDCOrgEx(hdcOptionalForPainting, &ptOrg))
163 return FALSE;
165 OffsetRect(&rcLimit, -ptOrg.x, -ptOrg.y);
166 if (IntersectRect(&rcLimit, &rcLimit, &rcClip) &&
167 (!lprcEnumMonitorsThatIntersect ||
168 IntersectRect(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect))) {
170 break;
172 /* fall through */
173 case NULLREGION:
174 return TRUE;
175 case ERROR:
176 return FALSE;
178 } else {
179 if ( lprcEnumMonitorsThatIntersect &&
180 !IntersectRect(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect)) {
182 return TRUE;
186 return lpfnEnumProc(
187 xPRIMARY_MONITOR,
188 hdcOptionalForPainting,
189 &rcLimit,
190 dwData);