Implement "find all wows" button

This commit is contained in:
2024-12-27 11:00:58 +01:00
parent 197f098f67
commit 6cee7038bd

View File

@@ -24,16 +24,22 @@ internal static class Program {
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
static extern bool AllocConsole(); static extern bool AllocConsole();
private static void AdjustAffinities() { private static void CleanWindows() {
for (int i = 0; i < NumProc; i++) { for (int i = 0; i < NumProc; i++) {
var window = windows[i]; var window = windows[i];
if (window == null) continue; if (window == null) continue;
if (window.MainWindowHandle == IntPtr.Zero) { if (window.MainWindowHandle == IntPtr.Zero) {
Console.WriteLine($"Window at index {i} has no main window, removing from tracked windows"); Console.WriteLine($"Window at index {i} has no main window, removing from tracked windows");
windows[i] = null; windows[i] = null;
continue;
} }
}
}
private static void AdjustAffinities() {
CleanWindows();
for (int i = 0; i < NumProc; i++) {
var window = windows[i];
if (window == null) continue;
if (i != ActiveIndex) { if (i != ActiveIndex) {
try { try {
window.ProcessorAffinity = defaultAffinity; window.ProcessorAffinity = defaultAffinity;
@@ -56,14 +62,10 @@ internal static class Program {
} }
private static void AdjustPriorities() { private static void AdjustPriorities() {
CleanWindows();
for (int i = 0; i < NumProc; i++) { for (int i = 0; i < NumProc; i++) {
var window = windows[i]; var window = windows[i];
if (window == null) continue; if (window == null) continue;
if (window.MainWindowHandle == IntPtr.Zero) {
Console.WriteLine($"Window at index {i} has no main window, removing from tracked windows");
windows[i] = null;
continue;
}
if (i != ActiveIndex) { if (i != ActiveIndex) {
try { try {
@@ -100,27 +102,25 @@ internal static class Program {
return foregroundProcess; return foregroundProcess;
} }
private static void TrackWindow() { private static void TrackWows() {
Console.WriteLine("Toggling foreground window as tracked..."); CleanWindows();
var foregroundProcess = GetForegroundProcess(); var processes = Process.GetProcesses();
if (foregroundProcess == null) return; foreach (var process in processes) {
Console.WriteLine($"Foreground process: {foregroundProcess}"); if (process.ProcessName == "UWow-64") {
Console.WriteLine($"Found UWow-64 at pid {process.Id}");
for (int i = 0; i < 9; i++) { for (int i = 0; i < NumProc; i++) {
var window = windows[i]; if (windows[i] != null && windows[i].Id == process.Id) {
if (window != null && window.Id == foregroundProcess.Id) { Console.WriteLine($"UWow-64 is already tracked at index {i}");
Console.WriteLine($"Removing foreground window from tracked at index {i}..."); continue;
windows[i] = null; }
return; }
} for (int i = 0; i < NumProc; i++) {
} if (windows[i] == null) {
windows[i] = process;
for (int i = 0; i < 9; i++) { Console.WriteLine($"Added UWow-64 to tracked windows at index {i}");
var window = windows[i]; break;
if (window == null) { }
Console.WriteLine($"Adding foreground window to tracked at index {i}..."); }
windows[i] = foregroundProcess;
return;
} }
} }
} }
@@ -202,7 +202,7 @@ internal static class Program {
static void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e) { static void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e) {
if (e.Key == Keys.Oemtilde && e.Modifiers == KeyModifiers.Alt) { if (e.Key == Keys.Oemtilde && e.Modifiers == KeyModifiers.Alt) {
TrackWindow(); TrackWows();
return; return;
} }