From 0d31eda795a5bbfd62f070b54f2409761a0eb87f Mon Sep 17 00:00:00 2001 From: SineStriker <trueful@163.com> Date: 周五, 01 12月 2023 18:22:00 +0800 Subject: [PATCH] Add small implementations --- src/core/handler/win32windowcontext.cpp | 39 ++++++++++++++++++++++++++++++++++----- 1 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/core/handler/win32windowcontext.cpp b/src/core/handler/win32windowcontext.cpp index 1208b04..0311532 100644 --- a/src/core/handler/win32windowcontext.cpp +++ b/src/core/handler/win32windowcontext.cpp @@ -4,16 +4,45 @@ namespace QWK { - static LRESULT CALLBACK QWKWindowsWndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam, - const LPARAM lParam) { + static LRESULT CALLBACK QWK_WindowsWndProc(const HWND hWnd, const UINT uMsg, + const WPARAM wParam, const LPARAM lParam) { // Implement return 0; } - Win32WindowContext::Win32WindowContext(QWindow *window, - WindowItemDelegate *delegate) + static bool hookWindowProc(QObject *window, WId windowId) { + Q_ASSERT(windowId); + if (!windowId) { + return false; + } + + const auto hwnd = reinterpret_cast<HWND>(windowId); + if (!extraData->qtWindowProc) { + ::SetLastError(ERROR_SUCCESS); + const auto qtWindowProc = + reinterpret_cast<WNDPROC>(::GetWindowLongPtrW(hwnd, GWLP_WNDPROC)); + Q_ASSERT(qtWindowProc); + if (!qtWindowProc) { + WARNING << getSystemErrorMessage(kGetWindowLongPtrW); + return false; + } + extraData->qtWindowProc = qtWindowProc; + } + if (!extraData->windowProcHooked) { + ::SetLastError(ERROR_SUCCESS); + if (::SetWindowLongPtrW(hwnd, GWLP_WNDPROC, + reinterpret_cast<LONG_PTR>(QWK_WindowsWndProc)) == 0) { + WARNING << getSystemErrorMessage(kSetWindowLongPtrW); + return false; + } + extraData->windowProcHooked = true; + } + return true; + } + + Win32WindowContext::Win32WindowContext(QWindow *window, WindowItemDelegate *delegate) : AbstractWindowContext(window, delegate) { - // Install windows hook + // Install windows window hook } Win32WindowContext::~Win32WindowContext() { -- Gitblit v1.9.1