From b270eaf1c6f4a71b029c8ea95d8421aa938b802f Mon Sep 17 00:00:00 2001 From: Tau Date: Sat, 19 Oct 2019 17:05:09 -0400 Subject: [PATCH] hooklib/gfx.c: Add option to frame the d3d window --- hooklib/gfx.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/hooklib/gfx.c b/hooklib/gfx.c index c89ee54..5dfdf1a 100644 --- a/hooklib/gfx.c +++ b/hooklib/gfx.c @@ -23,6 +23,7 @@ static HRESULT STDMETHODCALLTYPE my_CreateDevice( IDirect3DDevice9 **pdev); static IDirect3D9 * WINAPI my_Direct3DCreate9(UINT sdk_ver); static IDirect3D9 * (WINAPI *next_Direct3DCreate9)(UINT sdk_ver); +static HRESULT gfx_frame_window(HWND hwnd); static struct gfx_config gfx_config; @@ -106,5 +107,72 @@ static HRESULT STDMETHODCALLTYPE my_CreateDevice( pp->FullScreen_RefreshRateInHz = 0; } + if (gfx_config.framed) { + gfx_frame_window(hwnd); + } + return IDirect3D9_CreateDevice(real, adapter, type, hwnd, flags, pp, pdev); } + +static HRESULT gfx_frame_window(HWND hwnd) +{ + HRESULT hr; + DWORD error; + LONG style; + RECT rect; + BOOL ok; + + SetLastError(ERROR_SUCCESS); + style = GetWindowLongW(hwnd, GWL_STYLE); + error = GetLastError(); + + if (error != ERROR_SUCCESS) { + hr = HRESULT_FROM_WIN32(error); + dprintf("Gfx: GetWindowLongPtrW(%p, GWL_STYLE) failed: %x\n", + hwnd, + (int) hr); + + return hr; + } + + ok = GetClientRect(hwnd, &rect); + + if (!ok) { + hr = HRESULT_FROM_WIN32(GetLastError()); + dprintf("Gfx: GetClientRect(%p) failed: %x\n", hwnd, (int) hr); + + return hr; + } + + style |= WS_BORDER | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU; + ok = AdjustWindowRect(&rect, style, FALSE); + + if (!ok) { + /* come on... */ + hr = HRESULT_FROM_WIN32(GetLastError()); + dprintf("Gfx: AdjustWindowRect failed: %x\n", (int) hr); + + return hr; + } + + /* This... always seems to set an error, even though it works? idk */ + SetWindowLongW(hwnd, GWL_STYLE, style); + + ok = SetWindowPos( + hwnd, + HWND_TOP, + rect.left, + rect.top, + rect.right - rect.left, + rect.bottom - rect.top, + SWP_FRAMECHANGED | SWP_NOMOVE); + + if (!ok) { + hr = HRESULT_FROM_WIN32(GetLastError()); + dprintf("Gfx: SetWindowPos(%p) failed: %x\n", hwnd, (int) hr); + + return hr; + } + + return S_OK; +}