hooklib/gfx.c: Add option to frame the d3d window

This commit is contained in:
Tau 2019-10-19 17:05:09 -04:00
parent 7c721aa1f8
commit b270eaf1c6

View File

@ -23,6 +23,7 @@ static HRESULT STDMETHODCALLTYPE my_CreateDevice(
IDirect3DDevice9 **pdev); IDirect3DDevice9 **pdev);
static IDirect3D9 * WINAPI my_Direct3DCreate9(UINT sdk_ver); static IDirect3D9 * WINAPI my_Direct3DCreate9(UINT sdk_ver);
static IDirect3D9 * (WINAPI *next_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; static struct gfx_config gfx_config;
@ -106,5 +107,72 @@ static HRESULT STDMETHODCALLTYPE my_CreateDevice(
pp->FullScreen_RefreshRateInHz = 0; pp->FullScreen_RefreshRateInHz = 0;
} }
if (gfx_config.framed) {
gfx_frame_window(hwnd);
}
return IDirect3D9_CreateDevice(real, adapter, type, hwnd, flags, pp, pdev); 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;
}