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?
Save up to 50% on our desktop apps during our Year End Sale!Save up to 50% on our desktop apps during our Year End Sale, including DisplayFusion, ClipboardFusion, FileSeek, LogFusion, TrayStatus, and VoiceBot!Save up to 50% on our desktop apps during our Year End Sale!

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