Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure?

Minimize Specific Windows, Wait 1s, Restore Them

Description
This script will minimize the windows that match the text you set in the "targets" variable, then restore them 1 second later. This can be rn from a Timer Interval Trigger rule to attempt to prevent screen burn-in on OLED monitors.
Language
C#.net
Minimum Version
Created By
LEADER WAEL
Contributors
-
Date Created
5d ago
Date Last Modified
5d ago

Scripted Function (Macro) Code

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);
        }
    }
}