Cleaned up some more USER dependencies.
[wine/hacks.git] / windows / multimon.c
blob52c574d217b2849b3f85595121e0889a6bd0d5e0
1 /*
2 * Multimonitor APIs
4 * Copyright 1998 Turchanov Sergey
5 */
7 #include "windef.h"
8 #include "wingdi.h"
9 #include "winbase.h"
10 #include "winuser.h"
12 /**********************************************************************/
14 #define xPRIMARY_MONITOR ((HMONITOR)0x12340042)
16 /***********************************************************************
17 * MonitorFromPoint
19 HMONITOR WINAPI MonitorFromPoint(POINT ptScreenCoords, DWORD dwFlags)
21 if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
22 ((ptScreenCoords.x >= 0) &&
23 (ptScreenCoords.x < GetSystemMetrics(SM_CXSCREEN)) &&
24 (ptScreenCoords.y >= 0) &&
25 (ptScreenCoords.y < GetSystemMetrics(SM_CYSCREEN))))
27 return xPRIMARY_MONITOR;
29 return (HMONITOR)0;
32 /***********************************************************************
33 * MonitorFromRect
35 HMONITOR WINAPI MonitorFromRect(LPRECT lprcScreenCoords, DWORD dwFlags)
37 if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
38 ((lprcScreenCoords->right > 0) &&
39 (lprcScreenCoords->bottom > 0) &&
40 (lprcScreenCoords->left < GetSystemMetrics(SM_CXSCREEN)) &&
41 (lprcScreenCoords->top < GetSystemMetrics(SM_CYSCREEN))))
43 return xPRIMARY_MONITOR;
45 return (HMONITOR)0;
48 /***********************************************************************
49 * MonitorFromWindow
51 HMONITOR WINAPI MonitorFromWindow(HWND hWnd, DWORD dwFlags)
53 WINDOWPLACEMENT wp;
55 if (dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST))
56 return xPRIMARY_MONITOR;
58 if (IsIconic(hWnd) ?
59 GetWindowPlacement(hWnd, &wp) :
60 GetWindowRect(hWnd, &wp.rcNormalPosition)) {
62 return MonitorFromRect(&wp.rcNormalPosition, dwFlags);
65 return (HMONITOR)0;
68 /***********************************************************************
69 * GetMonitorInfoA
71 BOOL WINAPI GetMonitorInfoA(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
73 RECT rcWork;
75 if ((hMonitor == xPRIMARY_MONITOR) &&
76 lpMonitorInfo &&
77 (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
78 SystemParametersInfoA(SPI_GETWORKAREA, 0, &rcWork, 0))
80 SetRect( &lpMonitorInfo->rcMonitor, 0, 0,
81 GetSystemMetrics(SM_CXSCREEN),
82 GetSystemMetrics(SM_CYSCREEN) );
83 lpMonitorInfo->rcWork = rcWork;
84 lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
86 if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEXA))
87 lstrcpyA(((MONITORINFOEXA*)lpMonitorInfo)->szDevice, "DISPLAY");
89 return TRUE;
92 return FALSE;
95 /***********************************************************************
96 * GetMonitorInfoW
98 BOOL WINAPI GetMonitorInfoW(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
100 RECT rcWork;
102 if ((hMonitor == xPRIMARY_MONITOR) &&
103 lpMonitorInfo &&
104 (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
105 SystemParametersInfoW(SPI_GETWORKAREA, 0, &rcWork, 0))
107 SetRect( &lpMonitorInfo->rcMonitor, 0, 0,
108 GetSystemMetrics(SM_CXSCREEN),
109 GetSystemMetrics(SM_CYSCREEN) );
110 lpMonitorInfo->rcWork = rcWork;
111 lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
113 if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEXW))
114 lstrcpyW(((MONITORINFOEXW*)lpMonitorInfo)->szDevice, (LPCWSTR)"D\0I\0S\0P\0L\0A\0Y\0\0");
116 return TRUE;
119 return FALSE;
122 /***********************************************************************
123 * EnumDisplayMonitors
125 BOOL WINAPI EnumDisplayMonitors(
126 HDC hdcOptionalForPainting,
127 LPRECT lprcEnumMonitorsThatIntersect,
128 MONITORENUMPROC lpfnEnumProc,
129 LPARAM dwData)
131 RECT rcLimit;
132 SetRect( &rcLimit, 0, 0, GetSystemMetrics(SM_CXSCREEN),
133 GetSystemMetrics(SM_CYSCREEN) );
135 if (!lpfnEnumProc)
136 return FALSE;
138 if (hdcOptionalForPainting)
140 RECT rcClip;
141 POINT ptOrg;
143 switch (GetClipBox(hdcOptionalForPainting, &rcClip))
145 default:
146 if (!GetDCOrgEx(hdcOptionalForPainting, &ptOrg))
147 return FALSE;
149 OffsetRect(&rcLimit, -ptOrg.x, -ptOrg.y);
150 if (IntersectRect(&rcLimit, &rcLimit, &rcClip) &&
151 (!lprcEnumMonitorsThatIntersect ||
152 IntersectRect(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect))) {
154 break;
156 /*fall thru */
157 case NULLREGION:
158 return TRUE;
159 case ERROR:
160 return FALSE;
162 } else {
163 if ( lprcEnumMonitorsThatIntersect &&
164 !IntersectRect(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect)) {
166 return TRUE;
170 return lpfnEnumProc(
171 xPRIMARY_MONITOR,
172 hdcOptionalForPainting,
173 &rcLimit,
174 dwData);