using System; using System.Runtime.InteropServices; namespace Vanara.PInvoke { public static partial class User32 { /// Returns the system DPI. /// The system DPI value. /// /// /// The return value will be dependent based upon the calling context. If the current thread has a DPI_AWARENESS value of /// DPI_AWARENESS_UNAWARE, the return value will be 96. That is because the current context always assumes a DPI of 96. For /// any other DPI_AWARENESS value, the return value will be the actual system DPI. /// /// You should not cache the system DPI, but should use GetDpiForSystem whenever you need the system DPI value. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getdpiforsystem UINT GetDpiForSystem( ); [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "B744EC4A-DB78-4654-B50F-C27CB7702899")] public static extern uint GetDpiForSystem(); /// /// Retrieves the system DPI associated with a given process. This is useful for avoiding compatibility issues that arise from /// sharing DPI-sensitive information between multiple system-aware processes with different system DPI values. /// /// The handle for the process to examine. If this value is null, this API behaves identically to GetDpiForSystem. /// The process's system DPI value. /// /// The return value will be dependent based upon the process passed as a parameter. If the specified process has a DPI_AWARENESS /// value of DPI_AWARENESS_UNAWARE, the return value will be 96. That is because the current context always assumes a DPI of /// 96. For any other DPI_AWARENESS value, the return value will be the actual system DPI of the given process. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getsystemdpiforprocess UINT GetSystemDpiForProcess( HANDLE // hProcess ); [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "94236ECF-E69A-4D77-AABA-D43FE8DF8203")] public static extern uint GetSystemDpiForProcess(HPROCESS hProcess); /// Retrieves the specified system metric or system configuration setting taking into account a provided DPI. /// The system metric or configuration setting to be retrieved. See GetSystemMetrics for the possible values. /// The DPI to use for scaling the metric. /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// /// /// This function returns the same result as GetSystemMetrics but scales it according to an arbitrary DPI you provide if appropriate. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getsystemmetricsfordpi int GetSystemMetricsForDpi( int // nIndex, UINT dpi ); [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "E95BB417-81FA-4824-BE68-A1E3E003F8E0")] public static extern int GetSystemMetricsForDpi(SystemMetric nIndex, uint dpi); /// Retrieves the value of one of the system-wide parameters, taking into account the provided DPI value. /// /// The system-wide parameter to be retrieved. This function is only intended for use with SPI_GETICONTITLELOGFONT, /// SPI_GETICONMETRICS, or SPI_GETNONCLIENTMETRICS. See SystemParametersInfo for more information on these values. /// /// /// A parameter whose usage and format depends on the system parameter being queried. For more information about system-wide /// parameters, see the uiAction parameter. If not otherwise indicated, you must specify zero for this parameter. /// /// /// A parameter whose usage and format depends on the system parameter being queried. For more information about system-wide /// parameters, see the uiAction parameter. If not otherwise indicated, you must specify NULL for this parameter. For /// information on the PVOID datatype, see Windows Data Types. /// /// Has no effect for with this API. This parameter only has an effect if you're setting parameter. /// The DPI to use for scaling the metric. /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// /// /// /// This function returns a similar result as SystemParametersInfo, but scales it according to an arbitrary DPI you provide (if /// appropriate). It only scales with the following possible values for uiAction: SPI_GETICONTITLELOGFONT, /// SPI_GETICONMETRICS, SPI_GETNONCLIENTMETRICS. Other possible uiAction values do not provide ForDPI behavior, and /// therefore this function returns 0 if called with them. /// /// /// For uiAction values that contain strings within their associated structures, only Unicode (LOGFONTW) strings are supported in /// this function. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-systemparametersinfofordpi BOOL // SystemParametersInfoForDpi( UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWinIni, UINT dpi ); [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "BA460A5B-5356-43A5-B232-03E6E72D15A2")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SystemParametersInfoForDpi(SPI uiAction, uint uiParam, IntPtr pvParam, uint fWinIni, uint dpi); } }