From 3aeab2950960ae532d56a7f9c247299c4e39f3d9 Mon Sep 17 00:00:00 2001 From: Hugh Bellamy Date: Thu, 25 Jul 2019 13:19:07 +0100 Subject: [PATCH] Cleanup GetSystemMetrics --- .../User32/Interop.GetSystemMetrics.cs | 120 +++++ src/Common/src/NativeMethods.cs | 79 +-- src/Common/src/UnsafeNativeMethods.cs | 26 - .../src/System.Windows.Forms.csproj | 1 + .../src/System/Windows/Forms/Cursor.cs | 7 +- .../src/System/Windows/Forms/Screen.cs | 2 +- .../System/Windows/Forms/SystemInformation.cs | 468 +++++++----------- .../src/System/Windows/Forms/TrackBar.cs | 2 +- 8 files changed, 314 insertions(+), 391 deletions(-) create mode 100644 src/Common/src/Interop/User32/Interop.GetSystemMetrics.cs diff --git a/src/Common/src/Interop/User32/Interop.GetSystemMetrics.cs b/src/Common/src/Interop/User32/Interop.GetSystemMetrics.cs new file mode 100644 index 00000000000..8493a2bf6eb --- /dev/null +++ b/src/Common/src/Interop/User32/Interop.GetSystemMetrics.cs @@ -0,0 +1,120 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; +using System.Windows.Forms; + +internal static partial class Interop +{ + internal static partial class User32 + { + public enum SystemMetric + { + SM_CXSCREEN = 0, + SM_CYSCREEN = 1, + SM_CXVSCROLL = 2, + SM_CYHSCROLL = 3, + SM_CYCAPTION = 4, + SM_CXBORDER = 5, + SM_CYBORDER = 6, + SM_CXFIXEDFRAME = 7, + SM_CYFIXEDFRAME = 8, + SM_CYVTHUMB = 9, + SM_CXHTHUMB = 10, + SM_CXICON = 11, + SM_CYICON = 12, + SM_CXCURSOR = 13, + SM_CYCURSOR = 14, + SM_CYMENU = 15, + SM_CYKANJIWINDOW = 18, + SM_MOUSEPRESENT = 19, + SM_CYVSCROLL = 20, + SM_CXHSCROLL = 21, + SM_DEBUG = 22, + SM_SWAPBUTTON = 23, + SM_CXMIN = 28, + SM_CYMIN = 29, + SM_CXSIZE = 30, + SM_CYSIZE = 31, + SM_CXFRAME = 32, + SM_CYFRAME = 33, + SM_CXMINTRACK = 34, + SM_CYMINTRACK = 35, + SM_CXDOUBLECLK = 36, + SM_CYDOUBLECLK = 37, + SM_CXICONSPACING = 38, + SM_CYICONSPACING = 39, + SM_MENUDROPALIGNMENT = 40, + SM_PENWINDOWS = 41, + SM_DBCSENABLED = 42, + SM_CMOUSEBUTTONS = 43, + SM_SECURE = 44, + SM_CXEDGE = 45, + SM_CYEDGE = 46, + SM_CXMINSPACING = 47, + SM_CYMINSPACING = 48, + SM_CXSMICON = 49, + SM_CYSMICON = 50, + SM_CYSMCAPTION = 51, + SM_CXSMSIZE = 52, + SM_CYSMSIZE = 53, + SM_CXMENUSIZE = 54, + SM_CYMENUSIZE = 55, + SM_ARRANGE = 56, + SM_CXMINIMIZED = 57, + SM_CYMINIMIZED = 58, + SM_CXMAXTRACK = 59, + SM_CYMAXTRACK = 60, + SM_CXMAXIMIZED = 61, + SM_CYMAXIMIZED = 62, + SM_NETWORK = 63, + SM_CLEANBOOT = 67, + SM_CXDRAG = 68, + SM_CYDRAG = 69, + SM_SHOWSOUNDS = 70, + SM_CXMENUCHECK = 71, + SM_CYMENUCHECK = 72, + SM_MIDEASTENABLED = 74, + SM_MOUSEWHEELPRESENT = 75, + SM_XVIRTUALSCREEN = 76, + SM_YVIRTUALSCREEN = 77, + SM_CXVIRTUALSCREEN = 78, + SM_CYVIRTUALSCREEN = 79, + SM_CMONITORS = 80, + SM_SAMEDISPLAYFORMAT = 81, + SM_CYFOCUSBORDER = 84, + SM_CXFOCUSBORDER = 83, + SM_REMOTESESSION = 0x1000, + SM_CXSIZEFRAME = SM_CXFRAME, + SM_CYSIZEFRAME = SM_CYFRAME + } + + [DllImport(Libraries.User32, ExactSpelling = true)] + public static extern int GetSystemMetrics(SystemMetric nIndex); + + [DllImport(Libraries.User32, ExactSpelling = true)] + private static extern int GetSystemMetricsForDpi(SystemMetric nIndex, uint dpi); + + /// + /// Tries to get system metrics for the dpi. dpi is ignored if "GetSystemMetricsForDpi" is not available on the OS that this application is running. + /// + /// index + /// dpi requested + /// returns system metrics for dpi + public static int GetCurrentSystemMetrics(SystemMetric nIndex, uint dpi) + { + if (OsVersion.IsWindows10_1607OrGreater) + { + return GetSystemMetricsForDpi(nIndex, dpi); + } + else + { + Debug.Fail("GetSystemMetricsForDpi() is not available on this OS"); + return GetSystemMetrics(nIndex); + } + } + } +} diff --git a/src/Common/src/NativeMethods.cs b/src/Common/src/NativeMethods.cs index 1565d4babd0..da7ffe5b075 100644 --- a/src/Common/src/NativeMethods.cs +++ b/src/Common/src/NativeMethods.cs @@ -1231,80 +1231,7 @@ public static int MAKELCID(int lgid, int sort) SWP_SHOWWINDOW = 0x0040, SWP_HIDEWINDOW = 0x0080, SWP_DRAWFRAME = 0x0020, - SWP_NOOWNERZORDER = 0x0200, - SM_CXSCREEN = 0, - SM_CYSCREEN = 1, - SM_CXVSCROLL = 2, - SM_CYHSCROLL = 3, - SM_CYCAPTION = 4, - SM_CXBORDER = 5, - SM_CYBORDER = 6, - SM_CYVTHUMB = 9, - SM_CXHTHUMB = 10, - SM_CXICON = 11, - SM_CYICON = 12, - SM_CXCURSOR = 13, - SM_CYCURSOR = 14, - SM_CYMENU = 15, - SM_CYKANJIWINDOW = 18, - SM_MOUSEPRESENT = 19, - SM_CYVSCROLL = 20, - SM_CXHSCROLL = 21, - SM_DEBUG = 22, - SM_SWAPBUTTON = 23, - SM_CXMIN = 28, - SM_CYMIN = 29, - SM_CXSIZE = 30, - SM_CYSIZE = 31, - SM_CXFRAME = 32, - SM_CYFRAME = 33, - SM_CXMINTRACK = 34, - SM_CYMINTRACK = 35, - SM_CXDOUBLECLK = 36, - SM_CYDOUBLECLK = 37, - SM_CXICONSPACING = 38, - SM_CYICONSPACING = 39, - SM_MENUDROPALIGNMENT = 40, - SM_PENWINDOWS = 41, - SM_DBCSENABLED = 42, - SM_CMOUSEBUTTONS = 43, - SM_CXFIXEDFRAME = 7, - SM_CYFIXEDFRAME = 8, - SM_SECURE = 44, - SM_CXEDGE = 45, - SM_CYEDGE = 46, - SM_CXMINSPACING = 47, - SM_CYMINSPACING = 48, - SM_CXSMICON = 49, - SM_CYSMICON = 50, - SM_CYSMCAPTION = 51, - SM_CXSMSIZE = 52, - SM_CYSMSIZE = 53, - SM_CXMENUSIZE = 54, - SM_CYMENUSIZE = 55, - SM_ARRANGE = 56, - SM_CXMINIMIZED = 57, - SM_CYMINIMIZED = 58, - SM_CXMAXTRACK = 59, - SM_CYMAXTRACK = 60, - SM_CXMAXIMIZED = 61, - SM_CYMAXIMIZED = 62, - SM_NETWORK = 63, - SM_CLEANBOOT = 67, - SM_CXDRAG = 68, - SM_CYDRAG = 69, - SM_SHOWSOUNDS = 70, - SM_CXMENUCHECK = 71, - SM_CYMENUCHECK = 72, - SM_MIDEASTENABLED = 74, - SM_MOUSEWHEELPRESENT = 75, - SM_XVIRTUALSCREEN = 76, - SM_YVIRTUALSCREEN = 77, - SM_CXVIRTUALSCREEN = 78, - SM_CYVIRTUALSCREEN = 79, - SM_CMONITORS = 80, - SM_SAMEDISPLAYFORMAT = 81, - SM_REMOTESESSION = 0x1000; + SWP_NOOWNERZORDER = 0x0200; public const int HLP_FILE = 1, HLP_KEYWORD = 2, @@ -1370,10 +1297,6 @@ public static int MAKELCID(int lgid, int sort) SPI_GETANIMATION = 0x0048, SPI_GETBORDER = 0x0005, SPI_GETCARETWIDTH = 0x2006, - SM_CYFOCUSBORDER = 84, - SM_CXFOCUSBORDER = 83, - SM_CYSIZEFRAME = SM_CYFRAME, - SM_CXSIZEFRAME = SM_CXFRAME, SPI_GETDRAGFULLWINDOWS = 38, SPI_GETNONCLIENTMETRICS = 41, SPI_GETWORKAREA = 48, diff --git a/src/Common/src/UnsafeNativeMethods.cs b/src/Common/src/UnsafeNativeMethods.cs index 131bfb9f096..3f59879d8ba 100644 --- a/src/Common/src/UnsafeNativeMethods.cs +++ b/src/Common/src/UnsafeNativeMethods.cs @@ -676,35 +676,9 @@ public static extern IntPtr CallWindowProc(IntPtr wndProc, IntPtr hWnd, int msg, [DllImport(ExternDll.User32, CharSet = CharSet.Unicode, ExactSpelling = true)] public static extern bool GetClassInfoW(HandleRef hInstance, string lpClassName, ref NativeMethods.WNDCLASS lpWndClass); - [DllImport(ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)] - public static extern int GetSystemMetrics(int nIndex); - - // This API is available starting Windows10 RS1 - [DllImport(ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)] - public static extern int GetSystemMetricsForDpi(int nIndex, uint dpi); - [DllImport(ExternDll.Gdi32, CharSet = CharSet.Auto)] public static extern bool GetTextMetrics(HandleRef hdc, NativeMethods.TEXTMETRIC tm); - /// - /// Tries to get system metrics for the dpi. dpi is ignored if "GetSystemMetricsForDpi" is not available on the OS that this application is running. - /// - /// index - /// dpi requested - /// returns system metrics for dpi - public static int TryGetSystemMetricsForDpi(int nIndex, uint dpi) - { - if (OsVersion.IsWindows10_1607OrGreater) - { - return GetSystemMetricsForDpi(nIndex, dpi); - } - else - { - Debug.Assert(false, "GetSystemMetricsForDpi() is not available on this OS"); - return GetSystemMetrics(nIndex); - } - } - [DllImport(ExternDll.User32, CharSet = CharSet.Unicode, ExactSpelling = true)] private unsafe static extern bool SystemParametersInfoW(uint uiAction, uint uiParam, void* pvParam, uint fWinIni); diff --git a/src/System.Windows.Forms/src/System.Windows.Forms.csproj b/src/System.Windows.Forms/src/System.Windows.Forms.csproj index f665c685902..a19bdfa813c 100644 --- a/src/System.Windows.Forms/src/System.Windows.Forms.csproj +++ b/src/System.Windows.Forms/src/System.Windows.Forms.csproj @@ -74,6 +74,7 @@ + diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Cursor.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Cursor.cs index 71020007e67..31a6e1cdbf1 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Cursor.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Cursor.cs @@ -289,11 +289,10 @@ public Size Size if (cursorSize.IsEmpty) { cursorSize = new Size( - UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXCURSOR), - UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYCURSOR) - ); - + Interop.User32.GetSystemMetrics(Interop.User32.SystemMetric.SM_CXCURSOR), + Interop.User32.GetSystemMetrics(Interop.User32.SystemMetric.SM_CYCURSOR)); } + return cursorSize; } } diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Screen.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Screen.cs index 868801f39c2..d939487be23 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Screen.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Screen.cs @@ -53,7 +53,7 @@ public class Screen private const int MONITOR_DEFAULTTONEAREST = 0x00000002; private const int MONITORINFOF_PRIMARY = 0x00000001; - private static readonly bool multiMonitorSupport = (UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CMONITORS) != 0); + private static readonly bool multiMonitorSupport = (Interop.User32.GetSystemMetrics(Interop.User32.SystemMetric.SM_CMONITORS) != 0); private static Screen[] screens; internal Screen(IntPtr monitor) : this(monitor, IntPtr.Zero) diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/SystemInformation.cs b/src/System.Windows.Forms/src/System/Windows/Forms/SystemInformation.cs index a4b8f65aedd..2ba96392498 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/SystemInformation.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/SystemInformation.cs @@ -7,15 +7,15 @@ using System.Runtime.InteropServices; using System.Text; using Microsoft.Win32; +using static Interop.User32; namespace System.Windows.Forms { /// - /// Provides information about the operating system. + /// Provides information about the operating system. /// public static class SystemInformation { - // Figure out if all the multimon stuff is supported on the OS private static bool s_checkMultiMonitorSupport; private static bool s_multiMonitorSupport; private static bool s_highContrast; @@ -36,7 +36,7 @@ public static bool DragFullWindows => UnsafeNativeMethods.SystemParametersInfoBool(NativeMethods.SPI_GETDRAGFULLWINDOWS); /// - /// Gets a value indicating whether the user has selected to run in high contrast. + /// Gets a value indicating whether the user has selected to run in high contrast. /// public static bool HighContrast { @@ -67,140 +67,123 @@ public static int MouseWheelScrollLines /// Gets the dimensions of the primary display monitor in pixels. /// public static Size PrimaryMonitorSize - => new Size( - UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXSCREEN), - UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYSCREEN)); + => new Size(GetSystemMetrics(SystemMetric.SM_CXSCREEN), + GetSystemMetrics(SystemMetric.SM_CYSCREEN)); /// - /// Gets the width of the vertical scroll bar in pixels. + /// Gets the width of the vertical scroll bar in pixels. /// public static int VerticalScrollBarWidth { - get => UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXVSCROLL); + get => GetSystemMetrics(SystemMetric.SM_CXVSCROLL); } /// - /// Gets the width of the vertical scroll bar in pixels. + /// Gets the width of the vertical scroll bar in pixels. /// public static int GetVerticalScrollBarWidthForDpi(int dpi) { if (DpiHelper.IsPerMonitorV2Awareness) { - return UnsafeNativeMethods.TryGetSystemMetricsForDpi(NativeMethods.SM_CXVSCROLL, (uint)dpi); - } - else - { - return UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXVSCROLL); + return GetCurrentSystemMetrics(SystemMetric.SM_CXVSCROLL, (uint)dpi); } + + return GetSystemMetrics(SystemMetric.SM_CXVSCROLL); } /// - /// Gets the height of the horizontal scroll bar in pixels. + /// Gets the height of the horizontal scroll bar in pixels. /// - public static int HorizontalScrollBarHeight - { - get => UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYHSCROLL); - } + public static int HorizontalScrollBarHeight => GetSystemMetrics(SystemMetric.SM_CYHSCROLL); /// - /// Gets the height of the horizontal scroll bar in pixels. + /// Gets the height of the horizontal scroll bar in pixels. /// public static int GetHorizontalScrollBarHeightForDpi(int dpi) { if (DpiHelper.IsPerMonitorV2Awareness) { - return UnsafeNativeMethods.TryGetSystemMetricsForDpi(NativeMethods.SM_CYHSCROLL, (uint)dpi); - } - else - { - return UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYHSCROLL); + return GetCurrentSystemMetrics(SystemMetric.SM_CYHSCROLL, (uint)dpi); } + + return GetSystemMetrics(SystemMetric.SM_CYHSCROLL); } /// - /// Gets the height of the normal caption area of a window in pixels. + /// Gets the height of the normal caption area of a window in pixels. /// public static int CaptionHeight { - get => UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYCAPTION); + get => GetSystemMetrics(SystemMetric.SM_CYCAPTION); } /// - /// Gets the width and height of a window border in pixels. + /// Gets the width and height of a window border in pixels. /// public static Size BorderSize { - get => new Size(UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXBORDER), - UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYBORDER)); + get => new Size(GetSystemMetrics(SystemMetric.SM_CXBORDER), + GetSystemMetrics(SystemMetric.SM_CYBORDER)); } /// - /// Gets the width andheight of a window border in pixels. + /// Gets the width andheight of a window border in pixels. /// public static Size GetBorderSizeForDpi(int dpi) { if (DpiHelper.IsPerMonitorV2Awareness) { - return new Size(UnsafeNativeMethods.TryGetSystemMetricsForDpi(NativeMethods.SM_CXBORDER, (uint)dpi), - UnsafeNativeMethods.TryGetSystemMetricsForDpi(NativeMethods.SM_CYBORDER, (uint)dpi)); - } - else - { - return BorderSize; + return new Size(GetCurrentSystemMetrics(SystemMetric.SM_CXBORDER, (uint)dpi), + GetCurrentSystemMetrics(SystemMetric.SM_CYBORDER, (uint)dpi)); } + + return BorderSize; } /// - /// Gets the thickness in pixels, of the border for a window that has a caption - /// and is not resizable. + /// Gets the thickness in pixels, of the border for a window that has a caption and is not resizable. /// public static Size FixedFrameBorderSize { - get => new Size(UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXFIXEDFRAME), - UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYFIXEDFRAME)); + get => new Size(GetSystemMetrics(SystemMetric.SM_CXFIXEDFRAME), + GetSystemMetrics(SystemMetric.SM_CYFIXEDFRAME)); } /// - /// Gets the height of the scroll box in a vertical scroll bar in pixels. + /// Gets the height of the scroll box in a vertical scroll bar in pixels. /// - public static int VerticalScrollBarThumbHeight - { - get => UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYVTHUMB); - } + public static int VerticalScrollBarThumbHeight => GetSystemMetrics(SystemMetric.SM_CYVTHUMB); /// - /// Gets the width of the scroll box in a horizontal scroll bar in pixels. + /// Gets the width of the scroll box in a horizontal scroll bar in pixels. /// - public static int HorizontalScrollBarThumbWidth - { - get => UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXHTHUMB); - } + public static int HorizontalScrollBarThumbWidth => GetSystemMetrics(SystemMetric.SM_CXHTHUMB); /// - /// Gets the default dimensions of an icon in pixels. + /// Gets the default dimensions of an icon in pixels. /// public static Size IconSize { - get => new Size(UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXICON), - UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYICON)); + get => new Size(GetSystemMetrics(SystemMetric.SM_CXICON), + GetSystemMetrics(SystemMetric.SM_CYICON)); } /// - /// Gets the dimensions of a cursor in pixels. + /// Gets the dimensions of a cursor in pixels. /// public static Size CursorSize { - get => new Size(UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXCURSOR), - UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYCURSOR)); + get => new Size(GetSystemMetrics(SystemMetric.SM_CXCURSOR), + GetSystemMetrics(SystemMetric.SM_CYCURSOR)); } /// - /// Gets the system's font for menus. + /// Gets the system's font for menus. /// public static Font MenuFont => GetMenuFontHelper(0, useDpi: false); /// - /// Gets the system's font for menus, scaled accordingly to an arbitrary DPI you provide. + /// Gets the system's font for menus, scaled accordingly to an arbitrary DPI you provide. /// public static Font GetMenuFontForDpi(int dpi) { @@ -236,23 +219,17 @@ private unsafe static Font GetMenuFontHelper(uint dpi, bool useDpi) } /// - /// Gets the height of a one line of a menu in pixels. + /// Gets the height of a one line of a menu in pixels. /// - public static int MenuHeight - { - get => UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYMENU); - } + public static int MenuHeight => GetSystemMetrics(SystemMetric.SM_CYMENU); /// - /// Returns the current system power status. + /// Returns the current system power status. /// - public static PowerStatus PowerStatus - { - get => s_powerStatus ?? (s_powerStatus = new PowerStatus()); - } + public static PowerStatus PowerStatus => s_powerStatus ??= new PowerStatus(); /// - /// Gets the size of the working area in pixels. + /// Gets the size of the working area in pixels. /// public static Rectangle WorkingArea { @@ -265,352 +242,297 @@ public static Rectangle WorkingArea } /// - /// Gets the height, in pixels, of the Kanji window at the bottom of the screen - /// for double-byte (DBCS) character set versions of Windows. + /// Gets the height, in pixels, of the Kanji window at the bottom of the screen + /// for double-byte (DBCS) character set versions of Windows. /// - public static int KanjiWindowHeight - { - get => UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYKANJIWINDOW); - } + public static int KanjiWindowHeight => GetSystemMetrics(SystemMetric.SM_CYKANJIWINDOW); /// - /// Gets a value indicating whether the system has a mouse installed. + /// Gets a value indicating whether the system has a mouse installed. /// [EditorBrowsable(EditorBrowsableState.Never)] - public static bool MousePresent - { - get => UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_MOUSEPRESENT) != 0; - } + public static bool MousePresent => GetSystemMetrics(SystemMetric.SM_MOUSEPRESENT) != 0; /// - /// Gets the height in pixels, of the arrow bitmap on the vertical scroll bar. + /// Gets the height in pixels, of the arrow bitmap on the vertical scroll bar. /// - public static int VerticalScrollBarArrowHeight - { - get => UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYVSCROLL); - } + public static int VerticalScrollBarArrowHeight => GetSystemMetrics(SystemMetric.SM_CYVSCROLL); /// - /// Gets the height of the vertical scroll bar arrow bitmap in pixels. + /// Gets the height of the vertical scroll bar arrow bitmap in pixels. /// public static int VerticalScrollBarArrowHeightForDpi(int dpi) { - return UnsafeNativeMethods.TryGetSystemMetricsForDpi(NativeMethods.SM_CYVSCROLL, (uint)dpi); + return GetCurrentSystemMetrics(SystemMetric.SM_CYVSCROLL, (uint)dpi); } /// - /// Gets the width, in pixels, of the arrow bitmap on the horizontal scrollbar. + /// Gets the width, in pixels, of the arrow bitmap on the horizontal scrollbar. /// - public static int HorizontalScrollBarArrowWidth - { - get => UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXHSCROLL); - } + public static int HorizontalScrollBarArrowWidth =>GetSystemMetrics(SystemMetric.SM_CXHSCROLL); /// - /// Gets the width of the horizontal scroll bar arrow bitmap in pixels. + /// Gets the width of the horizontal scroll bar arrow bitmap in pixels. /// public static int GetHorizontalScrollBarArrowWidthForDpi(int dpi) { if (DpiHelper.IsPerMonitorV2Awareness) { - return UnsafeNativeMethods.TryGetSystemMetricsForDpi(NativeMethods.SM_CXHSCROLL, (uint)dpi); - } - else - { - return UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXHSCROLL); + return GetCurrentSystemMetrics(SystemMetric.SM_CXHSCROLL, (uint)dpi); } + + return GetSystemMetrics(SystemMetric.SM_CXHSCROLL); } /// - /// Gets a value indicating whether this is a debug version of the operating system. + /// Gets a value indicating whether this is a debug version of the operating system. /// - public static bool DebugOS - { - get => UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_DEBUG) != 0; - } + public static bool DebugOS => GetSystemMetrics(SystemMetric.SM_DEBUG) != 0; /// - /// Gets a value indicating whether the functions of the left and right mouse - /// buttons have been swapped. + /// Gets a value indicating whether the functions of the left and right mouse + /// buttons have been swapped. /// - public static bool MouseButtonsSwapped - { - get => (UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_SWAPBUTTON) != 0); - } + public static bool MouseButtonsSwapped => (GetSystemMetrics(SystemMetric.SM_SWAPBUTTON) != 0); /// - /// Gets the minimum allowable dimensions of a window in pixels. + /// Gets the minimum allowable dimensions of a window in pixels. /// public static Size MinimumWindowSize { - get => new Size(UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXMIN), - UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYMIN)); + get => new Size(GetSystemMetrics(SystemMetric.SM_CXMIN), + GetSystemMetrics(SystemMetric.SM_CYMIN)); } /// - /// Gets the dimensions in pixels, of a caption bar or title bar button. + /// Gets the dimensions in pixels, of a caption bar or title bar button. /// public static Size CaptionButtonSize { - get => new Size(UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXSIZE), - UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYSIZE)); + get => new Size(GetSystemMetrics(SystemMetric.SM_CXSIZE), + GetSystemMetrics(SystemMetric.SM_CYSIZE)); } /// - /// Gets the thickness in pixels, of the border for a window that can be resized. + /// Gets the thickness in pixels, of the border for a window that can be resized. /// public static Size FrameBorderSize { - get => new Size(UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXFRAME), - UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYFRAME)); + get => new Size(GetSystemMetrics(SystemMetric.SM_CXFRAME), + GetSystemMetrics(SystemMetric.SM_CYFRAME)); } /// - /// Gets the system's default minimum tracking dimensions of a window in pixels. + /// Gets the system's default minimum tracking dimensions of a window in pixels. /// public static Size MinWindowTrackSize { - get => new Size(UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXMINTRACK), - UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYMINTRACK)); + get => new Size(GetSystemMetrics(SystemMetric.SM_CXMINTRACK), + GetSystemMetrics(SystemMetric.SM_CYMINTRACK)); } /// - /// Gets the dimensions in pixels, of the area that the user must click within - /// for the system to consider the two clicks a double-click. The rectangle is - /// centered around the first click. + /// Gets the dimensions in pixels, of the area that the user must click within + /// for the system to consider the two clicks a double-click. The rectangle is + /// centered around the first click. /// public static Size DoubleClickSize { - get => new Size(UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXDOUBLECLK), - UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYDOUBLECLK)); + get => new Size(GetSystemMetrics(SystemMetric.SM_CXDOUBLECLK), + GetSystemMetrics(SystemMetric.SM_CYDOUBLECLK)); } /// - /// Gets the maximum number of milliseconds allowed between mouse clicks for a - /// double-click. + /// Gets the maximum number of milliseconds allowed between mouse clicks for a + /// double-click. /// public static int DoubleClickTime => SafeNativeMethods.GetDoubleClickTime(); /// - /// Gets the dimensions in pixels, of the grid used to arrange icons in a large - /// icon view. + /// Gets the dimensions in pixels, of the grid used to arrange icons in a large + /// icon view. /// public static Size IconSpacingSize { - get => new Size(UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXICONSPACING), - UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYICONSPACING)); + get => new Size(GetSystemMetrics(SystemMetric.SM_CXICONSPACING), + GetSystemMetrics(SystemMetric.SM_CYICONSPACING)); } /// - /// Gets a value indicating whether drop down menus should be right-aligned with - /// the corresponding menu bar item. + /// Gets a value indicating whether drop down menus should be right-aligned with the corresponding menu + /// bar item. /// - public static bool RightAlignedMenus - { - get => UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_MENUDROPALIGNMENT) != 0; - } + public static bool RightAlignedMenus => GetSystemMetrics(SystemMetric.SM_MENUDROPALIGNMENT) != 0; /// - /// Gets a value indicating whether the Microsoft Windows for Pen computing - /// extensions are installed. + /// Gets a value indicating whether the Microsoft Windows for Pen computing extensions are installed. /// - public static bool PenWindows - { - get => UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_PENWINDOWS) != 0; - } + public static bool PenWindows => GetSystemMetrics(SystemMetric.SM_PENWINDOWS) != 0; /// - /// Gets a value indicating whether the operating system is capable of handling - /// double-byte (DBCS) characters. + /// Gets a value indicating whether the operating system is capable of handling + /// double-byte (DBCS) characters. /// - public static bool DbcsEnabled - { - get => UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_DBCSENABLED) != 0; - } + public static bool DbcsEnabled => GetSystemMetrics(SystemMetric.SM_DBCSENABLED) != 0; /// - /// Gets the number of buttons on mouse. + /// Gets the number of buttons on mouse. /// - public static int MouseButtons - { - get => UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CMOUSEBUTTONS); - } + public static int MouseButtons => GetSystemMetrics(SystemMetric.SM_CMOUSEBUTTONS); /// - /// Gets a value indicating whether security is present on this operating system. + /// Gets a value indicating whether security is present on this operating system. /// - public static bool Secure - { - get => UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_SECURE) != 0; - } + public static bool Secure => GetSystemMetrics(SystemMetric.SM_SECURE) != 0; /// - /// Gets the dimensions in pixels, of a 3-D border. + /// Gets the dimensions in pixels, of a 3-D border. /// public static Size Border3DSize { - get => new Size(UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXEDGE), - UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYEDGE)); + get => new Size(GetSystemMetrics(SystemMetric.SM_CXEDGE), + GetSystemMetrics(SystemMetric.SM_CYEDGE)); } /// - /// Gets the dimensions in pixels, of the grid into which minimized windows will - /// be placed. + /// Gets the dimensions in pixels, of the grid into which minimized windows will + /// be placed. /// public static Size MinimizedWindowSpacingSize { - get => new Size(UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXMINSPACING), - UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYMINSPACING)); + get => new Size(GetSystemMetrics(SystemMetric.SM_CXMINSPACING), + GetSystemMetrics(SystemMetric.SM_CYMINSPACING)); } /// - /// Gets the recommended dimensions of a small icon in pixels. + /// Gets the recommended dimensions of a small icon in pixels. /// public static Size SmallIconSize { - get => new Size(UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXSMICON), - UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYSMICON)); + get => new Size(GetSystemMetrics(SystemMetric.SM_CXSMICON), + GetSystemMetrics(SystemMetric.SM_CYSMICON)); } /// - /// Gets the height of a small caption in pixels. + /// Gets the height of a small caption in pixels. /// - public static int ToolWindowCaptionHeight - { - get => UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYSMCAPTION); - } + public static int ToolWindowCaptionHeight => GetSystemMetrics(SystemMetric.SM_CYSMCAPTION); /// - /// Gets the dimensions of small caption buttons in pixels. + /// Gets the dimensions of small caption buttons in pixels. /// public static Size ToolWindowCaptionButtonSize { - get => new Size(UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXSMSIZE), - UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYSMSIZE)); + get => new Size(GetSystemMetrics(SystemMetric.SM_CXSMSIZE), + GetSystemMetrics(SystemMetric.SM_CYSMSIZE)); } /// - /// Gets the dimensions in pixels, of menu bar buttons. + /// Gets the dimensions in pixels, of menu bar buttons. /// public static Size MenuButtonSize { - get => new Size(UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXMENUSIZE), - UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYMENUSIZE)); + get => new Size(GetSystemMetrics(SystemMetric.SM_CXMENUSIZE), + GetSystemMetrics(SystemMetric.SM_CYMENUSIZE)); } /// - /// Gets flags specifying how the system arranges minimized windows. + /// Gets flags specifying how the system arranges minimized windows. /// public static ArrangeStartingPosition ArrangeStartingPosition { get { ArrangeStartingPosition mask = ArrangeStartingPosition.BottomLeft | ArrangeStartingPosition.BottomRight | ArrangeStartingPosition.Hide | ArrangeStartingPosition.TopLeft | ArrangeStartingPosition.TopRight; - int compoundValue = UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_ARRANGE); + int compoundValue = GetSystemMetrics(SystemMetric.SM_ARRANGE); return mask & (ArrangeStartingPosition)compoundValue; } } /// - /// Gets flags specifying how the system arranges minimized windows. + /// Gets flags specifying how the system arranges minimized windows. /// public static ArrangeDirection ArrangeDirection { get { ArrangeDirection mask = ArrangeDirection.Down | ArrangeDirection.Left | ArrangeDirection.Right | ArrangeDirection.Up; - int compoundValue = UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_ARRANGE); + int compoundValue = GetSystemMetrics(SystemMetric.SM_ARRANGE); return mask & (ArrangeDirection)compoundValue; } } /// - /// Gets the dimensions in pixels, of a normal minimized window. + /// Gets the dimensions in pixels, of a normal minimized window. /// public static Size MinimizedWindowSize { - get => new Size(UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXMINIMIZED), - UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYMINIMIZED)); + get => new Size(GetSystemMetrics(SystemMetric.SM_CXMINIMIZED), + GetSystemMetrics(SystemMetric.SM_CYMINIMIZED)); } /// - /// Gets the default maximum dimensions in pixels, of a window that has a - /// caption and sizing borders. + /// Gets the default maximum dimensions in pixels, of a window that has a + /// caption and sizing borders. /// public static Size MaxWindowTrackSize { - get => new Size(UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXMAXTRACK), - UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYMAXTRACK)); + get => new Size(GetSystemMetrics(SystemMetric.SM_CXMAXTRACK), + GetSystemMetrics(SystemMetric.SM_CYMAXTRACK)); } /// - /// Gets the default dimensions, in pixels, of a maximized top-left window on the - /// primary monitor. + /// Gets the default dimensions, in pixels, of a maximized top-left window on the + /// primary monitor. /// public static Size PrimaryMonitorMaximizedWindowSize { - get => new Size(UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXMAXIMIZED), - UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYMAXIMIZED)); + get => new Size(GetSystemMetrics(SystemMetric.SM_CXMAXIMIZED), + GetSystemMetrics(SystemMetric.SM_CYMAXIMIZED)); } /// - /// Gets a value indicating whether this computer is connected to a network. + /// Gets a value indicating whether this computer is connected to a network. /// - public static bool Network - { - get => (UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_NETWORK) & 0x00000001) != 0; - } + public static bool Network => (GetSystemMetrics(SystemMetric.SM_NETWORK) & 0x00000001) != 0; - public static bool TerminalServerSession - { - get => (UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_REMOTESESSION) & 0x00000001) != 0; - } + public static bool TerminalServerSession => (GetSystemMetrics(SystemMetric.SM_REMOTESESSION) & 0x00000001) != 0; /// - /// Gets a value that specifies how the system was started. + /// Gets a value that specifies how the system was started. /// - public static BootMode BootMode - { - get => (BootMode)UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CLEANBOOT); - } + public static BootMode BootMode => (BootMode)GetSystemMetrics(SystemMetric.SM_CLEANBOOT); /// - /// Gets the dimensions in pixels, of the rectangle that a drag operation must - /// extend to be considered a drag. The rectangle is centered on a drag point. + /// Gets the dimensions in pixels, of the rectangle that a drag operation must + /// extend to be considered a drag. The rectangle is centered on a drag point. /// public static Size DragSize { - get => new Size(UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXDRAG), - UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYDRAG)); + get => new Size(GetSystemMetrics(SystemMetric.SM_CXDRAG), + GetSystemMetrics(SystemMetric.SM_CYDRAG)); } /// - /// Gets a value indicating whether the user requires an application to present - /// information visually in situations where it would otherwise present the - /// information in audible form. + /// Gets a value indicating whether the user requires an application to present + /// information visually in situations where it would otherwise present the + /// information in audible form. /// - public static bool ShowSounds - { - get => UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_SHOWSOUNDS) != 0; - } + public static bool ShowSounds => GetSystemMetrics(SystemMetric.SM_SHOWSOUNDS) != 0; /// - /// Gets the dimensions of the default size of a menu checkmark in pixels. + /// Gets the dimensions of the default size of a menu checkmark in pixels. /// public static Size MenuCheckSize { - get => new Size(UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXMENUCHECK), - UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYMENUCHECK)); + get => new Size(GetSystemMetrics(SystemMetric.SM_CXMENUCHECK), + GetSystemMetrics(SystemMetric.SM_CYMENUCHECK)); } /// - /// Gets a value indicating whether the system is enabled for Hebrew and Arabic - /// languages. + /// Gets a value indicating whether the system is enabled for Hebrew and Arabic languages. /// - public static bool MidEastEnabled - { - get => UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_MIDEASTENABLED) != 0; - } + public static bool MidEastEnabled => GetSystemMetrics(SystemMetric.SM_MIDEASTENABLED) != 0; private static bool MultiMonitorSupport { @@ -618,7 +540,7 @@ private static bool MultiMonitorSupport { if (!s_checkMultiMonitorSupport) { - s_multiMonitorSupport = (UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CMONITORS) != 0); + s_multiMonitorSupport = (GetSystemMetrics(SystemMetric.SM_CMONITORS) != 0); s_checkMultiMonitorSupport = true; } @@ -630,19 +552,16 @@ private static bool MultiMonitorSupport /// Gets a value indicating whether a mouse with a mouse wheel is installed. /// /// - /// This was never really correct. All versions of Windows NT from 4.0 onward - /// supported the mouse wheel directly. This should have been a version check. - /// Rather than change it and risk breaking apps we'll keep it equivalent to - /// + /// This was never really correct. All versions of Windows NT from 4.0 onward supported the mouse wheel + /// directly. This should have been a version check. Rather than change it and risk breaking apps we'll + /// keep it equivalent to /// - public static bool NativeMouseWheelSupport - => UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_MOUSEWHEELPRESENT) != 0; + public static bool NativeMouseWheelSupport => GetSystemMetrics(SystemMetric.SM_MOUSEWHEELPRESENT) != 0; /// /// Gets a value indicating whether a mouse with a mouse wheel is installed. /// - public static bool MouseWheelPresent - => NativeMouseWheelSupport; + public static bool MouseWheelPresent => NativeMouseWheelSupport; /// /// Gets the bounds of the virtual screen. @@ -653,10 +572,10 @@ public static Rectangle VirtualScreen { if (MultiMonitorSupport) { - return new Rectangle(UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_XVIRTUALSCREEN), - UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_YVIRTUALSCREEN), - UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXVIRTUALSCREEN), - UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYVIRTUALSCREEN)); + return new Rectangle(GetSystemMetrics(SystemMetric.SM_XVIRTUALSCREEN), + GetSystemMetrics(SystemMetric.SM_YVIRTUALSCREEN), + GetSystemMetrics(SystemMetric.SM_CXVIRTUALSCREEN), + GetSystemMetrics(SystemMetric.SM_CYVIRTUALSCREEN)); } Size size = PrimaryMonitorSize; @@ -665,7 +584,7 @@ public static Rectangle VirtualScreen } /// - /// Gets the number of display monitors on the desktop. + /// Gets the number of display monitors on the desktop. /// public static int MonitorCount { @@ -673,7 +592,7 @@ public static int MonitorCount { if (MultiMonitorSupport) { - return UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CMONITORS); + return GetSystemMetrics(SystemMetric.SM_CMONITORS); } return 1; @@ -681,7 +600,7 @@ public static int MonitorCount } /// - /// Gets a value indicating whether all the display monitors have the same color format. + /// Gets a value indicating whether all the display monitors have the same color format. /// public static bool MonitorsSameDisplayFormat { @@ -689,7 +608,7 @@ public static bool MonitorsSameDisplayFormat { if (MultiMonitorSupport) { - return UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_SAMEDISPLAYFORMAT) != 0; + return GetSystemMetrics(SystemMetric.SM_SAMEDISPLAYFORMAT) != 0; } return true; @@ -697,7 +616,7 @@ public static bool MonitorsSameDisplayFormat } /// - /// Gets the computer name of the current system. + /// Gets the computer name of the current system. /// public static string ComputerName { @@ -710,13 +629,13 @@ public static string ComputerName } /// - /// Gets the user's domain name. + /// Gets the user's domain name. /// public static string UserDomainName => Environment.UserDomainName; /// - /// Gets a value indicating whether the current process is running in user - /// interactive mode. + /// Gets a value indicating whether the current process is running in user + /// interactive mode. /// public unsafe static bool UserInteractive { @@ -746,8 +665,8 @@ public unsafe static bool UserInteractive } /// - /// Gets the user name for the current thread, that is, the name of the user - /// currently logged onto the system. + /// Gets the user name for the current thread, that is, the name of the user currently logged onto + /// the system. /// public static string UserName { @@ -970,7 +889,7 @@ public static int BorderMultiplierFactor => UnsafeNativeMethods.SystemParametersInfoInt(NativeMethods.SPI_GETBORDER); /// - /// Indicates the caret blink time. + /// Indicates the caret blink time. /// public static int CaretBlinkTime { @@ -983,43 +902,30 @@ public static int CaretBlinkTime public static int CaretWidth => UnsafeNativeMethods.SystemParametersInfoInt(NativeMethods.SPI_GETCARETWIDTH); - public static int MouseWheelScrollDelta => NativeMethods.WHEEL_DELTA; /// - /// The width of the left and right edges of the focus rectangle. + /// The width of the left and right edges of the focus rectangle. /// - public static int VerticalFocusThickness - { - get => UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYFOCUSBORDER); - } + public static int VerticalFocusThickness => GetSystemMetrics(SystemMetric.SM_CYFOCUSBORDER); /// - /// The width of the top and bottom edges of the focus rectangle. + /// The width of the top and bottom edges of the focus rectangle. /// - public static int HorizontalFocusThickness - { - get => UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXFOCUSBORDER); - } + public static int HorizontalFocusThickness => GetSystemMetrics(SystemMetric.SM_CXFOCUSBORDER); /// - /// The height of the vertical sizing border around the perimeter of the window that can be resized. + /// The height of the vertical sizing border around the perimeter of the window that can be resized. /// - public static int VerticalResizeBorderThickness - { - get => UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYSIZEFRAME); - } + public static int VerticalResizeBorderThickness => GetSystemMetrics(SystemMetric.SM_CYSIZEFRAME); /// - /// The width of the horizontal sizing border around the perimeter of the window that can be resized. + /// The width of the horizontal sizing border around the perimeter of the window that can be resized. /// - public static int HorizontalResizeBorderThickness - { - get => UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXSIZEFRAME); - } + public static int HorizontalResizeBorderThickness => GetSystemMetrics(SystemMetric.SM_CXSIZEFRAME); /// - /// The orientation of the screen in degrees. + /// The orientation of the screen in degrees. /// public static ScreenOrientation ScreenOrientation { @@ -1092,10 +998,10 @@ public unsafe static Size MenuBarButtonSize } /// - /// Checks whether the current Winforms app is running on a secure desktop under a terminal - /// server session. This is the case when the TS session has been locked. - /// This method is useful when calling into GDI+ Graphics methods that modify the object's - /// state, these methods fail under a locked terminal session. + /// Checks whether the current Winforms app is running on a secure desktop under a terminal + /// server session. This is the case when the TS session has been locked. + /// This method is useful when calling into GDI+ Graphics methods that modify the object's + /// state, these methods fail under a locked terminal session. /// internal static bool InLockedTerminalSession() { diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/TrackBar.cs b/src/System.Windows.Forms/src/System/Windows/Forms/TrackBar.cs index 673b47636a4..3b3bc97ccc8 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/TrackBar.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/TrackBar.cs @@ -476,7 +476,7 @@ private int PreferredDimension { get { - int cyhscroll = UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYHSCROLL); + int cyhscroll = Interop.User32.GetSystemMetrics(Interop.User32.SystemMetric.SM_CYHSCROLL); // this is our preferred size //