Release 20000326.
[wine/gsoc-2012-control.git] / windows / multimon.c
blob987b6abf94b87c7526ca039c00f30f15b73d03db
1 /*
2 * Multimonitor APIs
4 * Copyright 1998 Turchanov Sergey
5 */
7 #include "monitor.h"
8 #include "windef.h"
9 #include "wingdi.h"
10 #include "winbase.h"
11 #include "winuser.h"
13 /**********************************************************************/
15 #define xPRIMARY_MONITOR ((HMONITOR)0x12340042)
17 MONITOR MONITOR_PrimaryMonitor;
19 /**********************************************************************/
21 HMONITOR WINAPI MonitorFromPoint(POINT ptScreenCoords, DWORD dwFlags)
23 if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
24 ((ptScreenCoords.x >= 0) &&
25 (ptScreenCoords.x < GetSystemMetrics(SM_CXSCREEN)) &&
26 (ptScreenCoords.y >= 0) &&
27 (ptScreenCoords.y < GetSystemMetrics(SM_CYSCREEN))))
29 return xPRIMARY_MONITOR;
31 return NULL;
34 HMONITOR WINAPI MonitorFromRect(LPRECT lprcScreenCoords, DWORD dwFlags)
36 if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
37 ((lprcScreenCoords->right > 0) &&
38 (lprcScreenCoords->bottom > 0) &&
39 (lprcScreenCoords->left < GetSystemMetrics(SM_CXSCREEN)) &&
40 (lprcScreenCoords->top < GetSystemMetrics(SM_CYSCREEN))))
42 return xPRIMARY_MONITOR;
44 return NULL;
47 HMONITOR WINAPI MonitorFromWindow(HWND hWnd, DWORD dwFlags)
49 WINDOWPLACEMENT wp;
51 if (dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST))
52 return xPRIMARY_MONITOR;
54 if (IsIconic(hWnd) ?
55 GetWindowPlacement(hWnd, &wp) :
56 GetWindowRect(hWnd, &wp.rcNormalPosition)) {
58 return MonitorFromRect(&wp.rcNormalPosition, dwFlags);
61 return NULL;
64 BOOL WINAPI GetMonitorInfoA(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
66 RECT rcWork;
68 if ((hMonitor == xPRIMARY_MONITOR) &&
69 lpMonitorInfo &&
70 (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
71 SystemParametersInfoA(SPI_GETWORKAREA, 0, &rcWork, 0))
73 lpMonitorInfo->rcMonitor = MONITOR_PrimaryMonitor.rect;
74 lpMonitorInfo->rcWork = rcWork;
75 lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
77 if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEXA))
78 lstrcpyA(((MONITORINFOEXA*)lpMonitorInfo)->szDevice, "DISPLAY");
80 return TRUE;
83 return FALSE;
86 BOOL WINAPI GetMonitorInfoW(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
88 RECT rcWork;
90 if ((hMonitor == xPRIMARY_MONITOR) &&
91 lpMonitorInfo &&
92 (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
93 SystemParametersInfoW(SPI_GETWORKAREA, 0, &rcWork, 0))
95 lpMonitorInfo->rcMonitor = MONITOR_PrimaryMonitor.rect;
96 lpMonitorInfo->rcWork = rcWork;
97 lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
99 if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEXW))
100 lstrcpyW(((MONITORINFOEXW*)lpMonitorInfo)->szDevice, (LPCWSTR)"D\0I\0S\0P\0L\0A\0Y\0\0");
102 return TRUE;
105 return FALSE;
108 BOOL WINAPI EnumDisplayMonitors(
109 HDC hdcOptionalForPainting,
110 LPRECT lprcEnumMonitorsThatIntersect,
111 MONITORENUMPROC lpfnEnumProc,
112 LPARAM dwData)
114 RECT rcLimit = MONITOR_PrimaryMonitor.rect;
116 if (!lpfnEnumProc)
117 return FALSE;
119 if (hdcOptionalForPainting)
121 RECT rcClip;
122 POINT ptOrg;
124 switch (GetClipBox(hdcOptionalForPainting, &rcClip))
126 default:
127 if (!GetDCOrgEx(hdcOptionalForPainting, &ptOrg))
128 return FALSE;
130 OffsetRect(&rcLimit, -ptOrg.x, -ptOrg.y);
131 if (IntersectRect(&rcLimit, &rcLimit, &rcClip) &&
132 (!lprcEnumMonitorsThatIntersect ||
133 IntersectRect(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect))) {
135 break;
137 /*fall thru */
138 case NULLREGION:
139 return TRUE;
140 case ERROR:
141 return FALSE;
143 } else {
144 if ( lprcEnumMonitorsThatIntersect &&
145 !IntersectRect(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect)) {
147 return TRUE;
151 return lpfnEnumProc(
152 xPRIMARY_MONITOR,
153 hdcOptionalForPainting,
154 &rcLimit,
155 dwData);