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