Skip to content

Commit

Permalink
handle WM_WTSSESSION_CHANGE message
Browse files Browse the repository at this point in the history
  • Loading branch information
Scighost committed Dec 30, 2023
1 parent c7017fc commit 134f0c3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
18 changes: 18 additions & 0 deletions src/Starward/MyWindows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -229,6 +244,9 @@ public unsafe bool Handled



[LibraryImport("wtsapi32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static partial bool WTSRegisterSessionNotification(IntPtr hWnd, int dwFlags);


}
19 changes: 1 addition & 18 deletions src/Starward/Pages/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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);



}

0 comments on commit 134f0c3

Please sign in to comment.