-#ifndef __MULTIMON_H\r
-#define __MULTIMON_H\r
-\r
-#ifdef _WIN32\r
-\r
-//=============================================================================\r
-//\r
-// MULTIMON\r
-// stub module that "stubs" multiple monitor APIs on pre-Memphis Win32 OSes\r
-//\r
-// By using this header your code will work unchanged on Win95,\r
-// you will get back correct values from GetSystemMetrics() for new metrics\r
-// and the new APIs will act like only one display is present.\r
-//\r
-// exactly one source must include this with COMPILE_MULTIMON_STUBS defined\r
-//\r
-//=============================================================================\r
-\r
-#ifdef __cplusplus\r
-extern "C" { /* Assume C declarations for C++ */\r
-#endif /* __cplusplus */\r
-\r
-//\r
-// if we are building on Win95/NT4 headers we need to declare this stuff ourselves\r
-//\r
-#ifndef SM_CMONITORS\r
-\r
-#define SM_XVIRTUALSCREEN 76\r
-#define SM_YVIRTUALSCREEN 77\r
-#define SM_CXVIRTUALSCREEN 78\r
-#define SM_CYVIRTUALSCREEN 79\r
-#define SM_CMONITORS 80\r
-#define SM_SAMEDISPLAYFORMAT 81\r
-\r
-DECLARE_HANDLE(HMONITOR);\r
-\r
-#define MONITOR_DEFAULTTONULL 0x00000000\r
-#define MONITOR_DEFAULTTOPRIMARY 0x00000001\r
-#define MONITOR_DEFAULTTONEAREST 0x00000002\r
-\r
-#define MONITORINFOF_PRIMARY 0x00000001\r
-\r
-typedef struct tagMONITORINFO\r
-{\r
- DWORD cbSize;\r
- RECT rcMonitor;\r
- RECT rcWork;\r
- DWORD dwFlags;\r
-} MONITORINFO, *LPMONITORINFO;\r
-\r
-#define CCHDEVICENAME 32\r
-\r
-#ifdef __cplusplus\r
-typedef struct tagMONITORINFOEX : public tagMONITORINFO\r
-{\r
- TCHAR szDevice[CCHDEVICENAME];\r
-} MONITORINFOEX, *LPMONITORINFOEX;\r
-#else\r
-typedef struct\r
-{\r
- MONITORINFO;\r
- TCHAR szDevice[CCHDEVICENAME];\r
-} MONITORINFOEX, *LPMONITORINFOEX;\r
-#endif\r
-\r
-typedef BOOL (CALLBACK* MONITORENUMPROC)(HMONITOR, HDC, LPRECT, LPARAM);\r
-\r
-#endif // SM_CMONITORS\r
-\r
-#ifndef DISPLAY_DEVICE_ATTACHED_TO_DESKTOP\r
-\r
-typedef struct {\r
- DWORD cb;\r
- CHAR DeviceName[32];\r
- CHAR DeviceString[128];\r
- DWORD StateFlags;\r
-} DISPLAY_DEVICE;\r
-\r
-#define DISPLAY_DEVICE_ATTACHED_TO_DESKTOP 0x00000001\r
-#define DISPLAY_DEVICE_MULTI_DRIVER 0x00000002\r
-#define DISPLAY_DEVICE_PRIMARY_DEVICE 0x00000004\r
-#define DISPLAY_DEVICE_MIRRORING_DRIVER 0x00000008\r
-\r
-#endif\r
-#define DISPLAY_DEVICE_VGA 0x00000010\r
-\r
-#ifndef ENUM_CURRENT_SETTINGS\r
-#define ENUM_CURRENT_SETTINGS ((DWORD)-1)\r
-#define ENUM_REGISTRY_SETTINGS ((DWORD)-2)\r
-#endif\r
-\r
-#undef GetMonitorInfo\r
-#undef GetSystemMetrics\r
-#undef MonitorFromWindow\r
-#undef MonitorFromRect\r
-#undef MonitorFromPoint\r
-#undef EnumDisplayMonitors\r
-#undef EnumDisplayDevices\r
-\r
-//\r
-// define this to compile the stubs\r
-// otherwise you get the declarations\r
-//\r
-#ifdef COMPILE_MULTIMON_STUBS\r
-\r
- //---------------------------------------------------------------------------\r
- //\r
- // Implement the API stubs.\r
- //\r
- //---------------------------------------------------------------------------\r
-\r
- int (WINAPI* g_pfnGetSystemMetrics)(int);\r
- HMONITOR (WINAPI* g_pfnMonitorFromWindow)(HWND, BOOL);\r
- HMONITOR (WINAPI* g_pfnMonitorFromRect)(LPCRECT, BOOL);\r
- HMONITOR (WINAPI* g_pfnMonitorFromPoint)(POINT, BOOL);\r
- BOOL (WINAPI* g_pfnGetMonitorInfo)(HMONITOR, LPMONITORINFO);\r
- BOOL (WINAPI* g_pfnEnumDisplayMonitors)(HDC, LPCRECT, MONITORENUMPROC, LPARAM);\r
- BOOL (WINAPI *g_pfnEnumDisplayDevices)(LPVOID, int, DISPLAY_DEVICE *, DWORD);\r
-\r
- BOOL InitMultipleMonitorStubs(void)\r
- {\r
- HMODULE hUser32;\r
- static BOOL fInitDone;\r
-\r
- if (fInitDone)\r
- {\r
- return g_pfnGetMonitorInfo != NULL;\r
- }\r
-\r
- if ((hUser32 = GetModuleHandle(TEXT("USER32"))) &&\r
- (*(FARPROC*)&g_pfnGetSystemMetrics = GetProcAddress(hUser32,"GetSystemMetrics")) &&\r
- (*(FARPROC*)&g_pfnMonitorFromWindow = GetProcAddress(hUser32,"MonitorFromWindow")) &&\r
- (*(FARPROC*)&g_pfnMonitorFromRect = GetProcAddress(hUser32,"MonitorFromRect")) &&\r
- (*(FARPROC*)&g_pfnMonitorFromPoint = GetProcAddress(hUser32,"MonitorFromPoint")) &&\r
- (*(FARPROC*)&g_pfnEnumDisplayMonitors = GetProcAddress(hUser32,"EnumDisplayMonitors")) &&\r
- #ifdef UNICODE\r
- (*(FARPROC*)&g_pfnGetMonitorInfo = GetProcAddress(hUser32,"GetMonitorInfoW")) &&\r
- (*(FARPROC*)&g_pfnEnumDisplayDevices = GetProcAddress(hUser32,"EnumDisplayDevicesW")) &&\r
- #else\r
- (*(FARPROC*)&g_pfnGetMonitorInfo = GetProcAddress(hUser32,"GetMonitorInfoA")) &&\r
- (*(FARPROC*)&g_pfnEnumDisplayDevices = GetProcAddress(hUser32,"EnumDisplayDevicesA")) &&\r
- #endif\r
- (GetSystemMetrics(SM_CXVIRTUALSCREEN) >= GetSystemMetrics(SM_CXSCREEN)) &&\r
- (GetSystemMetrics(SM_CYVIRTUALSCREEN) >= GetSystemMetrics(SM_CYSCREEN)) )\r
- {\r
- fInitDone = TRUE;\r
- return TRUE;\r
- }\r
- else\r
- {\r
- g_pfnGetSystemMetrics = NULL;\r
- g_pfnMonitorFromWindow = NULL;\r
- g_pfnMonitorFromRect = NULL;\r
- g_pfnMonitorFromPoint = NULL;\r
- g_pfnGetMonitorInfo = NULL;\r
- g_pfnEnumDisplayMonitors = NULL;\r
- g_pfnEnumDisplayDevices = NULL;\r
-\r
- fInitDone = TRUE;\r
- return FALSE;\r
- }\r
- }\r
-\r
- //---------------------------------------------------------------------------\r
- //\r
- // "stubbed" implementations of Monitor APIs that work with the primary // display\r
- //\r
- //---------------------------------------------------------------------------\r
-\r
- int WINAPI\r
- xGetSystemMetrics(int nIndex)\r
- {\r
- if (InitMultipleMonitorStubs())\r
- return g_pfnGetSystemMetrics(nIndex);\r
-\r
- switch (nIndex)\r
- {\r
- case SM_CMONITORS:\r
- case SM_SAMEDISPLAYFORMAT:\r
- return 1;\r
-\r
- case SM_XVIRTUALSCREEN:\r
- case SM_YVIRTUALSCREEN:\r
- return 0;\r
-\r
- case SM_CXVIRTUALSCREEN:\r
- nIndex = SM_CXSCREEN;\r
- break;\r
-\r
- case SM_CYVIRTUALSCREEN:\r
- nIndex = SM_CYSCREEN;\r
- break;\r
- }\r
-\r
- return GetSystemMetrics(nIndex);\r
- }\r
-\r
- #define xPRIMARY_MONITOR ((HMONITOR)0x42)\r
-\r
- HMONITOR WINAPI\r
- xMonitorFromRect(LPCRECT lprcScreenCoords,\r
- UINT uFlags)\r
- {\r
- if (InitMultipleMonitorStubs())\r
- return g_pfnMonitorFromRect(lprcScreenCoords, uFlags);\r
-\r
- if ((uFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||\r
- ((lprcScreenCoords->right > 0) &&\r
- (lprcScreenCoords->bottom > 0) &&\r
- (lprcScreenCoords->left < GetSystemMetrics(SM_CXSCREEN)) &&\r
- (lprcScreenCoords->top < GetSystemMetrics(SM_CYSCREEN))))\r
- {\r
- return xPRIMARY_MONITOR;\r
- }\r
-\r
- return NULL;\r
- }\r
-\r
- HMONITOR WINAPI\r
- xMonitorFromWindow(HWND hWnd,\r
- UINT uFlags)\r
- {\r
- RECT rc;\r
-\r
- if (InitMultipleMonitorStubs())\r
- return g_pfnMonitorFromWindow(hWnd, uFlags);\r
-\r
- if (uFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST))\r
- return xPRIMARY_MONITOR;\r
-\r
- if (GetWindowRect(hWnd, &rc))\r
- return xMonitorFromRect(&rc, uFlags);\r
-\r
- return NULL;\r
- }\r
-\r
- HMONITOR WINAPI\r
- xMonitorFromPoint(POINT ptScreenCoords,\r
- UINT uFlags)\r
- {\r
- if (InitMultipleMonitorStubs())\r
- return g_pfnMonitorFromPoint(ptScreenCoords, uFlags);\r
-\r
- if ((uFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||\r
- ((ptScreenCoords.x >= 0) &&\r
- (ptScreenCoords.x < GetSystemMetrics(SM_CXSCREEN)) &&\r
- (ptScreenCoords.y >= 0) &&\r
- (ptScreenCoords.y < GetSystemMetrics(SM_CYSCREEN))))\r
- {\r
- return xPRIMARY_MONITOR;\r
- }\r
-\r
- return NULL;\r
- }\r
-\r
- BOOL WINAPI\r
- xGetMonitorInfo(HMONITOR hMonitor,\r
- LPMONITORINFO lpMonitorInfo)\r
- {\r
- RECT rcWork;\r
-\r
- if (InitMultipleMonitorStubs())\r
- return g_pfnGetMonitorInfo(hMonitor, lpMonitorInfo);\r
-\r
- if ((hMonitor == xPRIMARY_MONITOR) && lpMonitorInfo &&\r
- (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&\r
- SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWork, 0))\r
- {\r
- lpMonitorInfo->rcMonitor.left = 0;\r
- lpMonitorInfo->rcMonitor.top = 0;\r
- lpMonitorInfo->rcMonitor.right = GetSystemMetrics(SM_CXSCREEN);\r
- lpMonitorInfo->rcMonitor.bottom = GetSystemMetrics(SM_CYSCREEN);\r
- lpMonitorInfo->rcWork = rcWork;\r
- lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;\r
-\r
- if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEX))\r
- lstrcpy(((MONITORINFOEX*)lpMonitorInfo)->szDevice,\r
- TEXT("DISPLAY"));\r
-\r
- return TRUE;\r
- }\r
-\r
- return FALSE;\r
- }\r
-\r
- BOOL WINAPI\r
- xEnumDisplayMonitors(HDC hdc,\r
- LPCRECT lprcIntersect, \r
- MONITORENUMPROC lpfnEnumProc,\r
- LPARAM lData)\r
- {\r
- RECT rcCallback, rcLimit;\r
-\r
- if (InitMultipleMonitorStubs())\r
- return g_pfnEnumDisplayMonitors(hdc, lprcIntersect, lpfnEnumProc, lData);\r
- \r
- if (!lpfnEnumProc)\r
- return FALSE;\r
-\r
- rcLimit.left = 0;\r
- rcLimit.top = 0;\r
- rcLimit.right = GetSystemMetrics(SM_CXSCREEN);\r
- rcLimit.bottom = GetSystemMetrics(SM_CYSCREEN);\r
-\r
- if (hdc)\r
- {\r
- RECT rcClip;\r
- HWND hWnd;\r
-\r
- if ((hWnd = WindowFromDC(hdc)) == NULL)\r
- return FALSE;\r
-\r
- switch (GetClipBox(hdc, &rcClip))\r
- {\r
- default:\r
- MapWindowPoints(NULL, hWnd, (LPPOINT)&rcLimit, 2);\r
- if (IntersectRect(&rcCallback, &rcClip, &rcLimit))\r
- break;\r
- //fall thru\r
- case NULLREGION:\r
- return TRUE;\r
- case ERROR:\r
- return FALSE;\r
- }\r
-\r
- rcLimit = rcCallback;\r
- }\r
-\r
- if (!lprcIntersect || IntersectRect(&rcCallback, lprcIntersect, &rcLimit))\r
- {\r
- lpfnEnumProc(xPRIMARY_MONITOR, hdc, &rcCallback, lData);\r
- }\r
-\r
- return TRUE;\r
- }\r
-\r
- BOOL WINAPI\r
- xEnumDisplayDevices(LPVOID lpReserved,\r
- int iDeviceNum, \r
- DISPLAY_DEVICE * pDisplayDevice,\r
- DWORD dwFlags)\r
- {\r
- if (InitMultipleMonitorStubs())\r
- return g_pfnEnumDisplayDevices(lpReserved, iDeviceNum, pDisplayDevice, dwFlags);\r
- \r
- return FALSE;\r
- }\r
-\r
- #undef xPRIMARY_MONITOR\r
- #undef COMPILE_MULTIMON_STUBS\r
-\r
-#else // COMPILE_MULTIMON_STUBS\r
-\r
- extern int WINAPI xGetSystemMetrics(int);\r
- extern HMONITOR WINAPI xMonitorFromWindow(HWND, UINT);\r
- extern HMONITOR WINAPI xMonitorFromRect(LPCRECT, UINT);\r
- extern HMONITOR WINAPI xMonitorFromPoint(POINT, UINT);\r
- extern BOOL WINAPI xGetMonitorInfo(HMONITOR, LPMONITORINFO);\r
- extern BOOL WINAPI xEnumDisplayMonitors(HDC, LPCRECT, MONITORENUMPROC, LPARAM);\r
- extern BOOL WINAPI xEnumDisplayDevices(LPVOID, int, DISPLAY_DEVICE *, DWORD);\r
-\r
-#endif // COMPILE_MULTIMON_STUBS\r
-\r
-//\r
-// build defines that replace the regular APIs with our versions\r
-//\r
-#define GetSystemMetrics xGetSystemMetrics\r
-#define MonitorFromWindow xMonitorFromWindow\r
-#define MonitorFromRect xMonitorFromRect\r
-#define MonitorFromPoint xMonitorFromPoint\r
-#define GetMonitorInfo xGetMonitorInfo\r
-#define EnumDisplayMonitors xEnumDisplayMonitors\r
-#define EnumDisplayDevices xEnumDisplayDevices\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif // __cplusplus\r
-\r
-#endif // WIN32\r
-\r
-#endif // __MULTIMON_H
\ No newline at end of file
+#ifndef __MULTIMON_H
+#define __MULTIMON_H
+
+#ifdef _WIN32
+
+//=============================================================================
+//
+// MULTIMON
+// stub module that "stubs" multiple monitor APIs on pre-Memphis Win32 OSes
+//
+// By using this header your code will work unchanged on Win95,
+// you will get back correct values from GetSystemMetrics() for new metrics
+// and the new APIs will act like only one display is present.
+//
+// exactly one source must include this with COMPILE_MULTIMON_STUBS defined
+//
+//=============================================================================
+
+#ifdef __cplusplus
+extern "C" { /* Assume C declarations for C++ */
+#endif /* __cplusplus */
+
+//
+// if we are building on Win95/NT4 headers we need to declare this stuff ourselves
+//
+#ifndef SM_CMONITORS
+
+#define SM_XVIRTUALSCREEN 76
+#define SM_YVIRTUALSCREEN 77
+#define SM_CXVIRTUALSCREEN 78
+#define SM_CYVIRTUALSCREEN 79
+#define SM_CMONITORS 80
+#define SM_SAMEDISPLAYFORMAT 81
+
+DECLARE_HANDLE( HMONITOR );
+
+#define MONITOR_DEFAULTTONULL 0x00000000
+#define MONITOR_DEFAULTTOPRIMARY 0x00000001
+#define MONITOR_DEFAULTTONEAREST 0x00000002
+
+#define MONITORINFOF_PRIMARY 0x00000001
+
+typedef struct tagMONITORINFO
+{
+ DWORD cbSize;
+ RECT rcMonitor;
+ RECT rcWork;
+ DWORD dwFlags;
+} MONITORINFO, *LPMONITORINFO;
+
+#define CCHDEVICENAME 32
+
+#ifdef __cplusplus
+typedef struct tagMONITORINFOEX : public tagMONITORINFO
+{
+ TCHAR szDevice[CCHDEVICENAME];
+} MONITORINFOEX, *LPMONITORINFOEX;
+#else
+typedef struct
+{
+ MONITORINFO;
+ TCHAR szDevice[CCHDEVICENAME];
+} MONITORINFOEX, *LPMONITORINFOEX;
+#endif
+
+typedef BOOL ( CALLBACK * MONITORENUMPROC )( HMONITOR, HDC, LPRECT, LPARAM );
+
+#endif // SM_CMONITORS
+
+#ifndef DISPLAY_DEVICE_ATTACHED_TO_DESKTOP
+
+typedef struct {
+ DWORD cb;
+ CHAR DeviceName[32];
+ CHAR DeviceString[128];
+ DWORD StateFlags;
+} DISPLAY_DEVICE;
+
+#define DISPLAY_DEVICE_ATTACHED_TO_DESKTOP 0x00000001
+#define DISPLAY_DEVICE_MULTI_DRIVER 0x00000002
+#define DISPLAY_DEVICE_PRIMARY_DEVICE 0x00000004
+#define DISPLAY_DEVICE_MIRRORING_DRIVER 0x00000008
+
+#endif
+#define DISPLAY_DEVICE_VGA 0x00000010
+
+#ifndef ENUM_CURRENT_SETTINGS
+#define ENUM_CURRENT_SETTINGS ( (DWORD)-1 )
+#define ENUM_REGISTRY_SETTINGS ( (DWORD)-2 )
+#endif
+
+#undef GetMonitorInfo
+#undef GetSystemMetrics
+#undef MonitorFromWindow
+#undef MonitorFromRect
+#undef MonitorFromPoint
+#undef EnumDisplayMonitors
+#undef EnumDisplayDevices
+
+//
+// define this to compile the stubs
+// otherwise you get the declarations
+//
+#ifdef COMPILE_MULTIMON_STUBS
+
+//---------------------------------------------------------------------------
+//
+// Implement the API stubs.
+//
+//---------------------------------------------------------------------------
+
+int ( WINAPI* g_pfnGetSystemMetrics )( int );
+HMONITOR ( WINAPI* g_pfnMonitorFromWindow )( HWND, BOOL );
+HMONITOR ( WINAPI* g_pfnMonitorFromRect )( LPCRECT, BOOL );
+HMONITOR ( WINAPI* g_pfnMonitorFromPoint )( POINT, BOOL );
+BOOL ( WINAPI* g_pfnGetMonitorInfo )( HMONITOR, LPMONITORINFO );
+BOOL ( WINAPI* g_pfnEnumDisplayMonitors )( HDC, LPCRECT, MONITORENUMPROC, LPARAM );
+BOOL ( WINAPI *g_pfnEnumDisplayDevices )( LPVOID, int, DISPLAY_DEVICE *, DWORD );
+
+BOOL InitMultipleMonitorStubs( void ){
+ HMODULE hUser32;
+ static BOOL fInitDone;
+
+ if ( fInitDone ) {
+ return g_pfnGetMonitorInfo != NULL;
+ }
+
+ if ( ( hUser32 = GetModuleHandle( TEXT( "USER32" ) ) ) &&
+ ( *(FARPROC*)&g_pfnGetSystemMetrics = GetProcAddress( hUser32,"GetSystemMetrics" ) ) &&
+ ( *(FARPROC*)&g_pfnMonitorFromWindow = GetProcAddress( hUser32,"MonitorFromWindow" ) ) &&
+ ( *(FARPROC*)&g_pfnMonitorFromRect = GetProcAddress( hUser32,"MonitorFromRect" ) ) &&
+ ( *(FARPROC*)&g_pfnMonitorFromPoint = GetProcAddress( hUser32,"MonitorFromPoint" ) ) &&
+ ( *(FARPROC*)&g_pfnEnumDisplayMonitors = GetProcAddress( hUser32,"EnumDisplayMonitors" ) ) &&
+ #ifdef UNICODE
+ ( *(FARPROC*)&g_pfnGetMonitorInfo = GetProcAddress( hUser32,"GetMonitorInfoW" ) ) &&
+ ( *(FARPROC*)&g_pfnEnumDisplayDevices = GetProcAddress( hUser32,"EnumDisplayDevicesW" ) ) &&
+ #else
+ ( *(FARPROC*)&g_pfnGetMonitorInfo = GetProcAddress( hUser32,"GetMonitorInfoA" ) ) &&
+ ( *(FARPROC*)&g_pfnEnumDisplayDevices = GetProcAddress( hUser32,"EnumDisplayDevicesA" ) ) &&
+ #endif
+ ( GetSystemMetrics( SM_CXVIRTUALSCREEN ) >= GetSystemMetrics( SM_CXSCREEN ) ) &&
+ ( GetSystemMetrics( SM_CYVIRTUALSCREEN ) >= GetSystemMetrics( SM_CYSCREEN ) ) ) {
+ fInitDone = TRUE;
+ return TRUE;
+ }
+ else
+ {
+ g_pfnGetSystemMetrics = NULL;
+ g_pfnMonitorFromWindow = NULL;
+ g_pfnMonitorFromRect = NULL;
+ g_pfnMonitorFromPoint = NULL;
+ g_pfnGetMonitorInfo = NULL;
+ g_pfnEnumDisplayMonitors = NULL;
+ g_pfnEnumDisplayDevices = NULL;
+
+ fInitDone = TRUE;
+ return FALSE;
+ }
+}
+
+//---------------------------------------------------------------------------
+//
+// "stubbed" implementations of Monitor APIs that work with the primary // display
+//
+//---------------------------------------------------------------------------
+
+int WINAPI
+xGetSystemMetrics( int nIndex ){
+ if ( InitMultipleMonitorStubs() ) {
+ return g_pfnGetSystemMetrics( nIndex );
+ }
+
+ switch ( nIndex )
+ {
+ case SM_CMONITORS:
+ case SM_SAMEDISPLAYFORMAT:
+ return 1;
+
+ case SM_XVIRTUALSCREEN:
+ case SM_YVIRTUALSCREEN:
+ return 0;
+
+ case SM_CXVIRTUALSCREEN:
+ nIndex = SM_CXSCREEN;
+ break;
+
+ case SM_CYVIRTUALSCREEN:
+ nIndex = SM_CYSCREEN;
+ break;
+ }
+
+ return GetSystemMetrics( nIndex );
+}
+
+ #define xPRIMARY_MONITOR ( (HMONITOR)0x42 )
+
+HMONITOR WINAPI
+xMonitorFromRect( LPCRECT lprcScreenCoords,
+ UINT uFlags ){
+ if ( InitMultipleMonitorStubs() ) {
+ return g_pfnMonitorFromRect( lprcScreenCoords, uFlags );
+ }
+
+ if ( ( uFlags & ( MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST ) ) ||
+ ( ( lprcScreenCoords->right > 0 ) &&
+ ( lprcScreenCoords->bottom > 0 ) &&
+ ( lprcScreenCoords->left < GetSystemMetrics( SM_CXSCREEN ) ) &&
+ ( lprcScreenCoords->top < GetSystemMetrics( SM_CYSCREEN ) ) ) ) {
+ return xPRIMARY_MONITOR;
+ }
+
+ return NULL;
+}
+
+HMONITOR WINAPI
+xMonitorFromWindow( HWND hWnd,
+ UINT uFlags ){
+ RECT rc;
+
+ if ( InitMultipleMonitorStubs() ) {
+ return g_pfnMonitorFromWindow( hWnd, uFlags );
+ }
+
+ if ( uFlags & ( MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST ) ) {
+ return xPRIMARY_MONITOR;
+ }
+
+ if ( GetWindowRect( hWnd, &rc ) ) {
+ return xMonitorFromRect( &rc, uFlags );
+ }
+
+ return NULL;
+}
+
+HMONITOR WINAPI
+xMonitorFromPoint( POINT ptScreenCoords,
+ UINT uFlags ){
+ if ( InitMultipleMonitorStubs() ) {
+ return g_pfnMonitorFromPoint( ptScreenCoords, uFlags );
+ }
+
+ if ( ( uFlags & ( MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST ) ) ||
+ ( ( ptScreenCoords.x >= 0 ) &&
+ ( ptScreenCoords.x < GetSystemMetrics( SM_CXSCREEN ) ) &&
+ ( ptScreenCoords.y >= 0 ) &&
+ ( ptScreenCoords.y < GetSystemMetrics( SM_CYSCREEN ) ) ) ) {
+ return xPRIMARY_MONITOR;
+ }
+
+ return NULL;
+}
+
+BOOL WINAPI
+xGetMonitorInfo( HMONITOR hMonitor,
+ LPMONITORINFO lpMonitorInfo ){
+ RECT rcWork;
+
+ if ( InitMultipleMonitorStubs() ) {
+ return g_pfnGetMonitorInfo( hMonitor, lpMonitorInfo );
+ }
+
+ if ( ( hMonitor == xPRIMARY_MONITOR ) && lpMonitorInfo &&
+ ( lpMonitorInfo->cbSize >= sizeof( MONITORINFO ) ) &&
+ SystemParametersInfo( SPI_GETWORKAREA, 0, &rcWork, 0 ) ) {
+ lpMonitorInfo->rcMonitor.left = 0;
+ lpMonitorInfo->rcMonitor.top = 0;
+ lpMonitorInfo->rcMonitor.right = GetSystemMetrics( SM_CXSCREEN );
+ lpMonitorInfo->rcMonitor.bottom = GetSystemMetrics( SM_CYSCREEN );
+ lpMonitorInfo->rcWork = rcWork;
+ lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
+
+ if ( lpMonitorInfo->cbSize >= sizeof( MONITORINFOEX ) ) {
+ lstrcpy( ( (MONITORINFOEX*)lpMonitorInfo )->szDevice,
+ TEXT( "DISPLAY" ) );
+ }
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+BOOL WINAPI
+xEnumDisplayMonitors( HDC hdc,
+ LPCRECT lprcIntersect,
+ MONITORENUMPROC lpfnEnumProc,
+ LPARAM lData ){
+ RECT rcCallback, rcLimit;
+
+ if ( InitMultipleMonitorStubs() ) {
+ return g_pfnEnumDisplayMonitors( hdc, lprcIntersect, lpfnEnumProc, lData );
+ }
+
+ if ( !lpfnEnumProc ) {
+ return FALSE;
+ }
+
+ rcLimit.left = 0;
+ rcLimit.top = 0;
+ rcLimit.right = GetSystemMetrics( SM_CXSCREEN );
+ rcLimit.bottom = GetSystemMetrics( SM_CYSCREEN );
+
+ if ( hdc ) {
+ RECT rcClip;
+ HWND hWnd;
+
+ if ( ( hWnd = WindowFromDC( hdc ) ) == NULL ) {
+ return FALSE;
+ }
+
+ switch ( GetClipBox( hdc, &rcClip ) )
+ {
+ default:
+ MapWindowPoints( NULL, hWnd, (LPPOINT)&rcLimit, 2 );
+ if ( IntersectRect( &rcCallback, &rcClip, &rcLimit ) ) {
+ break;
+ }
+ //fall thru
+ case NULLREGION:
+ return TRUE;
+ case ERROR:
+ return FALSE;
+ }
+
+ rcLimit = rcCallback;
+ }
+
+ if ( !lprcIntersect || IntersectRect( &rcCallback, lprcIntersect, &rcLimit ) ) {
+ lpfnEnumProc( xPRIMARY_MONITOR, hdc, &rcCallback, lData );
+ }
+
+ return TRUE;
+}
+
+BOOL WINAPI
+xEnumDisplayDevices( LPVOID lpReserved,
+ int iDeviceNum,
+ DISPLAY_DEVICE * pDisplayDevice,
+ DWORD dwFlags ){
+ if ( InitMultipleMonitorStubs() ) {
+ return g_pfnEnumDisplayDevices( lpReserved, iDeviceNum, pDisplayDevice, dwFlags );
+ }
+
+ return FALSE;
+}
+
+ #undef xPRIMARY_MONITOR
+ #undef COMPILE_MULTIMON_STUBS
+
+#else // COMPILE_MULTIMON_STUBS
+
+extern int WINAPI xGetSystemMetrics( int );
+extern HMONITOR WINAPI xMonitorFromWindow( HWND, UINT );
+extern HMONITOR WINAPI xMonitorFromRect( LPCRECT, UINT );
+extern HMONITOR WINAPI xMonitorFromPoint( POINT, UINT );
+extern BOOL WINAPI xGetMonitorInfo( HMONITOR, LPMONITORINFO );
+extern BOOL WINAPI xEnumDisplayMonitors( HDC, LPCRECT, MONITORENUMPROC, LPARAM );
+extern BOOL WINAPI xEnumDisplayDevices( LPVOID, int, DISPLAY_DEVICE *, DWORD );
+
+#endif // COMPILE_MULTIMON_STUBS
+
+//
+// build defines that replace the regular APIs with our versions
+//
+#define GetSystemMetrics xGetSystemMetrics
+#define MonitorFromWindow xMonitorFromWindow
+#define MonitorFromRect xMonitorFromRect
+#define MonitorFromPoint xMonitorFromPoint
+#define GetMonitorInfo xGetMonitorInfo
+#define EnumDisplayMonitors xEnumDisplayMonitors
+#define EnumDisplayDevices xEnumDisplayDevices
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+
+#endif // WIN32
+
+#endif // __MULTIMON_H