Skip to content

Add DPI-aware wrapper methods for Win32 system metrics and window sizing#39

Merged
Lakritzator merged 7 commits intomasterfrom
copilot/add-win32-dpi-calls
Feb 20, 2026
Merged

Add DPI-aware wrapper methods for Win32 system metrics and window sizing#39
Lakritzator merged 7 commits intomasterfrom
copilot/add-win32-dpi-calls

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 18, 2026

Adds convenient type-safe wrappers for Win32 DPI APIs to simplify DPI-aware window management and system metric retrieval.

Changes

  • New DpiApi class with 6 wrapper methods:

    • GetSystemMetrics() / GetSystemMetricsForWindow() - DPI-scaled system metrics
    • AdjustWindowRect() / AdjustWindowRectForWindow() - DPI-aware window rect calculation from client rect
    • GetSystemParametersInfo<T>() / GetSystemParametersInfoForWindow<T>() - Type-safe system parameters with DPI
  • P/Invoke declarations added to NativeDpiMethods:

    • GetSystemMetricsForDpi()
    • AdjustWindowRectExForDpi()
  • Tests for all new wrapper methods

Usage

// Get DPI-scaled metrics
var borderWidth = DpiApi.GetSystemMetrics(SystemMetric.SM_CXBORDER, dpi: 144);
var screenWidth = DpiApi.GetSystemMetricsForWindow(SystemMetric.SM_CXSCREEN, hwnd);

// Calculate window rect from client rect with DPI awareness
var clientRect = new NativeRect(0, 0, 800, 600);
var windowRect = DpiApi.AdjustWindowRect(
    clientRect, 
    WindowStyleFlags.WS_OVERLAPPEDWINDOW,
    dpi: 144);

// Type-safe system parameters
var iconMetrics = DpiApi.GetSystemParametersInfo<IconMetrics>(
    SystemParametersInfoActions.SPI_GETICONMETRICS, 
    dpi: 192);

All methods return nullable types for clean error handling and support both explicit DPI values and window handle-based DPI detection.

Original prompt

This section details on the original issue you should resolve

<issue_title>Add more Win32 DPI calls</issue_title>
<issue_description>Extend the functionality in Dapplo.Windows.Dpi a more convenient way to call:

So not just the pinvoke with the metrics which returns result.
Place these in DpiApi.cs

Hint: The Enum for the metrics is already available as Dapplo.Windows.User32.Enums.SystemMetric but some metrics have specific results which are also an enum.

Consider other Windows DPI relevant things...
</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…wRectExForDpi) and DpiApi convenience class

Co-authored-by: Lakritzator <708125+Lakritzator@users.noreply.github.com>
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI and others added 5 commits February 18, 2026 15:48
Co-authored-by: Lakritzator <708125+Lakritzator@users.noreply.github.com>
Co-authored-by: Lakritzator <708125+Lakritzator@users.noreply.github.com>
Co-authored-by: Lakritzator <708125+Lakritzator@users.noreply.github.com>
Co-authored-by: Lakritzator <708125+Lakritzator@users.noreply.github.com>
…e readability

Co-authored-by: Lakritzator <708125+Lakritzator@users.noreply.github.com>
Copilot AI changed the title [WIP] Add more Win32 DPI calls for convenience Add DPI-aware wrapper methods for Win32 system metrics and window sizing Feb 18, 2026
Copilot AI requested a review from Lakritzator February 18, 2026 15:56
@Lakritzator Lakritzator marked this pull request as ready for review February 20, 2026 12:02
@Lakritzator Lakritzator merged commit be0c91a into master Feb 20, 2026
1 check was pending
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.

Add more Win32 DPI calls

3 participants