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?

Window Click Through Toggle

Description
This script will toggle the ability to pass clicks through the focused window. It's best used in conjunction with setting the window to translucent.
Language
C#.net
Minimum Version
Created By
Renan Gonçalves Micheletti
Contributors
Thomas Malloch (BFS)
Date Created
10d ago
Date Last Modified
10d ago

Scripted Function (Macro) Code

using System;
using System.Drawing;
using System.Collections.Generic;

// The 'windowHandle' parameter will contain the window handle for the:
//   - Active window when run by hotkey
//   - Trigger target when run by a Trigger rule
//   - TitleBar Button owner when run by a TitleBar Button
//   - Jump List owner when run from a Taskbar Jump List
//   - Currently focused window if none of these match
public static class DisplayFusionFunction
{
	private const string ClickThroughWindowPropertyKey = "ClickThrough";
	
	public static void Run(IntPtr windowHandle)
	{
		// If no window handle is provided, bail out
        if (windowHandle == IntPtr.Zero)
        {
            BFS.Dialog.ShowMessageInfo("No window handle was passed to the script!");
            return;
        }
		
		// Check the window property
		bool isClickThroughEnabled = (BFS.Window.GetWindowProperty(windowHandle, ClickThroughWindowPropertyKey) == new IntPtr(1));
		
		// Toggle click through
		if(isClickThroughEnabled)
			DisableClickThrough(windowHandle);
		else
			EnableClickThrough(windowHandle);
	}
	
	private static void DisableClickThrough(IntPtr windowHandle)
    {
        // Remove click-through styles
        var exStyle = BFS.Window.GetWindowStyleEx(windowHandle);
        exStyle &= ~BFS.WindowEnum.WindowStyleEx.WS_EX_TRANSPARENT;
        exStyle &= ~BFS.WindowEnum.WindowStyleEx.WS_EX_LAYERED;
        BFS.Window.SetWindowStyleEx(exStyle, windowHandle);

        // Remove the window property
        BFS.Window.RemoveWindowProperty(windowHandle, ClickThroughWindowPropertyKey);
    }


    private static void EnableClickThrough(IntPtr windowHandle)
    {
        // Get the current extended styles as an enum
        var exStyle = BFS.Window.GetWindowStyleEx(windowHandle);

        // Add WS_EX_TRANSPARENT + WS_EX_LAYERED to make it click-through
        exStyle |= BFS.WindowEnum.WindowStyleEx.WS_EX_TRANSPARENT;
        exStyle |= BFS.WindowEnum.WindowStyleEx.WS_EX_LAYERED;
        BFS.Window.SetWindowStyleEx(exStyle, windowHandle);

        // Set a window property
		BFS.Window.SetWindowProperty(windowHandle, ClickThroughWindowPropertyKey, new IntPtr(1));
    }
}