SineStriker
2023-12-01 0640f7a902a3489332627ce93aa61c0dc25087b1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "win32windowcontext_p.h"
 
#include <windows.h>
 
namespace QWK {
 
    static LRESULT CALLBACK QWK_WindowsWndProc(const HWND hWnd, const UINT uMsg,
                                               const WPARAM wParam, const LPARAM lParam) {
        // Implement
        return 0;
    }
 
    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 window hook
    }
 
    Win32WindowContext::~Win32WindowContext() {
    }
 
}