commit 759201bbcd1eb9f44bb9cb2a691dadeef008d1b1
parent 29992f4df28f0d6c5b52027dd173c5446ce9d054
Author: cfillion <cfillion@users.noreply.github.com>
Date: Sun, 23 Feb 2020 20:58:21 -0800
about: preserve formatting when DPI changes in Per-Monitor v2 mode
Diffstat:
2 files changed, 65 insertions(+), 0 deletions(-)
diff --git a/src/dllimport.hpp b/src/dllimport.hpp
@@ -0,0 +1,54 @@
+/* ReaPack: Package manager for REAPER
+ * Copyright (C) 2015-2020 Christian Fillion
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef REAPACK_DLLIMPORT_HPP
+#define REAPACK_DLLIMPORT_HPP
+
+#ifndef _WIN32
+# error This file should not be included on non-Windows systems.
+#endif
+
+#include <windows.h>
+
+template<typename Proc, typename = std::enable_if_t<std::is_function_v<Proc>>>
+class DllImport {
+public:
+ DllImport(const wchar_t *dll, const char *func)
+ {
+ if (m_lib = LoadLibrary(dll))
+ m_proc = reinterpret_cast<Proc *>(GetProcAddress(m_lib, func));
+ else
+ m_proc = nullptr;
+ }
+
+ ~DllImport()
+ {
+ if (m_lib)
+ FreeLibrary(m_lib);
+ }
+
+ operator bool() const { return m_proc != nullptr; }
+
+ template<typename... Args>
+ auto operator()(Args&&... args) const { return m_proc(std::forward<Args>(args)...); }
+
+private:
+ HINSTANCE m_lib;
+ Proc *m_proc;
+};
+
+#endif
diff --git a/src/richedit-win32.cpp b/src/richedit-win32.cpp
@@ -20,6 +20,7 @@
// This is the Win32 implementation of RichEdit
// The macOS implementation is in richedit.mm, Linux is in richedit-generic.cpp
+#include "dllimport.hpp"
#include "win32.hpp"
#include <memory>
@@ -51,6 +52,16 @@ RichEdit::RichEdit(HWND handle)
SendMessage(handle, EM_SETEVENTMASK, 0, ENM_LINK);
SendMessage(handle, EM_SETEDITSTYLE,
SES_HYPERLINKTOOLTIPS, SES_HYPERLINKTOOLTIPS);
+
+ // available since Windows 10 version 1703
+ static DllImport<decltype(SetDialogControlDpiChangeBehavior)>
+ _SetDialogControlDpiChangeBehavior
+ {L"user32.dll", "SetDialogControlDpiChangeBehavior"};
+
+ if(_SetDialogControlDpiChangeBehavior) {
+ _SetDialogControlDpiChangeBehavior(handle,
+ DCDC_DISABLE_FONT_UPDATE, DCDC_DISABLE_FONT_UPDATE);
+ }
}
RichEdit::~RichEdit() = default;