From f936a54000ad1285f4eae44d82475edbeb2f495c Mon Sep 17 00:00:00 2001 From: Tobias Taschner Date: Wed, 16 Sep 2015 00:19:41 +0200 Subject: [PATCH] Remove dynamic loading of Display APIs. ChangeDisplaySettingsEx, EnumDisplayMonitors, MonitorFromPoint, MonitorFromWindow and GetMonitorInfo are available since Win2k. --- src/msw/display.cpp | 83 +++------------------------------------------ 1 file changed, 5 insertions(+), 78 deletions(-) diff --git a/src/msw/display.cpp b/src/msw/display.cpp index 67d6969897..4f5f6970de 100644 --- a/src/msw/display.cpp +++ b/src/msw/display.cpp @@ -70,32 +70,6 @@ static const wxChar displayDllName[] = wxT("user32.dll"); -// ---------------------------------------------------------------------------- -// typedefs for dynamically loaded Windows functions -// ---------------------------------------------------------------------------- - -typedef LONG (WINAPI *ChangeDisplaySettingsEx_t)(LPCTSTR lpszDeviceName, - LPDEVMODE lpDevMode, - HWND hwnd, - DWORD dwFlags, - LPVOID lParam); - -typedef BOOL (WINAPI *EnumDisplayMonitors_t)(HDC,LPCRECT,MONITORENUMPROC,LPARAM); -typedef HMONITOR (WINAPI *MonitorFromPoint_t)(POINT,DWORD); -typedef HMONITOR (WINAPI *MonitorFromWindow_t)(HWND,DWORD); -typedef BOOL (WINAPI *GetMonitorInfo_t)(HMONITOR,LPMONITORINFO); - -// emulation of ChangeDisplaySettingsEx() for Win95 -LONG WINAPI ChangeDisplaySettingsExForWin95(LPCTSTR WXUNUSED(lpszDeviceName), - LPDEVMODE lpDevMode, - HWND WXUNUSED(hwnd), - DWORD dwFlags, - LPVOID WXUNUSED(lParam)) -{ - return ::ChangeDisplaySettings(lpDevMode, dwFlags); -} - - // ---------------------------------------------------------------------------- // wxDisplayMSW declaration // ---------------------------------------------------------------------------- @@ -148,12 +122,6 @@ private: WX_DEFINE_ARRAY(HMONITOR, wxMonitorHandleArray); -// functions dynamically bound by wxDisplayFactoryMSW ctor. -static MonitorFromPoint_t gs_MonitorFromPoint = NULL; -static MonitorFromWindow_t gs_MonitorFromWindow = NULL; -static GetMonitorInfo_t gs_GetMonitorInfo = NULL; -static EnumDisplayMonitors_t gs_EnumDisplayMonitors = NULL; - class wxDisplayFactoryMSW : public wxDisplayFactory { public: @@ -236,7 +204,7 @@ wxDisplayFactoryMSW* wxDisplayFactoryMSW::ms_factory = NULL; bool wxDisplayMSW::GetMonInfo(MONITORINFOEX& monInfo) const { - if ( !gs_GetMonitorInfo(m_hmon, &monInfo) ) + if ( !::GetMonitorInfo(m_hmon, &monInfo) ) { wxLogLastError(wxT("GetMonitorInfo")); return false; @@ -390,30 +358,8 @@ bool wxDisplayMSW::ChangeMode(const wxVideoMode& mode) } - // get pointer to the function dynamically - // - // we're only called from the main thread, so it's ok to use static - // variable - static ChangeDisplaySettingsEx_t pfnChangeDisplaySettingsEx = NULL; - if ( !pfnChangeDisplaySettingsEx ) - { - wxDynamicLibrary dllDisplay(displayDllName, wxDL_VERBATIM | wxDL_QUIET); - if ( dllDisplay.IsLoaded() ) - { - wxDL_INIT_FUNC_AW(pfn, ChangeDisplaySettingsEx, dllDisplay); - } - //else: huh, no this DLL must always be present, what's going on?? - - if ( !pfnChangeDisplaySettingsEx ) - { - // we must be under Win95 and so there is no multiple monitors - // support anyhow - pfnChangeDisplaySettingsEx = ChangeDisplaySettingsExForWin95; - } - } - // do change the mode - switch ( pfnChangeDisplaySettingsEx + switch ( ::ChangeDisplaySettingsEx ( GetName().t_str(), // display name pDevMode, // dev mode or NULL to reset @@ -478,25 +424,6 @@ wxDisplayFactoryMSW::wxDisplayFactoryMSW() 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 @@ -535,7 +462,7 @@ void wxDisplayFactoryMSW::DoRefreshMonitors() { m_displays.Clear(); - if ( !gs_EnumDisplayMonitors(NULL, NULL, MultimonEnumProc, (LPARAM)this) ) + if ( !::EnumDisplayMonitors(NULL, NULL, MultimonEnumProc, (LPARAM)this) ) { wxLogLastError(wxT("EnumDisplayMonitors")); } @@ -586,14 +513,14 @@ int wxDisplayFactoryMSW::GetFromPoint(const wxPoint& pt) pt2.x = pt.x; pt2.y = pt.y; - return FindDisplayFromHMONITOR(gs_MonitorFromPoint(pt2, + return FindDisplayFromHMONITOR(::MonitorFromPoint(pt2, MONITOR_DEFAULTTONULL)); } int wxDisplayFactoryMSW::GetFromWindow(const wxWindow *window) { #ifdef __WXMSW__ - return FindDisplayFromHMONITOR(gs_MonitorFromWindow(GetHwndOf(window), + return FindDisplayFromHMONITOR(::MonitorFromWindow(GetHwndOf(window), MONITOR_DEFAULTTONULL)); #else const wxSize halfsize = window->GetSize() / 2;