From aa7b258a8a037c8bc1cb6587f3252cda909780ec Mon Sep 17 00:00:00 2001 From: fanlumaster <1730976608@qq.com> Date: Sat, 22 Mar 2025 11:55:44 +0800 Subject: [PATCH] do not repeat WM_COPYDATA if not necessary --- src/Global/Globals.h | 1 + src/Window/CandidateWindow.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/Global/Globals.h b/src/Global/Globals.h index 06550dcd..e8afd56f 100644 --- a/src/Global/Globals.h +++ b/src/Global/Globals.h @@ -175,4 +175,5 @@ inline std::vector WStringCandidateList; inline std::wstring FindKeyCode; inline POINT PointDTO = {0, 0}; +inline std::wstring CandidateWString = L""; } // namespace Global diff --git a/src/Window/CandidateWindow.cpp b/src/Window/CandidateWindow.cpp index a5f26261..19506af1 100644 --- a/src/Window/CandidateWindow.cpp +++ b/src/Window/CandidateWindow.cpp @@ -2,7 +2,9 @@ #include "Globals.h" #include "BaseWindow.h" #include "Globals.h" +#include #include +#include #include #include #include "CandidateWindow.h" @@ -545,6 +547,8 @@ void CCandidateWindow::_DrawListWithWebview2(_In_ UINT iIndex) std::wstring preeditString(preeditStringRange.Get(), preeditStringRange.GetLength()); + std::wstring candWString = preeditString; + // // Draw candidate list // @@ -553,6 +557,30 @@ void CCandidateWindow::_DrawListWithWebview2(_In_ UINT iIndex) std::wstring pageCountString = std::to_wstring(*_pIndexRange->GetAt(pageCount)); CCandidateListItem *pItemList = _candidateList.GetAt(iIndex); std::wstring itemString(pItemList->_ItemString.Get(), pItemList->_ItemString.GetLength()); + candWString = candWString + L"," + pageCountString + L". " + itemString; + } + + if (Global::CandidateWString != candWString) + { + Global::CandidateWString = candWString; + + HWND UIHwnd = FindWindow(L"global_candidate_window", NULL); + if (UIHwnd == NULL) + { + DWORD error = GetLastError(); + std::wstring errorString = L"FindWindow failed with error: " + std::to_wstring(error); + Global::LogMessageW(errorString.c_str()); + } + COPYDATASTRUCT cds; + cds.dwData = 1; + cds.cbData = (candWString.size() + 1) * sizeof(WCHAR); + cds.lpData = (PVOID)candWString.c_str(); + if (!SendMessage(UIHwnd, WM_COPYDATA, (WPARAM)UIHwnd, (LPARAM)&cds)) + { + DWORD error = GetLastError(); + std::wstring errorString = L"PostMessage failed with error: " + std::to_wstring(error); + Global::LogMessageW(errorString.c_str()); + } } }