Fix "Force Windowned Mode" crash.

This commit is contained in:
Robert Krawczyk 2016-02-01 22:22:54 +01:00
parent ca6ccbacd3
commit eb221b4429
2 changed files with 33 additions and 29 deletions

View file

@ -130,15 +130,18 @@ bool MainContext::ApplyPresentationParameters(D3DPRESENT_PARAMETERS* pPresentati
if (config.GetBorderless()) if (config.GetBorderless())
{ {
SetWindowPos(pPresentationParameters->hDeviceWindow, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOMOVE | SWP_NOSENDCHANGING); int cx = GetSystemMetrics(SM_CXSCREEN);
int cy = GetSystemMetrics(SM_CYSCREEN);
SetWindowPos(pPresentationParameters->hDeviceWindow, HWND_TOP, 0, 0, cx, cy, SWP_SHOWWINDOW | SWP_NOCOPYBITS | SWP_NOSENDCHANGING);
if (config.GetForceWindowedMode()) if (config.GetForceWindowedMode())
{ {
pPresentationParameters->SwapEffect = D3DSWAPEFFECT_FLIP; pPresentationParameters->SwapEffect = pPresentationParameters->MultiSampleType == D3DMULTISAMPLE_NONE ? D3DSWAPEFFECT_DISCARD : D3DSWAPEFFECT_FLIP;
pPresentationParameters->Windowed = TRUE; pPresentationParameters->Windowed = TRUE;
pPresentationParameters->FullScreen_RefreshRateInHz = 0; pPresentationParameters->FullScreen_RefreshRateInHz = 0;
PrintLog("ForceWindowedMode");
} }
PrintLog("ForceWindowedMode: Windowed set to TRUE");
} }
if (config.GetHideCursor()) while (::ShowCursor(FALSE) >= 0); // ShowCursor < 0 -> hidden if (config.GetHideCursor()) while (::ShowCursor(FALSE) >= 0); // ShowCursor < 0 -> hidden
@ -158,11 +161,11 @@ bool MainContext::CheckWindow(HWND hWnd)
PrintLog("HWND 0x%p: ClassName \"%ls\", WindowName: \"%ls\"", hWnd, className.get(), windowName.get()); PrintLog("HWND 0x%p: ClassName \"%ls\", WindowName: \"%ls\"", hWnd, className.get(), windowName.get());
bool classname = config.GetWindowClass().compare(className.get()) == 0; bool class_found = config.GetWindowClass().compare(className.get()) == 0;
bool windowname = config.GetWindowName().compare(windowName.get()) == 0; bool window_found = config.GetWindowName().compare(windowName.get()) == 0;
bool always = config.GetAllWindows(); bool force = config.GetAllWindows();
return classname || windowname || always; return class_found || window_found || force;
} }
void MainContext::ApplyWndProc(HWND hWnd) void MainContext::ApplyWndProc(HWND hWnd)
@ -181,7 +184,7 @@ void MainContext::ApplyBorderless(HWND hWnd)
LONG_PTR dwExStyle = GetWindowLongPtr(hWnd, GWL_EXSTYLE); LONG_PTR dwExStyle = GetWindowLongPtr(hWnd, GWL_EXSTYLE);
DWORD new_dwStyle = dwStyle & ~WS_OVERLAPPEDWINDOW; DWORD new_dwStyle = dwStyle & ~WS_OVERLAPPEDWINDOW;
DWORD new_dwExStyle = dwExStyle & ~(WS_EX_OVERLAPPEDWINDOW | WS_EX_TOPMOST); DWORD new_dwExStyle = dwExStyle & ~(WS_EX_OVERLAPPEDWINDOW);
context.TrueSetWindowLongW(hWnd, GWL_STYLE, new_dwStyle); context.TrueSetWindowLongW(hWnd, GWL_STYLE, new_dwStyle);
context.TrueSetWindowLongW(hWnd, GWL_EXSTYLE, new_dwExStyle); context.TrueSetWindowLongW(hWnd, GWL_EXSTYLE, new_dwExStyle);
@ -239,7 +242,7 @@ LONG WINAPI MainContext::HookSetWindowLongA(HWND hWnd, int nIndex, LONG dwNewLon
if (nIndex == GWL_EXSTYLE) if (nIndex == GWL_EXSTYLE)
{ {
dwNewLong &= ~(WS_EX_OVERLAPPEDWINDOW | WS_EX_TOPMOST); dwNewLong &= ~(WS_EX_OVERLAPPEDWINDOW);
PrintLog("SetWindowLongA dwExStyle: %lX->%lX", olddwNewLong, dwNewLong); PrintLog("SetWindowLongA dwExStyle: %lX->%lX", olddwNewLong, dwNewLong);
} }
} }
@ -259,7 +262,7 @@ LONG WINAPI MainContext::HookSetWindowLongW(HWND hWnd, int nIndex, LONG dwNewLon
if (nIndex == GWL_EXSTYLE) if (nIndex == GWL_EXSTYLE)
{ {
dwNewLong &= ~(WS_EX_OVERLAPPEDWINDOW | WS_EX_TOPMOST); dwNewLong &= ~(WS_EX_OVERLAPPEDWINDOW);
PrintLog("SetWindowLongW dwExStyle: %lX->%lX", olddwNewLong, dwNewLong); PrintLog("SetWindowLongW dwExStyle: %lX->%lX", olddwNewLong, dwNewLong);
} }
} }

View file

@ -1,19 +1,20 @@
SETTING(u32, LongValue, PresentationInterval, Options, -1); SETTING(u32, LongValue, PresentationInterval, Options, -1);
SETTING(bool, BoolValue, TrippleBuffering, Options, false); SETTING(bool, BoolValue, TrippleBuffering, Options, false);
SETTING(bool, BoolValue, AlwaysActive, Options, false); SETTING(bool, BoolValue, AlwaysActive, Options, false);
SETTING(bool, BoolValue, AutoFix, Options, true); SETTING(bool, BoolValue, AutoFix, Options, true);
SETTING(u32, LongValue, Multisample, Options, 0); SETTING(u32, LongValue, Multisample, Options, 0);
SETTING(bool, BoolValue, HideCursor, Options, false); SETTING(bool, BoolValue, HideCursor, Options, false);
SETTING(u32, LongValue, BehaviorFlags, Options, 0); SETTING(u32, LongValue, BehaviorFlags, Options, 0);
SETTING(bool, BoolValue, Adapter, Adapter, false); SETTING(bool, BoolValue, Adapter, Adapter, false);
SETTING(u32, LongValue, VendorId, Adapter, 0); SETTING(u32, LongValue, VendorId, Adapter, 0);
SETTING(u32, LongValue, DeviceId, Adapter, 0); SETTING(u32, LongValue, DeviceId, Adapter, 0);
SETTING(bool, BoolValue, Borderless, Borderless, false); SETTING(bool, BoolValue, Borderless, Borderless, false);
SETTING(bool, BoolValue, ForceWindowedMode, Borderless, false); SETTING(bool, BoolValue, ForceWindowedMode, Borderless, false);
SETTING(bool, BoolValue, AllWindows, Borderless, false); SETTING(bool, BoolValue, AllWindows, Borderless, false);
SETTING(std::wstring, StringValue, WindowClass, Borderless, L""); SETTING(bool, BoolValue, TopMost, Borderless, false);
SETTING(std::wstring, StringValue, WindowName, Borderless, L""); SETTING(std::wstring, StringValue, WindowClass, Borderless, L"");
SETTING(std::wstring, StringValue, WindowName, Borderless, L"");