// Hook window void WindowMgr::HookWindow(CWindow Window) { // Get window procedure // Note: Can't use CWindow::GetWindowLongPtr because we need to // explicitly call both the ANSI and Unicode version of the function. WNDPROC WndProcA = reinterpret_cast(GetWindowLongPtrA(Window, GWLP_WNDPROC)); WNDPROC WndProcW = reinterpret_cast(GetWindowLongPtrW(Window, GWLP_WNDPROC)); // Debug output std::wcout << boost::wformat(L"WindowMgr::HookWindow: WndProcA = %p, " L"WndProcW = %p.") %WndProcA %WndProcW << std::endl; // Real window procedure WNDPROC WndProc = nullptr; // Check if WndProc pointer is a valid pointer or a special handle if (WndProcW && HIWORD(WndProcW) != 0xFFFF) { WndProc = WndProcW; } else if (WndProcA && HIWORD(WndProcA) != 0xFFFF) { WndProc = WndProcA; } else { // Debug output std::wcout << "WindowMgr::HookWindow: No valid window procedure found." << std::endl; // No valid window procedure found, nothing left to do return; } // Hook window procedure PBYTE Target = reinterpret_cast(WndProc); PBYTE Detour = reinterpret_cast(WndProc_Hook); m_pWndProcHk.reset(new Cypher::PatchInline(Target, Detour)); m_pWndProcHk->Enable(); }