/// <summary>
        /// Process windows messages
        /// </summary>
        protected override void WndProc(ref Message m)
        {
            MonitorEventArgs args = new MonitorEventArgs(Environment.UserName);
            WindowsMessages msg = (WindowsMessages)m.Msg;
            int wparam = m.WParam.ToInt32();
            int lparam = m.LParam.ToInt32();

            // check for session change notifications
            if (msg == WindowsMessages.WM_WTSSESSION_CHANGE) {
                log.Info("Get system message: Monitor session changed: wparam" + m.ToString());
                if (wparam == (int)WTS.WTS_SESSION_LOCK) {
                    manager.OnMonitorLocked(args);
                } else if (wparam == (int)WTS.WTS_SESSION_UNLOCK) {
                    manager.OnMonitorUnlocked(args);
                }
            } else if (msg == WindowsMessages.WM_SYSCOMMAND) {
                if (wparam == (int)SysCommands.SC_MONITORPOWER) {
                    log.Info("Get system message: Monitor Power. Lparam: " + m.ToString());
                    if (m.LParam.ToInt32() == Win32Helper.MONITOR_ON_PARAM)
                        manager.OnMonitorOpened(args);
                    else if (m.LParam.ToInt32() == Win32Helper.MONITOR_OFF_PARAM)
                        manager.OnMonitorShutdown(args);
                } else if (wparam == (int)SysCommands.SC_SCREENSAVE) {
                    log.Info("Get system message: Monitor PowerScreen Saver. " + m.ToString());
                }
            }

            log.Debug("messages: " + m.ToString());
            base.WndProc(ref m);
            return;
        }
 internal void OnScreenSaverStarted(MonitorEventArgs args)
 {
     log.Info("Notify ScreenSaverStarted: " + args.ToString());
     IsSreenSaverRuning = true;
     if (ScreenSaverStarted != null)
     {
         ScreenSaverStarted(this, args);
     }
 }
 internal void OnMonitorUnlocked(MonitorEventArgs args)
 {
     log.Info("Notify MonitorUnlocked: " + args.ToString());
     IsMonitorLocked = false;
     if (MonitorUnlocked != null)
     {
         MonitorUnlocked(this, args);
     }
 }
 internal void OnMonitorOpened(MonitorEventArgs args)
 {
     log.Info("Notify MonitorOpened: " + args.ToString());
     IsMonitorShutdown = false;
     if (MonitorOpened != null)
     {
         MonitorOpened(this, args);
     }
 }
 internal void OnMonitorShutdown(MonitorEventArgs args)
 {
     log.Info("Notify MonitorShutdown: " + args.ToString());
     IsMonitorShutdown = true;
     if (MonitorShutdown != null)
     {
         MonitorShutdown(this, args);
     }
 }
Beispiel #6
0
        /// <summary>
        /// Process windows messages
        /// </summary>
        protected override void WndProc(ref Message m)
        {
            MonitorEventArgs args = new MonitorEventArgs(Environment.UserName);
            WindowsMessages  msg  = (WindowsMessages)m.Msg;
            int wparam            = m.WParam.ToInt32();
            int lparam            = m.LParam.ToInt32();

            // check for session change notifications
            if (msg == WindowsMessages.WM_WTSSESSION_CHANGE)
            {
                log.Info("Get system message: Monitor session changed: wparam" + m.ToString());
                if (wparam == (int)WTS.WTS_SESSION_LOCK)
                {
                    manager.OnMonitorLocked(args);
                }
                else if (wparam == (int)WTS.WTS_SESSION_UNLOCK)
                {
                    manager.OnMonitorUnlocked(args);
                }
            }
            else if (msg == WindowsMessages.WM_SYSCOMMAND)
            {
                if (wparam == (int)SysCommands.SC_MONITORPOWER)
                {
                    log.Info("Get system message: Monitor Power. Lparam: " + m.ToString());
                    if (m.LParam.ToInt32() == Win32Helper.MONITOR_ON_PARAM)
                    {
                        manager.OnMonitorOpened(args);
                    }
                    else if (m.LParam.ToInt32() == Win32Helper.MONITOR_OFF_PARAM)
                    {
                        manager.OnMonitorShutdown(args);
                    }
                }
                else if (wparam == (int)SysCommands.SC_SCREENSAVE)
                {
                    log.Info("Get system message: Monitor PowerScreen Saver. " + m.ToString());
                }
            }

            log.Debug("messages: " + m.ToString());
            base.WndProc(ref m);
            return;
        }
 void monitor_MonitorUnlocked(object sender, MonitorEventArgs e)
 {
     log.Debug("Computer unlocked!");
     TimeSpan span = System.DateTime.Now - LockedTime;
     log.Debug("Locked Seconds : " + span.TotalSeconds);
     if (span.TotalSeconds >= BreakingSeconds) {
         CompleteBreaking();
     }
 }
 void monitor_MonitorLocked(object sender, MonitorEventArgs e)
 {
     log.Debug("Computer locked!");
     LockedTime = System.DateTime.Now;
 }