Skip to content

Commit

Permalink
fix for window position not getting restored properly
Browse files Browse the repository at this point in the history
  • Loading branch information
FunkyFr3sh committed Aug 31, 2018
1 parent 557359b commit 559923f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
32 changes: 22 additions & 10 deletions src/ddraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct {
LRESULT(CALLBACK *OrgWndProc)(HWND, UINT, WPARAM, LPARAM);
BOOL Fullscreen = TRUE;
BOOL MouseLocked;
RECT OldWindowPos;
RECT WindowRect;
HWND hwnd_main;
void* pvBmpBits;
HDC hdc_offscreen;
Expand Down Expand Up @@ -77,11 +77,11 @@ void FixBnet(BOOL showWindow)
{
if (showWindow)
{
SetWindowPos(hwnd_main, HWND_TOPMOST, OldWindowPos.left, OldWindowPos.top, 0, 0, SWP_NOSIZE);
SetWindowPos(hwnd_main, HWND_TOPMOST, WindowRect.left, WindowRect.top, 0, 0, SWP_NOSIZE);
}
else
{
GetWindowRect(hwnd_main, &OldWindowPos);
GetWindowRect(hwnd_main, &WindowRect);

int captsize = GetSystemMetrics(SM_CYCAPTION);
SetWindowPos(hwnd_main, HWND_NOTOPMOST, 0, captsize > 0 ? -(captsize / 2) : 0, 0, 0, SWP_NOSIZE);
Expand All @@ -105,13 +105,25 @@ void ToggleFullscreen()
ddraw->lpVtbl->RestoreDisplayMode(ddraw);
}

LONG x = OldWindowPos.right ? OldWindowPos.left : (GetSystemMetrics(SM_CXSCREEN) / 2) - (width / 2);
LONG y = OldWindowPos.right ? OldWindowPos.top : (GetSystemMetrics(SM_CYSCREEN) / 2) - (height / 2);
RECT dst = { x, y, width + x, height + y };

SetWindowLong(hwnd_main, GWL_STYLE, GetWindowLong(hwnd_main, GWL_STYLE) | WS_CAPTION | WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX);
AdjustWindowRect(&dst, GetWindowLong(hwnd_main, GWL_STYLE), FALSE);
SetWindowPos(hwnd_main, HWND_TOPMOST, dst.left, dst.top, (dst.right - dst.left), (dst.bottom - dst.top), SWP_SHOWWINDOW);

if (!WindowRect.right && !WindowRect.bottom)
{
LONG x = (GetSystemMetrics(SM_CXSCREEN) / 2) - (width / 2);
LONG y = (GetSystemMetrics(SM_CYSCREEN) / 2) - (height / 2);
WindowRect = { x, y, width + x, height + y };

AdjustWindowRect(&WindowRect, GetWindowLong(hwnd_main, GWL_STYLE), FALSE);
}

SetWindowPos(
hwnd_main,
HWND_TOPMOST,
WindowRect.left,
WindowRect.top,
(WindowRect.right - WindowRect.left),
(WindowRect.bottom - WindowRect.top),
SWP_SHOWWINDOW);

FixBnet(FALSE);
}
Expand All @@ -122,7 +134,7 @@ void ToggleFullscreen()
MouseUnlock();

if (!FindWindowEx(HWND_DESKTOP, NULL, "SDlgDialog", NULL))
GetWindowRect(hwnd_main, &OldWindowPos);
GetWindowRect(hwnd_main, &WindowRect);

SetWindowLong(hwnd_main, GWL_STYLE, GetWindowLong(hwnd_main, GWL_STYLE) & ~(WS_CAPTION | WS_THICKFRAME | WS_SYSMENU));
SetWindowPos(hwnd_main, 0, 0, 0, width, height, SWP_NOZORDER | SWP_NOOWNERZORDER);
Expand Down
6 changes: 3 additions & 3 deletions src/resource.rc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <windows.h>

VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,1,4,0
PRODUCTVERSION 0,1,4,0
FILEVERSION 0,1,4,1
PRODUCTVERSION 0,1,4,1
FILEFLAGSMASK 63
FILEFLAGS 0
FILEOS VOS_UNKNOWN
Expand All @@ -14,7 +14,7 @@ FILESUBTYPE VFT2_UNKNOWN
BLOCK "040904E4" /* LANG_ENGLISH/SUBLANG_DEFAULT, CP 1252 */
{
VALUE "FileDescription", "compatibility ddraw proxy for war2bne"
VALUE "FileVersion", "0.1.4.0"
VALUE "FileVersion", "0.1.4.1"
VALUE "LegalCopyright", "https://github.com/FunkyFr3sh/Aqrit-DDraw-Hack"
}
}
Expand Down

0 comments on commit 559923f

Please sign in to comment.