+// ----------------------------------------------------------------------------
+// wxDisplayFactoryMSW implementation
+// ----------------------------------------------------------------------------
+
+wxDisplayFactoryMSW::wxDisplayFactoryMSW()
+{
+ if ( gs_MonitorFromPoint==NULL || gs_MonitorFromWindow==NULL
+ || gs_GetMonitorInfo==NULL || gs_EnumDisplayMonitors==NULL )
+ {
+ // First initialization, or last initialization failed.
+ wxDynamicLibrary dllDisplay(displayDllName, wxDL_VERBATIM | wxDL_QUIET);
+
+ wxDL_INIT_FUNC(gs_, MonitorFromPoint, dllDisplay);
+ wxDL_INIT_FUNC(gs_, MonitorFromWindow, dllDisplay);
+ wxDL_INIT_FUNC_AW(gs_, GetMonitorInfo, dllDisplay);
+ wxDL_INIT_FUNC(gs_, EnumDisplayMonitors, dllDisplay);
+
+ // we can safely let dllDisplay go out of scope, the DLL itself will
+ // still remain loaded as all programs link to it statically anyhow
+ }
+
+ if ( gs_MonitorFromPoint==NULL || gs_MonitorFromWindow==NULL
+ || gs_GetMonitorInfo==NULL || gs_EnumDisplayMonitors==NULL )
+ return;
+
+ // enumerate all displays
+ if ( !gs_EnumDisplayMonitors(NULL, NULL, MultimonEnumProc, (LPARAM)this) )
+ {
+ wxLogLastError(wxT("EnumDisplayMonitors"));
+ }
+}
+
+/* static */
+BOOL CALLBACK
+wxDisplayFactoryMSW::MultimonEnumProc(
+ HMONITOR hMonitor, // handle to display monitor
+ HDC WXUNUSED(hdcMonitor), // handle to monitor-appropriate device context
+ LPRECT WXUNUSED(lprcMonitor), // pointer to monitor intersection rectangle
+ LPARAM dwData) // data passed from EnumDisplayMonitors (this)
+{
+ wxDisplayFactoryMSW *const self = (wxDisplayFactoryMSW *)dwData;
+
+ self->m_displays.Add(hMonitor);
+
+ // continue the enumeration
+ return TRUE;
+}
+
+wxDisplayImpl *wxDisplayFactoryMSW::CreateDisplay(unsigned n)
+{
+ wxCHECK_MSG( n < m_displays.size(), NULL, wxT("An invalid index was passed to wxDisplay") );
+
+ return new wxDisplayMSW(n, m_displays[n]);
+}
+
+// helper for GetFromPoint() and GetFromWindow()
+int wxDisplayFactoryMSW::FindDisplayFromHMONITOR(HMONITOR hmon) const
+{
+ if ( hmon )
+ {
+ const size_t count = m_displays.size();
+ for ( size_t n = 0; n < count; n++ )
+ {
+ if ( hmon == m_displays[n] )
+ return n;
+ }
+ }
+
+ return wxNOT_FOUND;
+}
+
+int wxDisplayFactoryMSW::GetFromPoint(const wxPoint& pt)
+{
+ POINT pt2;
+ pt2.x = pt.x;
+ pt2.y = pt.y;
+
+ return FindDisplayFromHMONITOR(gs_MonitorFromPoint(pt2,
+ MONITOR_DEFAULTTONULL));
+}
+
+int wxDisplayFactoryMSW::GetFromWindow(const wxWindow *window)
+{
+ return FindDisplayFromHMONITOR(gs_MonitorFromWindow(GetHwndOf(window),
+ MONITOR_DEFAULTTONULL));
+}
+
+#endif // wxUSE_DISPLAY