public static Process GetProcessFromWinItem(WindowItem windowItem) { if (windowItem.WindowInfo.Title == "*") { return(Process.GetProcesses().ToList().Find(x => x.ProcessName == windowItem.WindowInfo.Name && x.MainModule.FileName == windowItem.WindowInfo.FileName && x.MainModule.ModuleName == windowItem.WindowInfo.ModName)); } else { return(Process.GetProcesses().ToList().Find(x => x.ProcessName == windowItem.WindowInfo.Name && x.MainWindowTitle == windowItem.WindowInfo.Title && x.MainModule.FileName == windowItem.WindowInfo.FileName && x.MainModule.ModuleName == windowItem.WindowInfo.ModName)); } }
public static bool DoesDuplicateExist(WindowItem windowItem) { var existingWinItem = Toolbox.settings.ActiveWindowList.ToList().Find(x => x.WindowInfo.Name == windowItem.WindowInfo.Name && x.WindowInfo.Title == windowItem.WindowInfo.Title && x.WindowInfo.FileName == windowItem.WindowInfo.FileName && x.WindowInfo.ModName == windowItem.WindowInfo.ModName); if (existingWinItem != null) { return(true); } else { return(false); } }
public static void GetWindowItemLocation(WindowItem windowItem) { try { Process foundProc = null; if (windowItem.WindowInfo.Title == "*") { foreach (var proc in Process.GetProcesses()) { if ( proc.ProcessName == windowItem.WindowInfo.Name && proc.MainModule.ModuleName == windowItem.WindowInfo.ModName && proc.MainModule.FileName == windowItem.WindowInfo.FileName ) { foundProc = proc; } } } else { foreach (var proc in Process.GetProcesses()) { if ( proc.ProcessName == windowItem.WindowInfo.Name && proc.MainModule.ModuleName == windowItem.WindowInfo.ModName && proc.MainWindowTitle == windowItem.WindowInfo.Title && proc.MainModule.FileName == windowItem.WindowInfo.FileName ) { foundProc = proc; } } } if (foundProc == null) { uDebugLogAdd("Running process matching windowItem wasn't found"); } else { Toolbox.settings.UpdateWindowLocation(windowItem, foundProc); uDebugLogAdd($"Updated {windowItem.WindowName} windowItem"); Director.Main.uStatusUpdate($"Updated location for {foundProc.ProcessName}"); } } catch (Exception ex) { LogException(ex); } }
public void UpdateWindowLocation(WindowItem windowItem, Process proc) { var existingItem = _currentWindowList.Find(x => x.WindowInfo.PrivateID == windowItem.WindowInfo.PrivateID); WindowInfo windowInfo = WindowInfo.GetWindowInfoFromProc(proc); if (proc == null) { uDebugLogAdd("Update process was null"); } if (existingItem != null && proc != null) { existingItem.WindowInfo = windowInfo; OnPropertyChanged("WindowList"); } else { uDebugLogAdd("Couldn't find existing window item"); } Events.TriggerWindowInfoChange(true); }
public static WindowItem GetWindowItemUpdate(WindowItem winItem, Process proc) { return(new WindowItem() { }); }
public static bool MoveProcessHandle(WindowItem selectedWindow, Process process = null) { bool moveAll = false; bool windowMoved = false; try { /// Title is a wildcard, lets move ALL THE WINDOWS!!! if (selectedWindow.WindowInfo.Title == "*") { moveAll = true; uDebugLogAdd($"WindowInfo title for {selectedWindow.WindowInfo.Name} is {selectedWindow.WindowInfo.Title} so we will be MOVING ALL THE WINDOWS!!!!"); } /// Title isn't a wildcard, lets only move the windows we want else { uDebugLogAdd($"WindowInfo title for {selectedWindow.WindowInfo.Name} is {selectedWindow.WindowInfo.Title} so I can only move matching handles... :("); } List <DetailedProcess> foundList = new List <DetailedProcess>(); if (process == null) { foreach (var proc in Process.GetProcessesByName(selectedWindow.WindowInfo.Name)) { foreach (var handle in WinAPIWrapper.EnumerateProcessWindowHandles(proc.Id)) { try { var detProc = DetailedProcess.Create(proc, handle); foundList.Add(detProc); uDebugLogAdd($"Added to list | [{detProc.Handle}]{detProc.Name} :: {detProc.Title}"); } catch (Exception ex) { uDebugLogAdd($"Unable to add handle to the list | [{handle}]{proc.ProcessName}: {ex.Message}"); } } } } else { foreach (var handle in WinAPIWrapper.EnumerateProcessWindowHandles(process.Id)) { try { var detProc = DetailedProcess.Create(process, handle); foundList.Add(detProc); uDebugLogAdd($"Added to list | [{detProc.Handle}]{detProc.Name} :: {detProc.Title}"); } catch (Exception ex) { uDebugLogAdd($"Unable to add handle to the list | [{handle}]{process.ProcessName}: {ex.Message}"); } } } if (moveAll) { foreach (var detProc in foundList) { try { if (Toolbox.settings.ActiveWindowList.Find(x => x.WindowInfo.Name == detProc.Name && x.WindowInfo.Title == detProc.Title ) == null) { uDebugLogAdd($"Moving handle | [{detProc.Handle}]{detProc.Name} :: {detProc.Title}"); WinAPIWrapper.MoveWindow(detProc.Handle, selectedWindow.WindowInfo.XValue, selectedWindow.WindowInfo.YValue, selectedWindow.WindowInfo.Width, selectedWindow.WindowInfo.Height, true); windowMoved = true; } } catch (ArgumentException) { } catch (Exception ex) { uDebugLogAdd($"Unable to move handle window | [{detProc.Handle}]{detProc.Name} {detProc.Title}: {ex.Message}"); } } } else { foreach (var detProc in foundList) { try { if (detProc.Name == selectedWindow.WindowInfo.Name && detProc.Title == selectedWindow.WindowInfo.Title) { uDebugLogAdd($"Matched window & title, moving: [{detProc.Handle}]{detProc.Name} | {detProc.Title}"); WinAPIWrapper.MoveWindow(detProc.Handle, selectedWindow.WindowInfo.XValue, selectedWindow.WindowInfo.YValue, selectedWindow.WindowInfo.Width, selectedWindow.WindowInfo.Height, true); windowMoved = true; } } catch (ArgumentException) { } catch (Exception ex) { uDebugLogAdd($"Unable to move handle window | [{detProc.Handle}]{detProc.Name} {detProc.Title}: {ex.Message}"); } } } } catch (ArgumentException) { } catch (Exception ex) { LogException(ex); } return(windowMoved); }
public void RemoveWindow(WindowItem windowItem) { _currentWindowList.Remove(windowItem); OnPropertyChanged("ActiveWindowList"); Events.TriggerWindowInfoChange(); }