Skip to content

Commit

Permalink
Fix "Force Windowned Mode" crash.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nucleoprotein committed Feb 1, 2016
1 parent ca6ccba commit eb221b4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
23 changes: 13 additions & 10 deletions d3d9ex/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,18 @@ bool MainContext::ApplyPresentationParameters(D3DPRESENT_PARAMETERS* pPresentati

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())
{
pPresentationParameters->SwapEffect = D3DSWAPEFFECT_FLIP;
pPresentationParameters->SwapEffect = pPresentationParameters->MultiSampleType == D3DMULTISAMPLE_NONE ? D3DSWAPEFFECT_DISCARD : D3DSWAPEFFECT_FLIP;
pPresentationParameters->Windowed = TRUE;
pPresentationParameters->FullScreen_RefreshRateInHz = 0;
PrintLog("ForceWindowedMode");
}
PrintLog("ForceWindowedMode: Windowed set to TRUE");
}

if (config.GetHideCursor()) while (::ShowCursor(FALSE) >= 0); // ShowCursor < 0 -> hidden
Expand All @@ -158,11 +161,11 @@ bool MainContext::CheckWindow(HWND hWnd)

PrintLog("HWND 0x%p: ClassName \"%ls\", WindowName: \"%ls\"", hWnd, className.get(), windowName.get());

bool classname = config.GetWindowClass().compare(className.get()) == 0;
bool windowname = config.GetWindowName().compare(windowName.get()) == 0;
bool always = config.GetAllWindows();
bool class_found = config.GetWindowClass().compare(className.get()) == 0;
bool window_found = config.GetWindowName().compare(windowName.get()) == 0;
bool force = config.GetAllWindows();

return classname || windowname || always;
return class_found || window_found || force;
}

void MainContext::ApplyWndProc(HWND hWnd)
Expand All @@ -181,7 +184,7 @@ void MainContext::ApplyBorderless(HWND hWnd)
LONG_PTR dwExStyle = GetWindowLongPtr(hWnd, GWL_EXSTYLE);

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_EXSTYLE, new_dwExStyle);
Expand Down Expand Up @@ -239,7 +242,7 @@ LONG WINAPI MainContext::HookSetWindowLongA(HWND hWnd, int nIndex, LONG dwNewLon

if (nIndex == GWL_EXSTYLE)
{
dwNewLong &= ~(WS_EX_OVERLAPPEDWINDOW | WS_EX_TOPMOST);
dwNewLong &= ~(WS_EX_OVERLAPPEDWINDOW);
PrintLog("SetWindowLongA dwExStyle: %lX->%lX", olddwNewLong, dwNewLong);
}
}
Expand All @@ -259,7 +262,7 @@ LONG WINAPI MainContext::HookSetWindowLongW(HWND hWnd, int nIndex, LONG dwNewLon

if (nIndex == GWL_EXSTYLE)
{
dwNewLong &= ~(WS_EX_OVERLAPPEDWINDOW | WS_EX_TOPMOST);
dwNewLong &= ~(WS_EX_OVERLAPPEDWINDOW);
PrintLog("SetWindowLongW dwExStyle: %lX->%lX", olddwNewLong, dwNewLong);
}
}
Expand Down
39 changes: 20 additions & 19 deletions d3d9ex/Settings.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@

SETTING(u32, LongValue, PresentationInterval, Options, -1);
SETTING(bool, BoolValue, TrippleBuffering, Options, false);
SETTING(bool, BoolValue, AlwaysActive, Options, false);
SETTING(bool, BoolValue, AutoFix, Options, true);
SETTING(u32, LongValue, Multisample, Options, 0);
SETTING(bool, BoolValue, HideCursor, Options, false);
SETTING(u32, LongValue, BehaviorFlags, Options, 0);

SETTING(bool, BoolValue, Adapter, Adapter, false);
SETTING(u32, LongValue, VendorId, Adapter, 0);
SETTING(u32, LongValue, DeviceId, Adapter, 0);

SETTING(bool, BoolValue, Borderless, Borderless, false);
SETTING(bool, BoolValue, ForceWindowedMode, Borderless, false);
SETTING(bool, BoolValue, AllWindows, Borderless, false);
SETTING(std::wstring, StringValue, WindowClass, Borderless, L"");
SETTING(std::wstring, StringValue, WindowName, Borderless, L"");


SETTING(u32, LongValue, PresentationInterval, Options, -1);
SETTING(bool, BoolValue, TrippleBuffering, Options, false);
SETTING(bool, BoolValue, AlwaysActive, Options, false);
SETTING(bool, BoolValue, AutoFix, Options, true);
SETTING(u32, LongValue, Multisample, Options, 0);
SETTING(bool, BoolValue, HideCursor, Options, false);
SETTING(u32, LongValue, BehaviorFlags, Options, 0);

SETTING(bool, BoolValue, Adapter, Adapter, false);
SETTING(u32, LongValue, VendorId, Adapter, 0);
SETTING(u32, LongValue, DeviceId, Adapter, 0);

SETTING(bool, BoolValue, Borderless, Borderless, false);
SETTING(bool, BoolValue, ForceWindowedMode, Borderless, false);
SETTING(bool, BoolValue, AllWindows, Borderless, false);
SETTING(bool, BoolValue, TopMost, Borderless, false);
SETTING(std::wstring, StringValue, WindowClass, Borderless, L"");
SETTING(std::wstring, StringValue, WindowName, Borderless, L"");

0 comments on commit eb221b4

Please sign in to comment.