From 28c1ab5c63a912f8df20db22d5ff0881a5aa09d2 Mon Sep 17 00:00:00 2001 From: githubawn <115191165+githubawn@users.noreply.github.com> Date: Thu, 16 Apr 2026 05:07:15 +0200 Subject: [PATCH 1/2] Add Alt+Enter support for fullscreen toggling --- .../Include/Common/OptionPreferences.h | 2 + .../Source/Common/OptionPreferences.cpp | 17 ++++++ .../Source/WWVegas/WW3D2/dx8wrapper.cpp | 18 ++----- .../GameEngine/Include/Common/GlobalData.h | 4 +- .../GameEngine/Source/Common/CommandLine.cpp | 6 +++ .../GameEngine/Source/Common/GlobalData.cpp | 11 ++++ GeneralsMD/Code/Main/WinMain.cpp | 54 +++++++++++++++++++ 7 files changed, 98 insertions(+), 14 deletions(-) diff --git a/Core/GameEngine/Include/Common/OptionPreferences.h b/Core/GameEngine/Include/Common/OptionPreferences.h index 2bacaa07105..1bebcfa93ab 100644 --- a/Core/GameEngine/Include/Common/OptionPreferences.h +++ b/Core/GameEngine/Include/Common/OptionPreferences.h @@ -88,6 +88,8 @@ class OptionPreferences : public UserPreferences Real getGammaValue(); Int getTextureReduction(); void getResolution(Int *xres, Int *yres); + Bool getWindowed() const; + void setWindowed(Bool windowed); Bool get3DShadowsEnabled(); Bool get2DShadowsEnabled(); Bool getCloudShadowsEnabled(); diff --git a/Core/GameEngine/Source/Common/OptionPreferences.cpp b/Core/GameEngine/Source/Common/OptionPreferences.cpp index 36df300ef8a..63540e2ea8d 100644 --- a/Core/GameEngine/Source/Common/OptionPreferences.cpp +++ b/Core/GameEngine/Source/Common/OptionPreferences.cpp @@ -714,6 +714,23 @@ void OptionPreferences::getResolution(Int *xres, Int *yres) *yres=selectedYRes; } +Bool OptionPreferences::getWindowed() const +{ + OptionPreferences::const_iterator it = find("Windowed"); + if (it == end()) + return FALSE; + + if (stricmp(it->second.str(), "yes") == 0) { + return TRUE; + } + return FALSE; +} + +void OptionPreferences::setWindowed(Bool windowed) +{ + insert(std::make_pair(AsciiString("Windowed"), AsciiString(windowed ? "yes" : "no"))); +} + Real OptionPreferences::getMusicVolume() { OptionPreferences::const_iterator it = find("MusicVolume"); diff --git a/Core/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp b/Core/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp index 1e420b66798..33f34266a66 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp @@ -1241,20 +1241,12 @@ const char * DX8Wrapper::Get_Render_Device_Name(int device_index) bool DX8Wrapper::Set_Device_Resolution(int width,int height,int bits,int windowed, bool resize_window) { if (D3DDevice != nullptr) { + int w = (width == -1) ? ResolutionWidth : width; + int h = (height == -1) ? ResolutionHeight : height; + int b = (bits == -1) ? BitDepth : bits; + int win = (windowed == -1) ? IsWindowed : windowed; - if (width != -1) { - _PresentParameters.BackBufferWidth = ResolutionWidth = width; - } - if (height != -1) { - _PresentParameters.BackBufferHeight = ResolutionHeight = height; - } - if (resize_window) - { - Resize_And_Position_Window(); - } -#pragma message("TODO: support changing windowed status and changing the bit depth") - WWDEBUG_SAY(("DX8Wrapper::Set_Device_Resolution is resetting the device.")); - return Reset_Device(); + return Set_Render_Device(CurRenderDevice, w, h, b, win, resize_window, true, true); } else { return false; } diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h index 53ae5d7459a..03187281f53 100644 --- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h +++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h @@ -54,7 +54,7 @@ constexpr const Int MAX_GLOBAL_LIGHTS = 3; constexpr const Int SIMULATE_REPLAYS_SEQUENTIAL = -1; //------------------------------------------------------------------------------------------------- -class CommandLineData +struct CommandLineData { friend class CommandLine; friend class GlobalData; @@ -62,10 +62,12 @@ class CommandLineData CommandLineData() : m_hasParsedCommandLineForStartup(false) , m_hasParsedCommandLineForEngineInit(false) + , m_windowedCommandLineSpecified(false) {} Bool m_hasParsedCommandLineForStartup; Bool m_hasParsedCommandLineForEngineInit; + Bool m_windowedCommandLineSpecified; }; //------------------------------------------------------------------------------------------------- diff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp index cd2284943a5..b2611b0c93d 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp @@ -29,6 +29,7 @@ #include "Common/CommandLine.h" #include "Common/CRCDebug.h" #include "Common/LocalFileSystem.h" +#include "Common/OptionPreferences.h" #include "Common/Recorder.h" #include "Common/version.h" #include "GameClient/ClientInstance.h" @@ -118,6 +119,7 @@ Int parseNoLogOrCrash(char *args[], int) Int parseWin(char *args[], int) { TheWritableGlobalData->m_windowed = true; + TheWritableGlobalData->m_commandLineData.m_windowedCommandLineSpecified = true; return 1; } @@ -377,6 +379,7 @@ Int parseNoAudio(char *args[], int) Int parseNoWin(char *args[], int) { TheWritableGlobalData->m_windowed = false; + TheWritableGlobalData->m_commandLineData.m_windowedCommandLineSpecified = true; return 1; } @@ -1450,6 +1453,9 @@ void CommandLine::parseCommandLineForStartup() return; TheWritableGlobalData->m_commandLineData.m_hasParsedCommandLineForStartup = true; + OptionPreferences optionPref; + TheWritableGlobalData->m_windowed = optionPref.getWindowed(); + parseCommandLine(paramsForStartup, ARRAY_SIZE(paramsForStartup)); } diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp index 3d9382d0b60..3d972a26777 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp @@ -1162,6 +1162,8 @@ void GlobalData::reset() //------------------------------------------------------------------------------------------------- void GlobalData::parseGameDataDefinition( INI* ini ) { + Bool cmdWindowed = TheGlobalData->m_windowed; + if( TheWritableGlobalData && ini->getLoadType() != INI_LOAD_MULTIFILE) { @@ -1211,6 +1213,15 @@ void GlobalData::parseGameDataDefinition( INI* ini ) TheWritableGlobalData->m_playerInfoListFontSize = optionPref.getPlayerInfoListFontSize(); TheWritableGlobalData->m_showMoneyPerMinute = optionPref.getShowMoneyPerMinute(); + if (TheGlobalData->m_commandLineData.m_windowedCommandLineSpecified) + { + TheWritableGlobalData->m_windowed = cmdWindowed; + } + else + { + TheWritableGlobalData->m_windowed = optionPref.getWindowed(); + } + Int val=optionPref.getGammaValue(); //generate a value between 0.6 and 2.0. if (val < 50) diff --git a/GeneralsMD/Code/Main/WinMain.cpp b/GeneralsMD/Code/Main/WinMain.cpp index d285cb8ad46..01fb71d3f74 100644 --- a/GeneralsMD/Code/Main/WinMain.cpp +++ b/GeneralsMD/Code/Main/WinMain.cpp @@ -51,9 +51,11 @@ #include "Common/GameMemory.h" #include "Common/StackDump.h" #include "Common/MessageStream.h" +#include "Common/OptionPreferences.h" #include "Common/Registry.h" #include "Common/Team.h" #include "GameClient/ClientInstance.h" +#include "GameClient/Display.h" #include "GameClient/InGameUI.h" #include "GameClient/GameClient.h" #include "GameLogic/GameLogic.h" ///< @todo for demo, remove @@ -655,6 +657,58 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message, break; } #endif + case WM_SYSKEYDOWN: + { + if (wParam == VK_RETURN && (lParam & (1 << 29))) // Alt + Enter + { + if (TheGameEngine && !TheGameEngine->getQuitting() && TheDisplay) + { + TheWritableGlobalData->m_windowed = !TheGlobalData->m_windowed; + + DWORD windowStyle = WS_POPUP | WS_VISIBLE; + DWORD exStyle = 0; + Int resX = TheGlobalData->m_xResolution; + Int resY = TheGlobalData->m_yResolution; + + if (TheGlobalData->m_windowed) + { + windowStyle |= WS_MINIMIZEBOX | WS_SYSMENU | WS_DLGFRAME | WS_CAPTION; + } + else + { + windowStyle |= WS_SYSMENU; + exStyle |= WS_EX_TOPMOST; + } + + RECT windowRect = { 0, 0, resX, resY }; + AdjustWindowRect(&windowRect, windowStyle, FALSE); + int width = windowRect.right - windowRect.left; + int height = windowRect.bottom - windowRect.top; + + int x = 0, y = 0; + if (TheGlobalData->m_windowed) + { + x = max(0, (GetSystemMetrics(SM_CXSCREEN) - width) / 2); + y = max(0, (GetSystemMetrics(SM_CYSCREEN) - height) / 2); + } + + TheDisplay->setDisplayMode(resX, resY, 32, TheGlobalData->m_windowed); + + OptionPreferences optionPref; + optionPref.setWindowed(TheGlobalData->m_windowed); + optionPref.write(); + + // TheSuperHackers @info Apply styles and position after mode switch + SetWindowLong(hWnd, GWL_STYLE, windowStyle); + SetWindowLong(hWnd, GWL_EXSTYLE, exStyle); + SetWindowPos(hWnd, TheGlobalData->m_windowed ? HWND_NOTOPMOST : HWND_TOPMOST, + x, y, width, height, SWP_FRAMECHANGED | SWP_SHOWWINDOW); + UpdateWindow(hWnd); + } + return 0; + } + break; + } } } From 7ffc475f5941a0242353b3a7fc3b32d161317143 Mon Sep 17 00:00:00 2001 From: githubawn <115191165+githubawn@users.noreply.github.com> Date: Thu, 16 Apr 2026 05:25:45 +0200 Subject: [PATCH 2/2] greptile feedback implemented --- Core/GameEngine/Source/Common/OptionPreferences.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/GameEngine/Source/Common/OptionPreferences.cpp b/Core/GameEngine/Source/Common/OptionPreferences.cpp index 63540e2ea8d..b5e83410da7 100644 --- a/Core/GameEngine/Source/Common/OptionPreferences.cpp +++ b/Core/GameEngine/Source/Common/OptionPreferences.cpp @@ -728,7 +728,7 @@ Bool OptionPreferences::getWindowed() const void OptionPreferences::setWindowed(Bool windowed) { - insert(std::make_pair(AsciiString("Windowed"), AsciiString(windowed ? "yes" : "no"))); + (*this)["Windowed"] = (windowed ? "yes" : "no"); } Real OptionPreferences::getMusicVolume()