Remove duplicate definition of _tmain.
[wine.git] / windows / multimon.c
blobe770482497e1b8d7ca1a57268cd454089a160d94
1 /*
2 * Multimonitor APIs
4 * Copyright 1998 Turchanov Sergey
5 */
7 #include <string.h>
8 #include "windef.h"
9 #include "wingdi.h"
10 #include "winbase.h"
11 #include "winuser.h"
12 #include "wine/unicode.h"
14 /**********************************************************************/
16 #define xPRIMARY_MONITOR ((HMONITOR)0x12340042)
18 /***********************************************************************
19 * MonitorFromPoint (USER32.@)
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 (HMONITOR)0;
34 /***********************************************************************
35 * MonitorFromRect (USER32.@)
37 HMONITOR WINAPI MonitorFromRect(LPRECT lprcScreenCoords, DWORD dwFlags)
39 if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
40 ((lprcScreenCoords->right > 0) &&
41 (lprcScreenCoords->bottom > 0) &&
42 (lprcScreenCoords->left < GetSystemMetrics(SM_CXSCREEN)) &&
43 (lprcScreenCoords->top < GetSystemMetrics(SM_CYSCREEN))))
45 return xPRIMARY_MONITOR;
47 return (HMONITOR)0;
50 /***********************************************************************
51 * MonitorFromWindow (USER32.@)
53 HMONITOR WINAPI MonitorFromWindow(HWND hWnd, DWORD dwFlags)
55 WINDOWPLACEMENT wp;
57 if (dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST))
58 return xPRIMARY_MONITOR;
60 if (IsIconic(hWnd) ?
61 GetWindowPlacement(hWnd, &wp) :
62 GetWindowRect(hWnd, &wp.rcNormalPosition)) {
64 return MonitorFromRect(&wp.rcNormalPosition, dwFlags);
67 return (HMONITOR)0;
70 /***********************************************************************
71 * GetMonitorInfoA (USER32.@)
73 BOOL WINAPI GetMonitorInfoA(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
75 RECT rcWork;
77 if ((hMonitor == xPRIMARY_MONITOR) &&
78 lpMonitorInfo &&
79 (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
80 SystemParametersInfoA(SPI_GETWORKAREA, 0, &rcWork, 0))
82 SetRect( &lpMonitorInfo->rcMonitor, 0, 0,
83 GetSystemMetrics(SM_CXSCREEN),
84 GetSystemMetrics(SM_CYSCREEN) );
85 lpMonitorInfo->rcWork = rcWork;
86 lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
88 if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEXA))
89 strcpy(((MONITORINFOEXA*)lpMonitorInfo)->szDevice, "DISPLAY");
91 return TRUE;
94 return FALSE;
97 /***********************************************************************
98 * GetMonitorInfoW (USER32.@)
100 BOOL WINAPI GetMonitorInfoW(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
102 RECT rcWork;
104 if ((hMonitor == xPRIMARY_MONITOR) &&
105 lpMonitorInfo &&
106 (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
107 SystemParametersInfoW(SPI_GETWORKAREA, 0, &rcWork, 0))
109 SetRect( &lpMonitorInfo->rcMonitor, 0, 0,
110 GetSystemMetrics(SM_CXSCREEN),
111 GetSystemMetrics(SM_CYSCREEN) );
112 lpMonitorInfo->rcWork = rcWork;
113 lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
115 if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEXW))
116 strcpyW(((MONITORINFOEXW*)lpMonitorInfo)->szDevice, (LPCWSTR)"D\0I\0S\0P\0L\0A\0Y\0\0");
118 return TRUE;
121 return FALSE;
124 /***********************************************************************
125 * EnumDisplayMonitors (USER32.@)
127 BOOL WINAPI EnumDisplayMonitors(
128 HDC hdcOptionalForPainting,
129 LPRECT lprcEnumMonitorsThatIntersect,
130 MONITORENUMPROC lpfnEnumProc,
131 LPARAM dwData)
133 RECT rcLimit;
134 SetRect( &rcLimit, 0, 0, GetSystemMetrics(SM_CXSCREEN),
135 GetSystemMetrics(SM_CYSCREEN) );
137 if (!lpfnEnumProc)
138 return FALSE;
140 if (hdcOptionalForPainting)
142 RECT rcClip;
143 POINT ptOrg;
145 switch (GetClipBox(hdcOptionalForPainting, &rcClip))
147 default:
148 if (!GetDCOrgEx(hdcOptionalForPainting, &ptOrg))
149 return FALSE;
151 OffsetRect(&rcLimit, -ptOrg.x, -ptOrg.y);
152 if (IntersectRect(&rcLimit, &rcLimit, &rcClip) &&
153 (!lprcEnumMonitorsThatIntersect ||
154 IntersectRect(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect))) {
156 break;
158 /* fall through */
159 case NULLREGION:
160 return TRUE;
161 case ERROR:
162 return FALSE;
164 } else {
165 if ( lprcEnumMonitorsThatIntersect &&
166 !IntersectRect(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect)) {
168 return TRUE;
172 return lpfnEnumProc(
173 xPRIMARY_MONITOR,
174 hdcOptionalForPainting,
175 &rcLimit,
176 dwData);