From 394c22a587822e6e90ea0c75bd3bbfc9dfcd70bd Mon Sep 17 00:00:00 2001 From: Ricardo Date: Mon, 27 Dec 2021 16:50:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=8F=8C=E5=B1=8F=E5=A4=8D?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Loaf/MainWindow.xaml.cs | 4 ++- Loaf/ScreenHelper.cs | 64 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 Loaf/ScreenHelper.cs diff --git a/Loaf/MainWindow.xaml.cs b/Loaf/MainWindow.xaml.cs index 4b81f1b..872f43b 100644 --- a/Loaf/MainWindow.xaml.cs +++ b/Loaf/MainWindow.xaml.cs @@ -80,8 +80,9 @@ public void Loaf() } Frame.Navigate(typeof(Windows11UpdateView)); + _appWindow.SetPresenter(AppWindowPresenterKind.FullScreen); - + ScreenHelper.SetScreenMode(1); while (ShowCursor(true) < 0) { ShowCursor(true); //显示光标 @@ -99,6 +100,7 @@ public void Unloaf() { _isLoafing = false; _appWindow.SetPresenter(AppWindowPresenterKind.Default); + ScreenHelper.SetScreenMode(2); var parent = VisualTreeHelper.GetParent(Root); while (parent != null) { diff --git a/Loaf/ScreenHelper.cs b/Loaf/ScreenHelper.cs new file mode 100644 index 0000000..67f7054 --- /dev/null +++ b/Loaf/ScreenHelper.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace Loaf +{ + public static class ScreenHelper + { + private const uint SDC_APPLY = 0x00000080; + + private const uint SDC_TOPOLOGY_INTERNAL = 0x00000001; + + private const uint SDC_TOPOLOGY_CLONE = 0x00000002; + + /// + /// 扩展模式 + /// + private const uint SDC_TOPOLOGY_EXTEND = 0x00000004; + + [DllImport("user32.dll", CharSet = CharSet.Unicode)] + private static extern long SetDisplayConfig(uint numPathArrayElements, IntPtr pathArray, uint numModeArrayElements, + IntPtr modeArray, uint flags); + /// + /// 设置屏幕的显示模式 + /// + /// + /// + private static bool SetScreen(uint displayModel) + { + return SetDisplayConfig(0, IntPtr.Zero, 0, IntPtr.Zero, SDC_APPLY | displayModel) == 0; + } + + /// + /// 设置屏幕的显示模式 + /// + /// 模式(0 - 主屏 1 - 双屏复制 2 - 双屏扩展 + /// + public static bool SetScreenMode(int type) + { + uint smode; + + switch (type) + { + case 0: + smode = SDC_APPLY | SDC_TOPOLOGY_INTERNAL; + break; + case 1: + smode = SDC_APPLY | SDC_TOPOLOGY_CLONE; + break; + case 2: + smode = SDC_APPLY | SDC_TOPOLOGY_EXTEND; + break; + default: + smode = SDC_APPLY | SDC_TOPOLOGY_INTERNAL; + break; + } + + return SetDisplayConfig(0, IntPtr.Zero, 0, IntPtr.Zero, smode) == 0; + } + } +}