6 //=============================================================================
9 // stub module that "stubs" multiple monitor APIs on pre-Memphis Win32 OSes
11 // By using this header your code will work unchanged on Win95,
12 // you will get back correct values from GetSystemMetrics() for new metrics
13 // and the new APIs will act like only one display is present.
15 // exactly one source must include this with COMPILE_MULTIMON_STUBS defined
17 //=============================================================================
20 extern "C" { /* Assume C declarations for C++ */
21 #endif /* __cplusplus */
24 // if we are building on Win95/NT4 headers we need to declare this stuff ourselves
28 #define SM_XVIRTUALSCREEN 76
29 #define SM_YVIRTUALSCREEN 77
30 #define SM_CXVIRTUALSCREEN 78
31 #define SM_CYVIRTUALSCREEN 79
32 #define SM_CMONITORS 80
33 #define SM_SAMEDISPLAYFORMAT 81
35 DECLARE_HANDLE(HMONITOR);
37 #define MONITOR_DEFAULTTONULL 0x00000000
38 #define MONITOR_DEFAULTTOPRIMARY 0x00000001
39 #define MONITOR_DEFAULTTONEAREST 0x00000002
41 #define MONITORINFOF_PRIMARY 0x00000001
43 typedef struct tagMONITORINFO
49 } MONITORINFO, *LPMONITORINFO;
51 #define CCHDEVICENAME 32
54 typedef struct tagMONITORINFOEX : public tagMONITORINFO
56 TCHAR szDevice[CCHDEVICENAME];
57 } MONITORINFOEX, *LPMONITORINFOEX;
62 TCHAR szDevice[CCHDEVICENAME];
63 } MONITORINFOEX, *LPMONITORINFOEX;
66 typedef BOOL (CALLBACK* MONITORENUMPROC)(HMONITOR, HDC, LPRECT, LPARAM);
68 #endif // SM_CMONITORS
70 #ifndef DISPLAY_DEVICE_ATTACHED_TO_DESKTOP
75 CHAR DeviceString[128];
79 #define DISPLAY_DEVICE_ATTACHED_TO_DESKTOP 0x00000001
80 #define DISPLAY_DEVICE_MULTI_DRIVER 0x00000002
81 #define DISPLAY_DEVICE_PRIMARY_DEVICE 0x00000004
82 #define DISPLAY_DEVICE_MIRRORING_DRIVER 0x00000008
85 #define DISPLAY_DEVICE_VGA 0x00000010
87 #ifndef ENUM_CURRENT_SETTINGS
88 #define ENUM_CURRENT_SETTINGS ((DWORD)-1)
89 #define ENUM_REGISTRY_SETTINGS ((DWORD)-2)
93 #undef GetSystemMetrics
94 #undef MonitorFromWindow
95 #undef MonitorFromRect
96 #undef MonitorFromPoint
97 #undef EnumDisplayMonitors
98 #undef EnumDisplayDevices
101 // define this to compile the stubs
102 // otherwise you get the declarations
104 #ifdef COMPILE_MULTIMON_STUBS
106 //---------------------------------------------------------------------------
108 // Implement the API stubs.
110 //---------------------------------------------------------------------------
112 int (WINAPI* g_pfnGetSystemMetrics)(int);
113 HMONITOR (WINAPI* g_pfnMonitorFromWindow)(HWND, BOOL);
114 HMONITOR (WINAPI* g_pfnMonitorFromRect)(LPCRECT, BOOL);
115 HMONITOR (WINAPI* g_pfnMonitorFromPoint)(POINT, BOOL);
116 BOOL (WINAPI* g_pfnGetMonitorInfo)(HMONITOR, LPMONITORINFO);
117 BOOL (WINAPI* g_pfnEnumDisplayMonitors)(HDC, LPCRECT, MONITORENUMPROC, LPARAM);
118 BOOL (WINAPI *g_pfnEnumDisplayDevices)(LPVOID, int, DISPLAY_DEVICE *, DWORD);
120 BOOL InitMultipleMonitorStubs(void)
123 static BOOL fInitDone;
127 return g_pfnGetMonitorInfo != NULL;
130 if ((hUser32 = GetModuleHandle(TEXT("USER32"))) &&
131 (*(FARPROC*)&g_pfnGetSystemMetrics = GetProcAddress(hUser32,"GetSystemMetrics")) &&
132 (*(FARPROC*)&g_pfnMonitorFromWindow = GetProcAddress(hUser32,"MonitorFromWindow")) &&
133 (*(FARPROC*)&g_pfnMonitorFromRect = GetProcAddress(hUser32,"MonitorFromRect")) &&
134 (*(FARPROC*)&g_pfnMonitorFromPoint = GetProcAddress(hUser32,"MonitorFromPoint")) &&
135 (*(FARPROC*)&g_pfnEnumDisplayMonitors = GetProcAddress(hUser32,"EnumDisplayMonitors")) &&
137 (*(FARPROC*)&g_pfnGetMonitorInfo = GetProcAddress(hUser32,"GetMonitorInfoW")) &&
138 (*(FARPROC*)&g_pfnEnumDisplayDevices = GetProcAddress(hUser32,"EnumDisplayDevicesW")) &&
140 (*(FARPROC*)&g_pfnGetMonitorInfo = GetProcAddress(hUser32,"GetMonitorInfoA")) &&
141 (*(FARPROC*)&g_pfnEnumDisplayDevices = GetProcAddress(hUser32,"EnumDisplayDevicesA")) &&
143 (GetSystemMetrics(SM_CXVIRTUALSCREEN) >= GetSystemMetrics(SM_CXSCREEN)) &&
144 (GetSystemMetrics(SM_CYVIRTUALSCREEN) >= GetSystemMetrics(SM_CYSCREEN)) )
151 g_pfnGetSystemMetrics = NULL;
152 g_pfnMonitorFromWindow = NULL;
153 g_pfnMonitorFromRect = NULL;
154 g_pfnMonitorFromPoint = NULL;
155 g_pfnGetMonitorInfo = NULL;
156 g_pfnEnumDisplayMonitors = NULL;
157 g_pfnEnumDisplayDevices = NULL;
164 //---------------------------------------------------------------------------
166 // "stubbed" implementations of Monitor APIs that work with the primary // display
168 //---------------------------------------------------------------------------
171 xGetSystemMetrics(int nIndex)
173 if (InitMultipleMonitorStubs())
174 return g_pfnGetSystemMetrics(nIndex);
179 case SM_SAMEDISPLAYFORMAT:
182 case SM_XVIRTUALSCREEN:
183 case SM_YVIRTUALSCREEN:
186 case SM_CXVIRTUALSCREEN:
187 nIndex = SM_CXSCREEN;
190 case SM_CYVIRTUALSCREEN:
191 nIndex = SM_CYSCREEN;
195 return GetSystemMetrics(nIndex);
198 #define xPRIMARY_MONITOR ((HMONITOR)0x42)
201 xMonitorFromRect(LPCRECT lprcScreenCoords,
204 if (InitMultipleMonitorStubs())
205 return g_pfnMonitorFromRect(lprcScreenCoords, uFlags);
207 if ((uFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
208 ((lprcScreenCoords->right > 0) &&
209 (lprcScreenCoords->bottom > 0) &&
210 (lprcScreenCoords->left < GetSystemMetrics(SM_CXSCREEN)) &&
211 (lprcScreenCoords->top < GetSystemMetrics(SM_CYSCREEN))))
213 return xPRIMARY_MONITOR;
220 xMonitorFromWindow(HWND hWnd,
225 if (InitMultipleMonitorStubs())
226 return g_pfnMonitorFromWindow(hWnd, uFlags);
228 if (uFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST))
229 return xPRIMARY_MONITOR;
231 if (GetWindowRect(hWnd, &rc))
232 return xMonitorFromRect(&rc, uFlags);
238 xMonitorFromPoint(POINT ptScreenCoords,
241 if (InitMultipleMonitorStubs())
242 return g_pfnMonitorFromPoint(ptScreenCoords, uFlags);
244 if ((uFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
245 ((ptScreenCoords.x >= 0) &&
246 (ptScreenCoords.x < GetSystemMetrics(SM_CXSCREEN)) &&
247 (ptScreenCoords.y >= 0) &&
248 (ptScreenCoords.y < GetSystemMetrics(SM_CYSCREEN))))
250 return xPRIMARY_MONITOR;
257 xGetMonitorInfo(HMONITOR hMonitor,
258 LPMONITORINFO lpMonitorInfo)
262 if (InitMultipleMonitorStubs())
263 return g_pfnGetMonitorInfo(hMonitor, lpMonitorInfo);
265 if ((hMonitor == xPRIMARY_MONITOR) && lpMonitorInfo &&
266 (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
267 SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWork, 0))
269 lpMonitorInfo->rcMonitor.left = 0;
270 lpMonitorInfo->rcMonitor.top = 0;
271 lpMonitorInfo->rcMonitor.right = GetSystemMetrics(SM_CXSCREEN);
272 lpMonitorInfo->rcMonitor.bottom = GetSystemMetrics(SM_CYSCREEN);
273 lpMonitorInfo->rcWork = rcWork;
274 lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
276 if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEX))
277 lstrcpy(((MONITORINFOEX*)lpMonitorInfo)->szDevice,
287 xEnumDisplayMonitors(HDC hdc,
288 LPCRECT lprcIntersect,
289 MONITORENUMPROC lpfnEnumProc,
292 RECT rcCallback, rcLimit;
294 if (InitMultipleMonitorStubs())
295 return g_pfnEnumDisplayMonitors(hdc, lprcIntersect, lpfnEnumProc, lData);
302 rcLimit.right = GetSystemMetrics(SM_CXSCREEN);
303 rcLimit.bottom = GetSystemMetrics(SM_CYSCREEN);
310 if ((hWnd = WindowFromDC(hdc)) == NULL)
313 switch (GetClipBox(hdc, &rcClip))
316 MapWindowPoints(NULL, hWnd, (LPPOINT)&rcLimit, 2);
317 if (IntersectRect(&rcCallback, &rcClip, &rcLimit))
326 rcLimit = rcCallback;
329 if (!lprcIntersect || IntersectRect(&rcCallback, lprcIntersect, &rcLimit))
331 lpfnEnumProc(xPRIMARY_MONITOR, hdc, &rcCallback, lData);
338 xEnumDisplayDevices(LPVOID lpReserved,
340 DISPLAY_DEVICE * pDisplayDevice,
343 if (InitMultipleMonitorStubs())
344 return g_pfnEnumDisplayDevices(lpReserved, iDeviceNum, pDisplayDevice, dwFlags);
349 #undef xPRIMARY_MONITOR
350 #undef COMPILE_MULTIMON_STUBS
352 #else // COMPILE_MULTIMON_STUBS
354 extern int WINAPI xGetSystemMetrics(int);
355 extern HMONITOR WINAPI xMonitorFromWindow(HWND, UINT);
356 extern HMONITOR WINAPI xMonitorFromRect(LPCRECT, UINT);
357 extern HMONITOR WINAPI xMonitorFromPoint(POINT, UINT);
358 extern BOOL WINAPI xGetMonitorInfo(HMONITOR, LPMONITORINFO);
359 extern BOOL WINAPI xEnumDisplayMonitors(HDC, LPCRECT, MONITORENUMPROC, LPARAM);
360 extern BOOL WINAPI xEnumDisplayDevices(LPVOID, int, DISPLAY_DEVICE *, DWORD);
362 #endif // COMPILE_MULTIMON_STUBS
365 // build defines that replace the regular APIs with our versions
367 #define GetSystemMetrics xGetSystemMetrics
368 #define MonitorFromWindow xMonitorFromWindow
369 #define MonitorFromRect xMonitorFromRect
370 #define MonitorFromPoint xMonitorFromPoint
371 #define GetMonitorInfo xGetMonitorInfo
372 #define EnumDisplayMonitors xEnumDisplayMonitors
373 #define EnumDisplayDevices xEnumDisplayDevices
377 #endif // __cplusplus
381 #endif // __MULTIMON_H