/// <summary> /// Executes Draw events. /// </summary> internal static void CallDrawEvents() { OnPreDraw?.Invoke(); foreach (var scene in Scenes) { if (scene.Visible) { CurrentScene = scene; scene.Draw(); } } OnPostDraw?.Invoke(); }
internal override void _window_PreDrawGraphics(object sender, DrawGraphicsEventArgs e) { if (!Loaded) { return; } if (!_windowLoaded) { return; } #region Attach try { if (_attachTargetName != "") { if (_attachTargetType == AttachTargetEnum.Process) { var foregroundWindowHandle = User32.GetForegroundWindow(); if (foregroundWindowHandle != _foregroundWindowHandle) { _foregroundWindowHandle = foregroundWindowHandle; User32.GetWindowThreadProcessId(_foregroundWindowHandle, ref _foregroundProcessId); var processes = Process.GetProcessesByName(_attachTargetName); if (processes.Length != 0) { _targetProcessId = processes.First().Id; if (_targetProcessId == _foregroundProcessId || _foregroundProcessId == _currentProcessId) { _targetWindowHandle = processes.First().MainWindowHandle; if (AttachToTargetMode == AttachToTargetModeEnum.Manual) { if (AttachEventsRaiseType == AttachEventsRaiseTypeEnum.ChangeTargetState && _targetState != TargetStateEnum.Foreground) { AttachEvent?.Invoke(TargetStateEnum.Foreground); } else if (AttachEventsRaiseType == AttachEventsRaiseTypeEnum.Always) { AttachEvent?.Invoke(TargetStateEnum.Foreground); } } _targetState = TargetStateEnum.Foreground; if (AttachToTargetMode == AttachToTargetModeEnum.Automatic) { if (ActionWhenTargetStateForeground == ActionWhenTargetStateChangeEnum.Exit) { Process.GetCurrentProcess().Kill(); //Поменять } if (ActionWhenTargetStateForeground == ActionWhenTargetStateChangeEnum.Show) { Window.Show(); Window.PlaceAbove(_targetWindowHandle); Window.FitTo(_targetWindowHandle, true); } if (ActionWhenTargetStateForeground == ActionWhenTargetStateChangeEnum.Hide) { Window.Hide(); } if (ActionWhenTargetStateForeground == ActionWhenTargetStateChangeEnum.OpacityChange) { Window.Show(); CurrentOpacity = OpacityWhenTargetStateForeground; Window.PlaceAbove(_targetWindowHandle); Window.FitTo(_targetWindowHandle, true); } else { CurrentOpacity = 1f; } } } else { if (AttachToTargetMode == AttachToTargetModeEnum.Manual) { if (AttachEventsRaiseType == AttachEventsRaiseTypeEnum.ChangeTargetState && _targetState != TargetStateEnum.Background) { AttachEvent?.Invoke(TargetStateEnum.Background); } else if (AttachEventsRaiseType == AttachEventsRaiseTypeEnum.Always) { AttachEvent?.Invoke(TargetStateEnum.Background); } } _targetState = TargetStateEnum.Background; if (AttachToTargetMode == AttachToTargetModeEnum.Automatic) { if (ActionWhenTargetStateBackground == ActionWhenTargetStateChangeEnum.Exit) { Process.GetCurrentProcess().Kill(); //Поменять } if (ActionWhenTargetStateBackground == ActionWhenTargetStateChangeEnum.Show) { Window.Show(); Window.PlaceAbove(_targetWindowHandle); Window.FitTo(_targetWindowHandle, true); } if (ActionWhenTargetStateBackground == ActionWhenTargetStateChangeEnum.Hide) { Window.Hide(); } if (ActionWhenTargetStateBackground == ActionWhenTargetStateChangeEnum.OpacityChange) { Window.Show(); CurrentOpacity = OpacityWhenTargetStateBackground; Window.PlaceAbove(_targetWindowHandle); Window.FitTo(_targetWindowHandle, true); } else { CurrentOpacity = 1f; } } } } else { if (AttachToTargetMode == AttachToTargetModeEnum.Manual) { if (AttachEventsRaiseType == AttachEventsRaiseTypeEnum.ChangeTargetState && _targetState != TargetStateEnum.None) { AttachEvent?.Invoke(TargetStateEnum.None); } else if (AttachEventsRaiseType == AttachEventsRaiseTypeEnum.Always) { AttachEvent?.Invoke(TargetStateEnum.None); } } _targetState = TargetStateEnum.None; if (AttachToTargetMode == AttachToTargetModeEnum.Manual) { if (ActionWhenTargetStateNone == ActionWhenTargetStateChangeEnum.Exit) { Process.GetCurrentProcess().Kill(); //Поменять } if (ActionWhenTargetStateNone == ActionWhenTargetStateChangeEnum.Show) { Window.Show(); Window.PlaceAbove(_targetWindowHandle); Window.FitTo(_targetWindowHandle, true); } if (ActionWhenTargetStateNone == ActionWhenTargetStateChangeEnum.Hide) { Window.Hide(); } if (ActionWhenTargetStateNone == ActionWhenTargetStateChangeEnum.OpacityChange) { Window.Show(); CurrentOpacity = OpacityWhenTargetStateNone; Window.PlaceAbove(_targetWindowHandle); Window.FitTo(_targetWindowHandle, true); } else { CurrentOpacity = 1f; } } //none } } else { //not change if (AttachToTargetMode == AttachToTargetModeEnum.Manual) { if (AttachEventsRaiseType == AttachEventsRaiseTypeEnum.Always) { AttachEvent?.Invoke(TargetStateEnum.None); } } if (AttachToTargetMode == AttachToTargetModeEnum.Automatic) { if (Window.IsVisible) { if (_targetWindowHandle != IntPtr.Zero) { Window.PlaceAbove(_targetWindowHandle); Window.FitTo(_targetWindowHandle, true); } } } } } if (_attachTargetType == AttachTargetEnum.Window) { } } } catch (Exception exception) { } //if (_attachTargetName != "") //{ // if (_attachTargetMode == AttachTarget.Process) // { // _foregroundWindowHandle = User32.GetForegroundWindow(); // User32.GetWindowThreadProcessId(_foregroundWindowHandle, out _foregroundProcessId); // var processes = Process.GetProcessesByName(_attachTargetName); // if (processes.Length != 0) // { // _targetProcessId = processes.First().Id; // if (_targetProcessId == _foregroundProcessId || _foregroundProcessId == _currentProcessId) // { // //if (HideOverlayWhenTargetWindowNoForeground) // //{ // if (!g.Window.IsVisible) // g.Window.Show(); // //} // //else // //{ // if (!g.Window.IsTopmost) // g.Window.MakeTopmost(); // //} // var targetProcessMainWindowHandle = processes.First().MainWindowHandle; // g.Window.PlaceAboveWindow(targetProcessMainWindowHandle); // if (_aspectRatio.CloseTo(0)) // g.Window.FitToWindow(targetProcessMainWindowHandle); // else // g.Window.FitToWindow(targetProcessMainWindowHandle, _aspectRatio); // } // else // { // if (HideOverlayWhenTargetWindowNoForeground) // { // if (g.Window.IsVisible) // g.Window.Hide(); // } // else // { // if (g.Window.IsTopmost) // g.Window.RemoveTopmost(); // } // } // } // else // { // _targetProcessId = -1; // if (WorkWithoutProcess) // { // if (g.Window.IsVisible) // g.Window.Hide(); // } // else // { // OnAppExit(); // g.Overlay.StopHook(); // g.Overlay.Window.Graphics.Dispose(); // Process.GetCurrentProcess().Kill(); // } // } // } // else if(_attachTargetMode == AttachTarget.ActiveWindowTitle) // { // _foregroundWindowTitle = User32.GetActiveWindowTitle(); // if (_foregroundWindowTitle != null) // { // if (_foregroundWindowTitle.Contains(_attachTargetName)) // { // if (!g.Window.IsVisible) // g.Window.Show(); // var targetProcessMainWindowHandle = User32.GetForegroundWindow(); // g.Window.PlaceAboveWindow(targetProcessMainWindowHandle); // g.Window.FitToWindow(targetProcessMainWindowHandle, _aspectRatio); // } // else // { // if (g.Window.IsVisible) // g.Window.Hide(); // } // } // } //} #endregion OnPreDraw?.Invoke(sender, e); }