From 600cb73d1bcb7d5b6a27b11a0f6d3e01015027b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <1173718158@qq.com> Date: Fri, 15 Nov 2024 07:46:53 +0800 Subject: [PATCH] clip --- cpp/winsharedutils/clipboard.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/cpp/winsharedutils/clipboard.cpp b/cpp/winsharedutils/clipboard.cpp index dfa7db2a..3d75afc2 100644 --- a/cpp/winsharedutils/clipboard.cpp +++ b/cpp/winsharedutils/clipboard.cpp @@ -88,8 +88,7 @@ static void clipboard_callback_1(void (*callback)(const wchar_t *, bool), HANDLE WNDCLASS wc = {}; wc.lpfnWndProc = [](HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { -#ifndef WINXP - if (WM_CLIPBOARDUPDATE == message) + static auto callbackx = [](HWND hWnd) { auto data = clipboard_get_internal(); auto callback_ = reinterpret_cast(GetWindowLongPtrW(hWnd, GWLP_USERDATA)); @@ -100,6 +99,11 @@ static void clipboard_callback_1(void (*callback)(const wchar_t *, bool), HANDLE GetWindowThreadProcessId(ohwnd, &pid); callback_(data.value().c_str(), pid == GetCurrentProcessId()); } + }; +#ifndef WINXP + if (WM_CLIPBOARDUPDATE == message) + { + callbackx(hWnd); } #else static HWND nextviewer; @@ -125,15 +129,7 @@ static void clipboard_callback_1(void (*callback)(const wchar_t *, bool), HANDLE break; case WM_DRAWCLIPBOARD: { - auto data = clipboard_get_internal(); - auto callback_ = reinterpret_cast(GetWindowLongPtrW(hWnd, GWLP_USERDATA)); - if (data && callback_) - { - auto ohwnd = GetClipboardOwner(); - DWORD pid; - GetWindowThreadProcessId(ohwnd, &pid); - callback_(data.value().c_str(), pid == GetCurrentProcessId()); - } + callbackx(hWnd); if (nextviewer) SendMessage(nextviewer, message, wParam, lParam); }