/
githubmirror
/
PowerToys
Обзор
Документация
Войти
/
githubmirror
/
PowerToys
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/modules/ShortcutGuide/ShortcutGuide.Ui/Helpers/DisplayHelper.cs
49 строк
2 KB
Noraa Junker
Shortcut Guide V2 (#40834)
21 май 2026, 18:27
Не верифицирован
21 май 2026, 18:27
9699d8a
Код
Авторство
О чём код?
// Copyright (c) Microsoft Corporation // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using Windows.Foundation; using WinUIEx; namespace ShortcutGuide.Helpers { public static class DisplayHelper { /// <summary> /// Returns the display work area for the monitor that contains the specified window. /// </summary> /// <param name="hwnd">The window handle</param> /// <returns>A <see cref="Rect"/> element containing the display area</returns> public static Rect GetWorkAreaForDisplayWithWindow(nint hwnd) { var monitor = NativeMethods.MonitorFromWindow(hwnd, (int)NativeMethods.MonitorFromWindowDwFlags.MONITOR_DEFAULTTONEAREST); int foundIndex = -1; int currentIndex = 0; NativeMethods.EnumDisplayMonitors( nint.Zero, nint.Zero, (nint hMonitor, nint hdcMonitor, ref NativeMethods.RECT lprcMonitor, nint dwData) => { if (hMonitor == dwData) { foundIndex = currentIndex; return false; } currentIndex++; return true; }, monitor); var monitors = MonitorInfo.GetDisplayMonitors(); if (foundIndex < 0 || foundIndex >= monitors.Count) { foundIndex = 0; } return monitors[foundIndex].RectWork; } } }