Skip to content
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

fix(msstyleEditorSharp): add support for improved DPI awareness on newer systems #129

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

BinToss
Copy link

@BinToss BinToss commented Aug 28, 2023

Problem

fixed property values not persisting, set appl. DPI aware, working on issue #83
f23db77#diff-ba5ff7872fe40f60eae65ab65149696947047a9dc0420273d6b363aa0778d538

The above changes added very simple DPI awareness which was introduced with Windows Vista. Because no other awareness was specified, all later systems will use this DPI awareness which scales GUIs as blurry bitmaps and will not update scaling when moved to a monitor with a different DPI.

Solution

  • Change <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware> to <dpiAware "http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware> for the best legacy support.
    • Windows 8.1 will use its simple per-monitor DPI awareness. Application UIs will not bitmap-stretch, but child windows and UI elements will not scale. Windows Vista, 7, and 8 will be aware of Primary display's DPI and its changes, but will use bitmap-stretching for scaling.
  • Add <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor, System, unaware</dpiAwareness> .
    • Windows 10 (1703) and later will use an improved per-monitor DPI awareness. Top-level and child HWNDs are notified of DPI change. Includes automatic DPI scaling of Non-client area, Theme-drawn bitmaps in common controls (comctl32 V6), and Dialogs (CreateDialog).
  • Add <gdiScaling xmlns="http://schemas.microsoft.com/SMI/2017/WindowsSettings">true</gdiScaling> to allow WinForm's GDI+ backend to be DPI-aware.

Because WinForms uses GDI+ to draw GUIs, we may need to enable GDI Scaling (only works on Windows 10 (1703) and later).

Since Windows Vista, <dpiAware>true</dpiAware> sets DPI awareness level to "system". According to the table under Per-Monitor and Per-Monitor (V2) DPI Awareness, system-level awareness means "All displays have the same DPI (the DPI of the primary display at the time the current user session was started)". The application will scale to the DPI of the Primary display. When the DPI is changed (whether it be that of the Primary display or because the window was moved to another display), Windows will scale the application via "bitmap-stretching", causing blurring.

Windows 8.1 introduced a (very simple) per-monitor DPI awareness level that could be set via <dpiAware>per monitor</dpiAware> or (allows pre-8.1 Windows to use system-awareness) <dpiAware>true/pm</dpiAware>.

Windows 10 (1607) introduced a new element, dpiAwareness. When this element is present, the dpiAware element is ignored. The values allowed for this element were equivalent to dpiAware's values until Windows 10 (1703) added the value "PerMonitorV2".

…pes on newer systems

- Change `<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>` to `<dpiAware "http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware>` for the best legacy support.
  - Windows 8.1 will use its simple per-monitor DPI awareness. Application UIs will not bitmap-stretch, but child windows and UI elements will not scale. Windows Vista, 7, and 8 will be aware of Primary display's DPI and its changes, but will use bitmap-stretching for scaling.
- Add `<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor, System, unaware</dpiAwareness>` .
  - Windows 10 (1703) and later will use an improved per-monitor DPI awareness. Top-level and child HWNDs are notified of DPI change. Includes automatic DPI scaling of Non-client area, Theme-drawn bitmaps in common controls (comctl32 V6), and Dialogs (CreateDialog).
- Add `<gdiScaling xmlns="http://schemas.microsoft.com/SMI/2017/WindowsSettings">true</gdiScaling>` to allow WinForm's GDI+ backend to be DPI-aware.
@nptr
Copy link
Owner

nptr commented Aug 28, 2023

Thanks! I'll give it a try in the next few days and then merge. Shouldn't I target Framework 4.7 for those changes to work? I currently have it set to 4.5.

@nptr
Copy link
Owner

nptr commented Sep 11, 2023

I tried the changes and they kind of worked. The ribbon menu still looks ugly however. I'll see if i can fix it properly first and only then declare the app DPI aware.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants