From 134f0c395e98fc35b699635199e243e99ca72849 Mon Sep 17 00:00:00 2001 From: Scighost Date: Sat, 30 Dec 2023 23:39:29 +0800 Subject: [PATCH] handle WM_WTSSESSION_CHANGE message --- src/Starward/MyWindows/MainWindow.xaml.cs | 18 ++++++++++++++++++ src/Starward/Pages/MainPage.xaml.cs | 19 +------------------ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/Starward/MyWindows/MainWindow.xaml.cs b/src/Starward/MyWindows/MainWindow.xaml.cs index 6cf7a7e4d..b9ba77f51 100644 --- a/src/Starward/MyWindows/MainWindow.xaml.cs +++ b/src/Starward/MyWindows/MainWindow.xaml.cs @@ -10,6 +10,7 @@ using System.Diagnostics; using System.IO; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using Vanara.PInvoke; @@ -76,6 +77,7 @@ private void InitializeMainWindow() AdaptTitleBarButtonColorToActuallTheme(); SetDragRectangles(new RectInt32(0, 0, 100000, len)); AppWindow.SetIcon(Path.Combine(AppContext.BaseDirectory, @"Assets\logo.ico")); + WTSRegisterSessionNotification(WindowHandle, 0); if (AppWindow.Presenter is OverlappedPresenter presenter) { presenter.IsMaximizable = false; @@ -186,6 +188,19 @@ public override nint WindowSubclassProc(HWND hWnd, uint uMsg, nint wParam, nint return IntPtr.Zero; } } + if (uMsg == (uint)User32.WindowMessage.WM_WTSSESSION_CHANGE) + { + // WTS_SESSION_LOCK + if (wParam == 0x7) + { + mainPage?.PauseVideo(true); + } + // WTS_SESSION_UNLOCK + if (wParam == 0x8) + { + mainPage?.PlayVideo(true); + } + } return base.WindowSubclassProc(hWnd, uMsg, wParam, lParam, uIdSubclass, dwRefData); } @@ -229,6 +244,9 @@ public unsafe bool Handled + [LibraryImport("wtsapi32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + private static partial bool WTSRegisterSessionNotification(IntPtr hWnd, int dwFlags); } diff --git a/src/Starward/Pages/MainPage.xaml.cs b/src/Starward/Pages/MainPage.xaml.cs index f381cb556..e6b42eba9 100644 --- a/src/Starward/Pages/MainPage.xaml.cs +++ b/src/Starward/Pages/MainPage.xaml.cs @@ -81,7 +81,6 @@ public MainPage() private async void Page_Loaded(object sender, RoutedEventArgs e) { MainWindow.Current.KeyDown += MainPage_KeyDown; - WTSRegisterSessionNotification(MainWindow.Current.BridgeHandle, 0); InitializeNavigationViewPaneDisplayMode(); UpdateButtonEffect(); await UpdateBackgroundImageAsync(true); @@ -886,20 +885,6 @@ private void MainPage_KeyDown(object? sender, MainWindow.KeyDownEventArgs e) { return; } - // todo - if (e.uMsg == (uint)User32.WindowMessage.WM_WTSSESSION_CHANGE) - { - // WTS_SESSION_LOCK - if (e.wParam == 0x7) - { - PauseVideo(true); - } - // WTS_SESSION_UNLOCK - if (e.wParam == 0x8) - { - PlayVideo(true); - } - } if (e.wParam == (nint)User32.VK.VK_ESCAPE) { PauseVideo(); @@ -916,9 +901,7 @@ private void MainPage_KeyDown(object? sender, MainWindow.KeyDownEventArgs e) - [LibraryImport("wtsapi32.dll")] - [return: MarshalAs(UnmanagedType.Bool)] - private static partial bool WTSRegisterSessionNotification(IntPtr hWnd, int dwFlags); + }