+wxDisplayFactoryMSW::wxDisplayFactoryMSW()
+{
+ // This is not supposed to happen with the current code, the factory is
+ // implicitly a singleton.
+ wxASSERT_MSG( !ms_factory, wxS("Using more than one factory?") );
+
+ ms_factory = this;
+
+ m_hiddenHwnd = NULL;
+ m_hiddenClass = NULL;
+
+ 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;
+
+ DoRefreshMonitors();
+
+ // Also create a hidden window to listen for WM_SETTINGCHANGE that we
+ // receive when a monitor is added to or removed from the system as we must
+ // refresh our monitor handles information then.
+ m_hiddenHwnd = wxCreateHiddenWindow
+ (
+ &m_hiddenClass,
+ wxT("wxDisplayHiddenWindow"),
+ wxDisplayWndProc
+ );
+}
+
+wxDisplayFactoryMSW::~wxDisplayFactoryMSW()
+{
+ if ( m_hiddenHwnd )
+ {
+ if ( !::DestroyWindow(m_hiddenHwnd) )
+ {
+ wxLogLastError(wxT("DestroyWindow(wxDisplayHiddenWindow)"));
+ }
+
+ if ( m_hiddenClass )
+ {
+ if ( !::UnregisterClass(m_hiddenClass, wxGetInstance()) )
+ {
+ wxLogLastError(wxT("UnregisterClass(wxDisplayHiddenWindow)"));
+ }
+ }
+ }
+
+ ms_factory = NULL;
+}
+
+void wxDisplayFactoryMSW::DoRefreshMonitors()
+{
+ m_displays.Clear();