Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

Close Window Using Windows API

Description
This script simply calls Windows API to close a window. I use it for Triggers, mainly because of my annoyance with the second window Steam launches advertising their special offers. But it could be useful in countless other scenarios, for example, in a workspace setting, you could set up a Trigger for when you close Excel, it will close Microsoft Teams and Outlook. Or for gamers, set up a Trigger that will close Discord when you close Steam.
Language
C#.net
Minimum Version
Created By
anbardoi-displayfusion
Contributors
-
Date Created
Feb 2, 2024
Date Last Modified
Feb 2, 2024

Scripted Function (Macro) Code

using System;
using System.Runtime.InteropServices;

public static class DisplayFusionFunction
{
    private const int WM_CLOSE = 0x0010;

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    private static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);

    public static void Run(IntPtr windowHandle)
    {
        SendMessage(windowHandle, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
    }
}