private void window_event_triggered(uint pid) { if (IsDisposed || !this.IsHandleCreated) { return; } this.BeginInvoke(new MethodInvoker(() => { pid = WinEventHelper.GetForegroundWindowThreadProcessId(); SetProcessButtonActiveByProcessId(pid); })); }
private void process_button_removed(object sender, ControlEventArgs e) { if (IsDisposed || !this.IsHandleCreated) { return; } if (_buttonsContainer.Controls.Count != 0) { var pid = WinEventHelper.GetForegroundWindowThreadProcessId(); //Console.WriteLine(pid); this.BeginInvoke(new MethodInvoker(() => { SetProcessButtonActiveByProcessId(pid); })); } }
private void process_button_click(object sender, EventArgs e) { try { var processButton = sender as ProcessButton; if (processButton == null) { return; } processButton.Highlight(); WinEventHelper.BringProcessToFront(processButton.Process); } catch (Exception ex) { Console.WriteLine(ex); } }
public MainForm() { _runningTimer = new Stopwatch(); _runningTimer.Start(); this.Text = Resources.ApplicationName; InitializeComponent(); InitializeSettings(); _defaultFontFamily = FontFamily.GenericSansSerif; try { _defaultFontFamily = new FontFamily("Microsoft YaHei"); // use Microsoft YaHei if it is available } catch (Exception) { // ignore } _processMonitor = new ProcessMonitor(Resources.DragonNest_Exe_Name); _processMonitor.OnEventArrived += event_arrived; InitializeTitleBar(); _container = new FlowLayoutPanel() { AutoSize = true, AutoScroll = false, FlowDirection = FlowDirection.TopDown, WrapContents = false, Width = DefaultClientRectangleWidth, Padding = new Padding(0, this.TitleBar.Height, 0, 3), }; this.Controls.Add(_container); InitializeControls(_container); _processMonitor.StartMonitoring(); _winEvent = new WinEventHelper(); _winEvent.OnWindowForegroundChanged += window_event_triggered; _winEvent.OnWindowMinimizeStart += window_event_triggered; _winEvent.OnWindowMinimizeEnd += window_event_triggered; _keyboardEventHook = new KeyboardInputEventHelper(); _keyboardEventHook.KeyBoardKeyDownEvent += keyboard_key_down; this.ResizeEnd += resize_end; // hacky way to keep delegates alive GC.KeepAlive(_winEvent); GC.KeepAlive(_keyboardEventHook); // new version check Task.Factory.StartNew(NotifyIfNewVersionFound); #if DEBUG TitleBarLabel.Text += " DEBUG "; #endif }