I'm hooking a Direct3D9 device by searching for the VTable and appending my own method to the start of selected referenced functions with a detour.
D3DEndScene = (lpfnD3DEndScene)((LPVOID)dwVTable[VD3D_ENDSCENE]); // 35 dx8
D3DResetDevice = (lpfnD3DResetDevice)((LPVOID)dwVTable[VD3D_RESET]); // 14 dx8
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)D3DEndScene, D3DEndScene_Hook);
DetourAttach(&(PVOID&)D3DResetDevice, D3DResetDevice_Hook);
DetourTransactionCommit();
That's working fine.
As a result I have access to the Direct3D9 device I've called "pDevice".
HRESULT WINAPI D3DEndScene_Hook (LPDIRECT3DDEVICE9 pDevice)
I would like to extract the window handle that pDevice is using so that I can hook the WndProc attribute and filter out keyboard/mouse events (and handle them myself). I know I can use SetWindowLong to find the existing WndProc, but I've no idea how to actually get any form of window handle out of the device.
What I do know is that in the method IDirect3D9::CreateDevice there is the argument hFocusWindow which seems like what I'm looking for; but I've no idea how to access it after creation.
Hooking CreateDevice isn't a very good option for me because I won't be hooking until far after the device is created and hence I won't catch the function in time.
How can I get the window handle of a D3D9 device?
This is what you are looking for D3D9:
IDirect3DDevice9::GetCreationParameters
You can use that to get the creation paramaters used to create the device including hFocusWindow.
Hope that helps.