From 770e36c10cd17cdd8619ae5cb39196624204a064 Mon Sep 17 00:00:00 2001 From: Marco Schmid Date: Tue, 9 Oct 2018 18:37:51 +0200 Subject: [PATCH] added winapi-call to flush clipboard (#778) --- src/RunGui.cpp | 9 +++++++++ src/util/WindowsHelper.cpp | 12 ++++++++++++ src/util/WindowsHelper.hpp | 2 ++ 3 files changed, 23 insertions(+) diff --git a/src/RunGui.cpp b/src/RunGui.cpp index e342ca7c1..04cb7985a 100644 --- a/src/RunGui.cpp +++ b/src/RunGui.cpp @@ -11,6 +11,10 @@ #include "singletons/Updates.hpp" #include "widgets/dialogs/LastRunCrashDialog.hpp" +#ifdef USEWINSDK +# include "util/WindowsHelper.hpp" +#endif + #ifdef C_USE_BREAKPAD # include #endif @@ -133,6 +137,11 @@ void runGui(QApplication &a, Paths &paths, Settings &settings) chatterino::NetworkManager::deinit(); +#ifdef USEWINSDK + // flushing windows clipboard to keep copied messages + flushClipboard(); +#endif + _exit(0); } } // namespace chatterino diff --git a/src/util/WindowsHelper.cpp b/src/util/WindowsHelper.cpp index 38ca74698..c87d31561 100644 --- a/src/util/WindowsHelper.cpp +++ b/src/util/WindowsHelper.cpp @@ -34,6 +34,18 @@ boost::optional getWindowDpi(HWND hwnd) return boost::none; } +typedef HRESULT(CALLBACK *OleFlushClipboard_)(); + +void flushClipboard() +{ + static HINSTANCE ole32 = LoadLibrary(L"Ole32.dll"); + if (ole32 != nullptr) { + if (auto oleFlushClipboard = OleFlushClipboard_(GetProcAddress(ole32, "OleFlushClipboard"))) { + oleFlushClipboard(); + } + } +} + } // namespace chatterino #endif diff --git a/src/util/WindowsHelper.hpp b/src/util/WindowsHelper.hpp index f02bb1362..6e20b1e73 100644 --- a/src/util/WindowsHelper.hpp +++ b/src/util/WindowsHelper.hpp @@ -8,6 +8,8 @@ namespace chatterino { boost::optional getWindowDpi(HWND hwnd); +void flushClipboard(); + } // namespace chatterino