using System;
using System.Collections.Generic;
using System.Threading;
using System.Runtime.InteropServices;
using System.Text;
public static class DisplayFusionFunction
{
[DllImport("user32.dll")]
static extern bool IsWindowVisible(IntPtr hWnd);
[DllImport("user32.dll")]
static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int maxLength);
[DllImport("user32.dll")]
static extern int GetWindowTextLength(IntPtr hWnd);
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
const int SW_MINIMIZE = 6;
const int SW_RESTORE = 9;
public static void Run(IntPtr windowHandle)
{
string[] targets = { "Notepad", "Google Chrome", "Calculator" };
List<IntPtr> matchedWindows = new List<IntPtr>();
foreach (IntPtr hWnd in BFS.Window.GetAllWindowHandles())
{
if (!IsWindowVisible(hWnd))
continue;
if (BFS.Window.IsMinimized(hWnd))
continue;
int length = GetWindowTextLength(hWnd);
if (length == 0)
continue;
StringBuilder builder = new StringBuilder(length + 1);
GetWindowText(hWnd, builder, builder.Capacity);
string title = builder.ToString();
foreach (string keyword in targets)
{
if (title.Contains(keyword))
{
matchedWindows.Add(hWnd);
break;
}
}
}
// Minimize all matched windows
foreach (IntPtr hWnd in matchedWindows)
{
ShowWindow(hWnd, SW_MINIMIZE);
}
Thread.Sleep(1000);
// Restore all matched windows
foreach (IntPtr hWnd in matchedWindows)
{
ShowWindow(hWnd, SW_RESTORE);
}
}
}