C# 判断桌面是否处于屏保,监听解锁屏、登录和注销事件 您所在的位置:网站首页 如何解锁电脑控屏 C# 判断桌面是否处于屏保,监听解锁屏、登录和注销事件

C# 判断桌面是否处于屏保,监听解锁屏、登录和注销事件

2024-03-16 13:42| 来源: 网络整理| 查看: 265

判断桌面是否处于屏保,其他屏保操作可参考 (https://www.codeproject.com/Articles/17067/Controlling-The-Screen-Saver-With-C)

[DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern bool SystemParametersInfo( int uAction, int uParam, ref bool lpvParam, int flags); private const int SPI_GETSCREENSAVERRUNNING = 114; //获取是否处于屏保参数 /// /// 桌面是否处于屏保 /// /// public static bool IsScreenSaverRunning() { bool isRunning = false; SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, ref isRunning, 0); return isRunning; }

监听系统解锁屏、登录和注销事件

/// /// 当前登录的用户变化(登录、注销和解锁屏) /// class SessionSwitchClass { /// /// 解屏后执行的委托 /// public Action SessionUnlockAction { get; set; } /// /// 锁屏后执行的委托 /// public Action SessionLockAction { get; set; } public SessionSwitchClass() { SystemEvents.SessionSwitch += SystemEvents_SessionSwitch; } //析构,防止句柄泄漏 ~SessionSwitchClass() { //Do this during application close to avoid handle leak SystemEvents.SessionSwitch -= SystemEvents_SessionSwitch; } //当前登录的用户变化(登录、注销和解锁屏) private void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e) { switch (e.Reason) { //用户登录 case SessionSwitchReason.SessionLogon: BeginSessionUnlock(); break; //解锁屏 case SessionSwitchReason.SessionUnlock: BeginSessionUnlock(); break; //锁屏 case SessionSwitchReason.SessionLock: BeginSessionLock(); break; //注销 case SessionSwitchReason.SessionLogoff: break; } } /// /// 解屏、登录后执行 /// private void BeginSessionUnlock() { //解屏、登录后执行 } /// /// 锁屏后执行 /// private void BeginSessionLock() { //锁屏后执行 } }


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有