Skip to content

Commit e6f4e50

Browse files
authored
add new window styles (#21)
ForceWindowStyle=0 - no change ForceWindowStyle=1 - borderless fullscreen (old) ForceWindowStyle=2 - window (new) ForceWindowStyle=3 - resizable window (new)
1 parent 1049249 commit e6f4e50

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

data/d3d9.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
[MAIN]
22
FPSLimit = 0 // max fps (0: unlimited/off)
3-
FPSLimitMode = 1 // 1: realtime (thread-lock) - 2: accurate (sleep-yield)
3+
FPSLimitMode = 2 // 1: realtime (thread-lock) | 2: accurate (sleep-yield)
44
FullScreenRefreshRateInHz = 0 // overrides refresh rate selected by directx
55
DisplayFPSCounter = 0 // displays fps and frametime on screen
66
ForceWindowedMode = 0 // activates forced windowed mode
77

88
[FORCEWINDOWED]
99
UsePrimaryMonitor = 0 // move window to primary monitor
1010
CenterWindow = 1 // center window on screen
11-
BorderlessFullscreen = 0 // borderless fullscreen windowed mode
1211
AlwaysOnTop = 0 // window stays always on top
1312
DoNotNotifyOnTaskSwitch = 0 // window ignores focus loss
13+
ForceWindowStyle = 0 // 1: borderless fullscreen | 2: window | 3: resizable window
1414

1515
[LAUNCHER]
1616
AppExe =

source/dllmain.cpp

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ HMODULE d3d9dll = NULL;
4646
bool bForceWindowedMode;
4747
bool bUsePrimaryMonitor;
4848
bool bCenterWindow;
49-
bool bBorderlessFullscreen;
5049
bool bAlwaysOnTop;
5150
bool bDoNotNotifyOnTaskSwitch;
5251
bool bDisplayFPSCounter;
5352
float fFPSLimit;
5453
int nFullScreenRefreshRateInHz;
54+
int nForceWindowStyle;
5555

5656
char WinDir[MAX_PATH+1];
5757

@@ -262,7 +262,7 @@ void ForceWindowed(D3DPRESENT_PARAMETERS* pPresentationParameters, D3DDISPLAYMOD
262262
int left = (int)info.rcMonitor.left;
263263
int top = (int)info.rcMonitor.top;
264264

265-
if (!bBorderlessFullscreen)
265+
if (nForceWindowStyle != 1) // not borderless fullscreen
266266
{
267267
left += (int)(((float)DesktopResX / 2.0f) - ((float)pPresentationParameters->BackBufferWidth / 2.0f));
268268
top += (int)(((float)DesktopResY / 2.0f) - ((float)pPresentationParameters->BackBufferHeight / 2.0f));
@@ -282,16 +282,36 @@ void ForceWindowed(D3DPRESENT_PARAMETERS* pPresentationParameters, D3DDISPLAYMOD
282282

283283
if (hwnd != NULL)
284284
{
285+
int cx, cy;
285286
UINT uFlags = SWP_SHOWWINDOW;
286-
if (bBorderlessFullscreen)
287+
LONG lOldStyle = GetWindowLong(hwnd, GWL_STYLE);
288+
LONG lOldExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
289+
LONG lNewStyle, lNewExStyle;
290+
if (nForceWindowStyle == 1) // borderless fullscreen
287291
{
288-
LONG lOldStyle = GetWindowLong(hwnd, GWL_STYLE);
289-
LONG lOldExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
290-
LONG lNewStyle = lOldStyle & ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_DLGFRAME);
292+
cx = DesktopResX;
293+
cy = DesktopResY;
294+
lNewStyle = lOldStyle & ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_DLGFRAME);
291295
lNewStyle |= (lOldStyle & WS_CHILD) ? 0 : WS_POPUP;
292-
LONG lNewExStyle = lOldExStyle & ~(WS_EX_CONTEXTHELP | WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE | WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW);
296+
lNewExStyle = lOldExStyle & ~(WS_EX_CONTEXTHELP | WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE | WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW);
293297
lNewExStyle |= WS_EX_APPWINDOW;
298+
}
299+
else
300+
{
301+
cx = pPresentationParameters->BackBufferWidth;
302+
cy = pPresentationParameters->BackBufferHeight;
303+
if (!bCenterWindow)
304+
uFlags |= SWP_NOMOVE;
294305

306+
if (nForceWindowStyle) // force windowed style
307+
{
308+
lOldExStyle &= ~(WS_EX_TOPMOST);
309+
lNewStyle = (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX);
310+
lNewStyle |= (nForceWindowStyle == 3) ? (WS_THICKFRAME | WS_MAXIMIZEBOX) : 0;
311+
lNewExStyle = (WS_EX_APPWINDOW | WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE);
312+
}
313+
}
314+
if (nForceWindowStyle) {
295315
if (lNewStyle != lOldStyle)
296316
{
297317
SetWindowLong(hwnd, GWL_STYLE, lNewStyle);
@@ -302,15 +322,8 @@ void ForceWindowed(D3DPRESENT_PARAMETERS* pPresentationParameters, D3DDISPLAYMOD
302322
SetWindowLong(hwnd, GWL_EXSTYLE, lNewExStyle);
303323
uFlags |= SWP_FRAMECHANGED;
304324
}
305-
SetWindowPos(hwnd, bAlwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST, left, top, DesktopResX, DesktopResY, uFlags);
306-
}
307-
else
308-
{
309-
if (!bCenterWindow)
310-
uFlags |= SWP_NOMOVE;
311-
312-
SetWindowPos(hwnd, bAlwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST, left, top, pPresentationParameters->BackBufferWidth, pPresentationParameters->BackBufferHeight, uFlags);
313325
}
326+
SetWindowPos(hwnd, bAlwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST, left, top, cx, cy, uFlags);
314327
}
315328
}
316329

@@ -947,9 +960,9 @@ bool WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
947960
bDisplayFPSCounter = GetPrivateProfileInt("MAIN", "DisplayFPSCounter", 0, path);
948961
bUsePrimaryMonitor = GetPrivateProfileInt("FORCEWINDOWED", "UsePrimaryMonitor", 0, path) != 0;
949962
bCenterWindow = GetPrivateProfileInt("FORCEWINDOWED", "CenterWindow", 1, path) != 0;
950-
bBorderlessFullscreen = GetPrivateProfileInt("FORCEWINDOWED", "BorderlessFullscreen", 0, path) != 0;
951963
bAlwaysOnTop = GetPrivateProfileInt("FORCEWINDOWED", "AlwaysOnTop", 0, path) != 0;
952964
bDoNotNotifyOnTaskSwitch = GetPrivateProfileInt("FORCEWINDOWED", "DoNotNotifyOnTaskSwitch", 0, path) != 0;
965+
nForceWindowStyle = GetPrivateProfileInt("FORCEWINDOWED", "ForceWindowStyle", 0, path);
953966

954967
if (fFPSLimit > 0.0f)
955968
{

0 commit comments

Comments
 (0)