[英]To catch the event of screen lock in Windows 10 (WPF)
Tell me what to do, I don't know where to look for the answer. 告诉我该怎么办,我不知道在哪里寻找答案。
I have a WPF application that works with the tablet's camera using AForge. 我有一个WPF应用程序,可使用AForge与平板电脑的相机配合使用。 When the user locks the system by keyboard shortcut "Win+L" - the camera is no longer in use (indicator is off), because I'm in control of this process through the event is given below. 当用户通过键盘快捷键“ Win + L”锁定系统时-不再使用摄像头(指示灯已关闭),因为通过下面的事件我可以控制该过程。
private void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
{
switch (e.Reason)
{
case SessionSwitchReason.SessionLock: StopCam(); break;
case SessionSwitchReason.SessionUnlock:
if (this.Window.WindowState != WindowState.Minimized)
{
StartCam();
}
break;
}
}
If the user push the button of lock of the screen (usually on top of the tablet), my camera does not turn off (indicator lit). 如果用户按屏幕锁定按钮(通常在平板电脑顶部),则我的相机不会关闭(指示灯点亮)。 How do I track this event? 如何跟踪此事件?
ps my WPF application will run on Windows 10 tablets. ps我的WPF应用程序将在Windows 10平板电脑上运行。
Maybe i have a solution. 也许我有解决方案。 This code works on PC but i didn't tested it on tablet (because i don't have one). 这段代码在PC上有效,但我没有在平板电脑上测试过(因为我没有一个)。 You need to add using System.Windows.Interop; 您需要使用System.Windows.Interop添加;
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
HwndSource source = PresentationSource.FromVisual(this) as HwndSource;
source.AddHook(WndProc);
}
private const int WM_SYSCOMMAND = 0x0112;
private const int SC_MONITORPOWER = 0xf170;
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (msg == WM_SYSCOMMAND)
{
if (wParam.ToInt32() == SC_MONITORPOWER)
{
switch (lParam.ToInt32())
{
case -1:
this.listBox1.Items.Add("display is powering on");
break;
case 2:
this.listBox1.Items.Add("display is being shut off");
break;
}
}
}
return IntPtr.Zero;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.