private void HandleWinEvent(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime) { Task.Run(() => { try { string winTitle = GetWindowText(hwnd); int processId = 0; GetWindowThreadProcessId(hwnd, out processId); //var flags = Kernel32.ProcessAccessFlags.QueryInformation | Kernel32.ProcessAccessFlags.VirtualMemoryRead; string executablePath; using (var hProc = OpenProcess(flags, false, processId)) { executablePath = QueryFullProcessImageName(hProc, 0); }; if (!appNameCache.ContainsKey(executablePath)) { var info = FileVersionInfo.GetVersionInfo(executablePath); appNameCache.Add(executablePath, info.FileDescription); } string appName = appNameCache[executablePath]; var ev = new Win32WindowRef { Handle = hwnd, ProcessID = processId, ExecutablePath = executablePath, Title = winTitle.ToString(), ApplicationName = appName }; IntPtr hMenu = GetMenu(hwnd); if (hMenu != null) { ev.Menu = new IWindowRef.MenuRef { Ref = hMenu, Items = GetMenuItems(hMenu), }; } WindowSelected?.Invoke(ev); } catch (Exception ex) { Debug.WriteLine("F**k: {0}", ex); } }); }
private void OnMouseUp(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Left) { return; } _mouseTarget.Cursor = Cursors.Default; if (_lastWindow == null) { return; } ControlPaint.DrawReversibleFrame(_lastWindow.WindowRect, Color.Black, FrameStyle.Thick); WindowSelected?.Invoke(this, new WindowHoverEventArgs(_lastWindow)); }
private void rightToonCrosshair_WindowSelected(object sender, IntPtr handle) { ControllerPair.RightController.WindowHandle = rightToonCrosshair.SelectedWindowHandle; WindowSelected?.Invoke(this, EventArgs.Empty); }
private void OnWindowSelected() { WindowSelected?.Invoke(this, EventArgs.Empty); }