private void picturePicker_MouseMove(object sender, MouseEventArgs e) { if (!Searching) { return; } var w = Winapi.WindowFromPoint(Cursor.Position); uint pid; Winapi.GetWindowThreadProcessId(w, out pid); if (pid == CurrentPid) { return; } var json = GetWidgetData(w, false); var rect = GetWidgetRect(json); if (LastWindow != w || LastRect != rect) { // unhilite old InvertLast(); LastWindow = w; LastRect = rect; // hilite new InvertLast(); // also update window title Text = TitlePrefix + string.Format(" [{0:X8}, {1}, {2}]", w, json.TryGet <string>("class"), json.TryGet <string>("text")); } }
public static QtProcess FromWindow(IntPtr w) { uint pid; Winapi.GetWindowThreadProcessId(w, out pid); if (nonQtProcesses.Contains(pid)) { return(null); } if (qtProcesses.ContainsKey(pid)) { return(qtProcesses[pid]); } try { var proc = Process.GetProcessById((int)pid); foreach (var m in proc.Modules.Cast <ProcessModule>().Where( m => m.ModuleName.Equals("QtGui4.dll", StringComparison.InvariantCultureIgnoreCase))) { var qproc = new QtProcess { Process = proc, QtVersion = m.FileVersionInfo, }; qtProcesses.Add(pid, qproc); return(qproc); } } catch { } nonQtProcesses.Add(pid); return(null); }
private void MainForm_Deactivate(object sender, EventArgs e) { if (isSelectWindow) { isSelectWindow = false; webBrowser1.callScript("selectWindowEnd"); Task.Factory.StartNew(() => { IntPtr newWindow = Winapi.GetForegroundWindow(); if (newWindow != IntPtr.Zero) { uint pid; Winapi.GetWindowThreadProcessId(newWindow, out pid); setDefaultProcess((int)pid); } else { Thread.Sleep(100); newWindow = Winapi.GetForegroundWindow(); if (newWindow != IntPtr.Zero) { uint pid; Winapi.GetWindowThreadProcessId(newWindow, out pid); setDefaultProcess((int)pid); } else { Thread.Sleep(500); newWindow = Winapi.GetForegroundWindow(); if (newWindow != IntPtr.Zero) { uint pid; Winapi.GetWindowThreadProcessId(newWindow, out pid); setDefaultProcess((int)pid); } else { } } } }); } }