Skip to content

[GEN][ZH] Add Windows application manifest to executables #595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

valeronm
Copy link

@valeronm valeronm commented Apr 4, 2025

Currently, Windows treats the Gen and ZH executables as DPI unaware and forcefully scales the content of all application windows when the display scaling factor is set to something other than 100%. This means that when running the game in windowed mode with a resolution of 800x600, the real window size on screens with scaling set to 200% will be 1600x1200, and every pixel will simply be stretched to four pixels. To prevent this system scaling, the application should indicate to the system that it is DPI aware. The best way to achieve this is to add an application manifest with the dpiAware setting.

Another feature that can be configured via the application manifest is the application of modern visual styles. By default, applications are linked to ComCtl32.dll version 5, which contains UI elements styled like Windows 98/ME/2000. To use modern-looking elements, the application should request loading ComCtl32.dll version 6, which supports themed UI elements from Windows XP and later.

Changes

This PR adds an application manifest that addresses both issues:

  • Specifies that the application is DPI aware, preventing Windows from scaling the app’s windows.
  • Requests the modern version of the common controls library, ensuring that system dialogs in the app have a modern look.

Screenshots on screen with 200% display scaling

Without Manifest
Splash screen window scaled to 1600x1200 from 800x600, and the message dialog has stretched pixelated text, a Windows 98-style button, and an icon.
With Manifest
Splash screen remains unscaled at 800x600, and the message dialog has crisp text, a modern-looking button, and an icon.

@xezon
Copy link

xezon commented Apr 5, 2025

Is this more an enhancement or a fix? I have difficulties to decide.

@xezon xezon added Minor Severity: Minor < Major < Critical < Blocker Build Anything related to building, compiling labels Apr 5, 2025
@valeronm
Copy link
Author

valeronm commented Apr 5, 2025

I'd say that this is more enhancement. It's also currently possible to disable windows scaling by using "Compatibility" section on executable, but with this change there will be no need to do that. Also, looks like windows already applies this compatibility setting for original executables, possibly using some kind of compatibility database, so the issue happens only on manually built executable which is unknown to Windows.
Applying visual styles is definitely just an enhancement.

@xezon xezon added the Enhancement Is new feature or request label Apr 6, 2025
@helmutbuhler helmutbuhler self-requested a review April 14, 2025 21:42
Copy link

@helmutbuhler helmutbuhler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just reviewed it and tested this with VS6 and VS19 and it looks good.
Some things to note regarding the DPI Aware Setting:

  • We should use AdjustWindowRectExForDpi instead of AdjustWindowRect when we declare us dpi aware. But my Center Window PR #541 touches that code as well, so I'd wait until that is merged before we fix that.
  • We probably also should make the window resizeable to make different scalings on different monitors work.

But both issues shouldn't block this PR, we'll just have to fix those things eventually.

Not sure if I'm actually allowed to approve this and xezon want's this merged already though...

Copy link

@OmniBlade OmniBlade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the same file used for both binaries? It should probably be in a common location and just one copy used in addition to possibly templating it and having cmake generate the final file.

<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The manifest file should probably be templated for cmake to generate so we aren't hard coding 32bit unless "win32" covers both 32bit and 64bit applications?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's also win32 for 64-bit. Win32 is the name of the Windows-API, even the 64-bit version.

@xezon xezon added Gen Relates to Generals ZH Relates to Zero Hour labels May 16, 2025
@xezon xezon requested a review from OmniBlade May 16, 2025 19:53
@Mauller
Copy link

Mauller commented May 20, 2025

This could be merged sooner than later, it might help people who develop on laptops.

Copy link

@OmniBlade OmniBlade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm approving, but it looks like the manifest is the same file duplicated twice when ideallly there is just one copy all targets include, so if that is feasible I'd like to see the PR updated to include that before merge.

@helmutbuhler
Copy link

It seems @valeronm isn't around, so if there is no objection I'll merge this. It's a nice PR and I'd like to see it merged.

@xezon xezon merged commit 5121f07 into TheSuperHackers:main Jun 1, 2025
17 checks passed
@valeronm valeronm deleted the prevent_system_scaling_in_windowed_mode branch June 1, 2025 17:16
@valeronm
Copy link
Author

valeronm commented Jun 1, 2025

I was going to update the PR to use a single manifest for both targets but didn't have time to do that in the past weeks. I'll try to make separate PR to remove the duplication then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Build Anything related to building, compiling Enhancement Is new feature or request Gen Relates to Generals Minor Severity: Minor < Major < Critical < Blocker ZH Relates to Zero Hour
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants