1
0
mirror of https://github.com/FunkyFr3sh/cnc-ddraw.git synced 2025-03-15 06:04:49 +01:00

try to get at least some windowed games working with zero config

This commit is contained in:
FunkyFr3sh 2024-08-15 16:50:28 +02:00
parent aa357c044d
commit 33666bbd19
2 changed files with 29 additions and 3 deletions

View File

@ -166,7 +166,6 @@ typedef struct CNCDDRAW
int y;
} textbox; /* Age Of Empires 2 textbox align */
struct
{
BOOL enabled;

View File

@ -1427,6 +1427,13 @@ HRESULT dd_SetCooperativeLevel(HWND hwnd, DWORD dwFlags)
dd_SetDisplayMode(width, height, bpp, 0);
}
else if (!g_ddraw.width)
{
RECT rc = { 0 };
real_GetClientRect(hwnd, &rc);
dd_SetDisplayMode(rc.right, rc.bottom, 16, 0);
}
}
return DD_OK;
@ -1579,10 +1586,30 @@ ULONG dd_Release()
DeleteCriticalSection(&g_ddraw.cs);
/* restore old wndproc, subsequent ddraw creation will otherwise fail */
if (g_ddraw.hwnd)
if (g_ddraw.hwnd && IsWindow(g_ddraw.hwnd))
{
/* restore old wndproc, subsequent ddraw creation will otherwise fail */
real_SetWindowLongA(g_ddraw.hwnd, GWL_WNDPROC, (LONG)g_ddraw.wndproc);
/* restore old window size, required for games that can switch between windowed and fullscreen during runtime */
if (g_ddraw.width)
{
RECT rc = { 0, 0, g_ddraw.width, g_ddraw.height };
LONG style = real_GetWindowLongA(g_ddraw.hwnd, GWL_STYLE);
LONG exstyle = real_GetWindowLongA(g_ddraw.hwnd, GWL_EXSTYLE);
AdjustWindowRectEx(&rc, style, GetMenu(g_ddraw.hwnd) != NULL, exstyle);
real_SetWindowPos(
g_ddraw.hwnd,
0,
0,
0,
(rc.right - rc.left),
(rc.bottom - rc.top),
SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
}
}
memset(&g_ddraw, 0, sizeof(g_ddraw));