⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 syslocksensor.cs

📁 飞信的收发使用csharp进行开发
💻 CS
字号:
namespace Imps.Client.Pc.Sensor
{
    using Imps.Client.Pc;
    using Imps.Client.Utils;
    using Imps.Client.Utils.sensmon;
    using Imps.Common;
    using Microsoft.Win32;
    using System;
    using System.IO;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms;

    public class SysLockSensor : PresenceSensorBase, IDisposable
    {
        private static SysLockSensor _instance;
        private Imps.Client.Utils.sensmon.sensmon.sens_simple_notify_proc_type m_simple_event_proc;
        private static object syncObj = new object();

        private SysLockSensor(IFrameworkWindow iFwnd) : base(iFwnd)
        {
            OperatingSystem oSVersion = Environment.OSVersion;
            if (((oSVersion.Platform != PlatformID.Unix) && (oSVersion.Platform != PlatformID.WinCE)) && ((oSVersion.Version.Major <= 5) && ((oSVersion.Version.Major != 5) || (oSVersion.Version.Minor < 1))))
            {
                try
                {
                    this.m_simple_event_proc = new Imps.Client.Utils.sensmon.sensmon.sens_simple_notify_proc_type(this.on_event_simple);
                    Imps.Client.Utils.sensmon.sensmon.simple_subscribe(Imps.Client.Utils.sensmon.sensmon.event_id.sens_displaylock, this.m_simple_event_proc, IntPtr.Zero);
                    Imps.Client.Utils.sensmon.sensmon.simple_subscribe(Imps.Client.Utils.sensmon.sensmon.event_id.sens_displayunlock, this.m_simple_event_proc, IntPtr.Zero);
                }
                catch (Exception exception)
                {
                    ClientLogger.WriteException("Failed to subscribing Logon & Logoff events", exception);
                }
            }
        }

        public void Dispose()
        {
            try
            {
                if (this.m_simple_event_proc != null)
                {
                    Imps.Client.Utils.sensmon.sensmon.simple_unsubscribe(Imps.Client.Utils.sensmon.sensmon.event_id.sens_displaylock, this.m_simple_event_proc);
                    Imps.Client.Utils.sensmon.sensmon.simple_unsubscribe(Imps.Client.Utils.sensmon.sensmon.event_id.sens_displayunlock, this.m_simple_event_proc);
                }
            }
            catch (Exception exception)
            {
                ClientLogger.WriteException("Failed to unsubscribing Logon & Logoff events", exception);
            }
        }

        ~SysLockSensor()
        {
            this.Dispose();
        }

        public static SysLockSensor GetInstance(IFrameworkWindow ifwnd)
        {
            if (_instance == null)
            {
                lock (syncObj)
                {
                    if (_instance == null)
                    {
                        if (ifwnd == null)
                        {
                            throw new ArgumentNullException("ifwnd should not be null!");
                        }
                        _instance = new SysLockSensor(ifwnd);
                    }
                }
            }
            return _instance;
        }

        [MethodImpl(MethodImplOptions.NoInlining)]
        public void on_event_simple(Imps.Client.Utils.sensmon.sensmon.event_id id, IntPtr context)
        {
            try
            {
                if ((base.ImpsConfig.UserSetting.SensorSetting.AwayOnScreenSaver != null) && (id == Imps.Client.Utils.sensmon.sensmon.event_id.sens_displaylock))
                {
                    base.PresenseValue = MainPresence.Away;
                }
                else
                {
                    base.PresenseValue = MainPresence.Online;
                }
            }
            catch
            {
            }
        }

        public static void PrepareEnvironment()
        {
            try
            {
                RegistryKey key = RegistryHelper.OpenOrCreateSubKey(Registry.LocalMachine, @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Notify");
                if (key != null)
                {
                    try
                    {
                        key.DeleteSubKeyTree("ImpsSensor");
                    }
                    catch (Exception)
                    {
                    }
                    key.Close();
                }
                string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "ImpsSensor.dll");
                if (File.Exists(path))
                {
                    try
                    {
                        File.Delete(path);
                    }
                    catch (Exception)
                    {
                    }
                }
                OperatingSystem oSVersion = Environment.OSVersion;
                if ((((oSVersion.Platform != PlatformID.Unix) && (oSVersion.Platform != PlatformID.WinCE)) && ((oSVersion.Version.Major <= 5) && (oSVersion.Version.Major == 5))) && (oSVersion.Version.Minor >= 1))
                {
                }
            }
            catch (Exception exception)
            {
                ClientLogger.WriteException(exception);
            }
        }

        public void ProccessWndMsg(System.Windows.Forms.Message m, Imps.Client.Utils.sensmon.sensmon.sens_simple_notify_proc_type callback)
        {
            if (m.Msg == 0x2b1)
            {
                switch (m.WParam.ToInt32())
                {
                    case 7:
                        callback(Imps.Client.Utils.sensmon.sensmon.event_id.sens_displaylock, IntPtr.Zero);
                        return;

                    case 8:
                        callback(Imps.Client.Utils.sensmon.sensmon.event_id.sens_displayunlock, IntPtr.Zero);
                        return;

                    default:
                        return;
                }
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -