MultiMonitor.cpp
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25  */
26 
32 #ifdef XP_WIN
33 
34 #include <windows.h>
35 #include <memory.h>
36 
37 #include <shlobj.h>
38 #include <multimon.h>
39 #if !defined(HMONITOR_DECLARED) && (WINVER < 0x500)
40 DECLARE_HANDLE(HMONITOR);
41 #define HMONITOR_DECLARED
42 #endif
43 
44 #endif
45 
46 #include "MultiMonitor.h"
47 
48 // CLASSES ====================================================================
49 
50 //=============================================================================
51 // CMultipleMonitor Class
52 //=============================================================================
53 
54 //-----------------------------------------------------------------------------
55 /* Implementation file */
56 
58 #ifdef XP_WIN
59  if (window != NULL)
60  {
61  // Load dll dynamically so as to be compatible with older versions of Win32
62  HINSTANCE user32 = LoadLibrary(L"USER32.DLL");
63  if (user32 != NULL)
64  {
65  HMONITOR (WINAPI *_MonitorFromWindow)(HWND wnd, DWORD dwFlags)=(HMONITOR (WINAPI *)(HWND, DWORD)) GetProcAddress(user32, "MonitorFromWindow");
66  BOOL (WINAPI *_GetMonitorInfoW)(HMONITOR mon, LPMONITORINFO lpmi) = (BOOL (WINAPI *)(HMONITOR, LPMONITORINFO)) GetProcAddress(user32, "GetMonitorInfoW");
67 
68  if (_MonitorFromWindow && _GetMonitorInfoW)
69  {
70  HMONITOR hmon;
71  hmon = _MonitorFromWindow(window, MONITOR_DEFAULTTONULL);
72  if (hmon != NULL)
73  {
74  MONITORINFOEX mie;
75  memset(&mie, sizeof(mie), 0);
76  mie.cbSize = sizeof(mie);
77  if (_GetMonitorInfoW(hmon, &mie))
78  {
79  if (excludeTaskbar)
80  *r = mie.rcWork;
81  else
82  *r = mie.rcMonitor;
83  FreeLibrary(user32);
84  return;
85  }
86  }
87  }
88  FreeLibrary(user32);
89  }
90  }
91  SystemParametersInfo(SPI_GETWORKAREA, 0, r, 0);
92 #endif
93 }
94 
95 
96 void CMultiMonitor::GetMonitorFromPoint(RECT *r, POINT *pt, bool excludeTaskbar) {
97 #ifdef XP_WIN
98  if (pt != NULL)
99  {
100  // Load dll dynamically so as to be compatible with older versions of Win32
101  HINSTANCE user32 = LoadLibrary(L"USER32.DLL");
102  if (user32 != NULL)
103  {
104  HMONITOR (WINAPI *_MonitorFromPoint)(POINT pt, DWORD dwFlags) = (HMONITOR (WINAPI *)(POINT, DWORD)) GetProcAddress(user32, "MonitorFromPoint");
105  BOOL (WINAPI *_GetMonitorInfoW)(HMONITOR mon, LPMONITORINFO lpmi) = (BOOL (WINAPI *)(HMONITOR, LPMONITORINFO)) GetProcAddress(user32, "GetMonitorInfoW");
106  if (_MonitorFromPoint && _GetMonitorInfoW)
107  {
108  HMONITOR hmon;
109  hmon = _MonitorFromPoint(*pt, MONITOR_DEFAULTTONULL);
110  if (hmon != NULL)
111  {
112  MONITORINFOEX mie;
113  memset(&mie, sizeof(mie), 0);
114  mie.cbSize = sizeof(mie);
115  if (_GetMonitorInfoW(hmon, &mie))
116  {
117  if (excludeTaskbar)
118  *r = mie.rcWork;
119  else
120  *r = mie.rcMonitor;
121  FreeLibrary(user32);
122  return;
123  }
124  }
125  }
126  FreeLibrary(user32);
127  }
128  }
129  SystemParametersInfo(SPI_GETWORKAREA, 0, r, 0);
130 #endif
131 } // GetMonitorFromPoint
static nsresult LoadLibrary(nsCOMPtr< nsIFile > aLibDir, nsString aLibPath)
Songbird Multiple Monitor Support - Definition.
let window
static void GetMonitorFromPoint(RECT *r, POINT *pt, bool excludeTaskbar)
#define NATIVEWINDOW
static void GetMonitorFromWindow(RECT *r, void *wnd, bool excludeTaskbar)
struct tagPOINT POINT