Beispiel #1
0
        private static void WinEventProc(IntPtr hook, SetWinEventHookEventType eventType, IntPtr window, int objectId, int childId, uint threadId, uint time)
        {
            try
            {
                if (eventType == SetWinEventHookEventType.EVENT_SYSTEM_FOREGROUND ||
                    eventType == SetWinEventHookEventType.EVENT_SYSTEM_MOVESIZEEND)
                {//焦点变化,窗口大小变化
                    var m = new OtherProgramChecker(_currentProcess).CheckMaximized();
                    RaiseMaximizedEvent(m);
                }

                if (eventType == SetWinEventHookEventType.EVENT_OBJECT_LOCATIONCHANGE)
                {//处理最大化操作
                    WINDOWPLACEMENT placment = new WINDOWPLACEMENT();
                    User32Wrapper.GetWindowPlacement(window, ref placment);
                    //string title = User32Wrapper.GetWindowText(window);
                    int pid = User32Wrapper.GetProcessId(window);
                    if (placment.showCmd == WINDOWPLACEMENTFlags.SW_HIDE)
                    {
                        return;
                    }

                    if (pid == _currentProcess.Id)
                    {
                        return;
                    }

                    if (placment.showCmd == WINDOWPLACEMENTFlags.SW_SHOWMAXIMIZED)
                    {
                        if (!maximizedPid.Contains(pid))
                        {
                            maximizedPid.Add(pid);
                            var m = new OtherProgramChecker(_currentProcess).CheckMaximized();
                            RaiseMaximizedEvent(m);
                        }
                    }

                    if (placment.showCmd == WINDOWPLACEMENTFlags.SW_SHOWNORMAL ||
                        placment.showCmd == WINDOWPLACEMENTFlags.SW_RESTORE ||
                        placment.showCmd == WINDOWPLACEMENTFlags.SW_SHOW ||
                        placment.showCmd == WINDOWPLACEMENTFlags.SW_SHOWMINIMIZED)
                    {
                        if (maximizedPid.Contains(pid))
                        {
                            maximizedPid.Remove(pid);
                            var m = new OtherProgramChecker(_currentProcess).CheckMaximized();
                            RaiseMaximizedEvent(m);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }
Beispiel #2
0
        private static void _timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            _timer.Stop();

            var m = new OtherProgramChecker(_currentProcess).CheckMaximized();

            RaiseMaximizedEvent(m);

            _timer.Start();
        }
        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (IsPaused)
            {
                PausedTime = PausedTime.Add(TimeSpan.FromMilliseconds(_timer.Interval));
                if (_taskbarIcon == null)
                {
                    _taskbarIcon = IoC.Get <TaskbarIcon>();
                    _sourceIcon  = _taskbarIcon.Icon;
                }
            }
            else
            {
                PausedTime = new TimeSpan();
                //游戏中,延迟
                if (IsDelaying)
                {
                    warned     = false;
                    IsDelaying = false;
                    ResetCountDown();
                }
                //正常运行中
                else if (!IsResting)
                {
                    //倒计时减1秒
                    Countdown        = Countdown.Subtract(new TimeSpan(0, 0, 1));
                    CountdownPercent = Countdown.TotalSeconds / Setting.App.AlarmInterval.TotalSeconds * 100;
                    //提前30秒警告一次
                    if (!warned && Countdown.TotalSeconds <= 30 && Countdown.TotalSeconds >= 20)
                    {
                        warned = true;
                        ////游戏中不播放警告声音
                        //bool isMaximized = new OtherProgramChecker(_currentPID, true).CheckMaximized();
                        //if (!isMaximized)
                        //还是加上提示,害怕突然说话过于惊悚
                        _eventAggregator.PublishOnUIThread(new PlayAudioEvent()
                        {
                            Source = @"Resources\Sounds\breakpre.mp3"
                        });
                    }
                    //判断休息
                    if (Countdown.TotalSeconds <= 0)
                    {
                        _timer.Stop();

                        bool isMaximized = new OtherProgramChecker(Process.GetCurrentProcess(), true).CheckMaximized();
                        //bool isMaximized = true;

                        if (isMaximized && Setting.Speech.Enable)
                        {
                            //正在全屏,语音提示
                            IsDelaying = true;
                            PlaySpeech();
                        }
                        else
                        {//没有全屏玩游戏,立即休息
                            IsResting = true;
                            _lastLockScreenViewModel = IoC.Get <LockScreenViewModel>();
                            Execute.OnUIThread(() =>
                            {
                                _windowManager.ShowWindow(_lastLockScreenViewModel);
                                _lastLockScreenViewModel.Deactivated += _lastLockScreenViewModel_Deactivated;
                            });
                            PlayRestingAudio(IsResting);
                        }

                        RestTimeCountdown = Setting.App.RestTime;

                        _timer.Start();
                    }
                }
                //休息中
                else
                {
                    warned                   = false;
                    RestTimeCountdown        = RestTimeCountdown.Subtract(new TimeSpan(0, 0, 1));
                    RestTimeCountdownPercent = RestTimeCountdown.TotalSeconds / Setting.App.RestTime.TotalSeconds * 100;
                    if (RestTimeCountdown.TotalSeconds <= 0)
                    {
                        //休息完毕
                        ResetCountDown();
                        PlayRestingAudio(IsResting);
                        _totalPlayTime = new TimeSpan();
                    }
                }
            }
        }