Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

Make Window Translucent and Enable Click-Through then Return Window to Previous State

Description
This script makes the focused window translucent and allows clicks to pass through it on the first run. On the second run, it reverts it back to its previous state.
Language
C#.net
Minimum Version
Created By
pl0x55036
Contributors
Sharkman43570
Date Created
Jan 19, 2022
Date Last Modified
Jan 19, 2022

Scripted Function (Macro) Code

using System;
using System.Drawing;

// In order to disable this on the target window, you have to run this script via keyboard shortcut or with the "One Click List" entry

public static class DisplayFusionFunction
{
	public static void Run(IntPtr windowHandle)
	{
		if (windowHandle == IntPtr.Zero) return;

		// Get the status of the current wintow, is already set to always on top, what is its current transparency and get a string version of the pointer to this window
		bool isWindowAlwaysOnTop = BFS.Window.GetAlwaysOnTop(windowHandle);
		decimal windowOriginalTransparency = BFS.Window.GetTransparency(windowHandle);
		string thisWindowHandleAsString = windowHandle.ToString();

		string[] ScriptSettingsValueNames = BFS.ScriptSettings.GetValueNames();
		bool indexPresent = Array.IndexOf<string>(ScriptSettingsValueNames, thisWindowHandleAsString) != -1;

		// If there are no values set to persist betwern executions of any function, or this function's windowHandleToString isn't present then write them all
		if (ScriptSettingsValueNames.Length == 0 | !indexPresent)
		{
			BFS.ScriptSettings.WriteValue(thisWindowHandleAsString, thisWindowHandleAsString);
			BFS.ScriptSettings.WriteValueBool(thisWindowHandleAsString + "-WindowAlwaysOnTop", isWindowAlwaysOnTop);
			BFS.ScriptSettings.WriteValueInt(thisWindowHandleAsString + "-WindowOriginalTransparencyInt", Convert.ToInt32(windowOriginalTransparency));
		}

		// If Window has been made Click-Through (WS_EX_LAYERED | WS_WX_TRANSPARENT) Check for the stored variables and use those 
		if (BFS.Window.HasWindowStyleEx(BFS.WindowEnum.WindowStyleEx.WS_EX_LAYERED | BFS.WindowEnum.WindowStyleEx.WS_EX_TRANSPARENT, windowHandle))
		{

			if (indexPresent)
			{
				// If present set local variables to ScriptSetting ones we made in another execution else use default values
				isWindowAlwaysOnTop = BFS.ScriptSettings.ReadValueBool(thisWindowHandleAsString + "-WindowAlwaysOnTop") | false;
				windowOriginalTransparency = Convert.ToDecimal(BFS.ScriptSettings.ReadValueInt(thisWindowHandleAsString + "WindowOriginalTransparencyInt") | 100);
				// And now that we are about to restore the window to its former state, we delete the variables we saved
				BFS.ScriptSettings.DeleteValue(thisWindowHandleAsString);
				BFS.ScriptSettings.DeleteValue(thisWindowHandleAsString + "-WindowAlwaysOnTop");
				BFS.ScriptSettings.DeleteValue(thisWindowHandleAsString + "-WindowOriginalTransparencyInt");
			}

			BFS.Window.SetTransparency(windowHandle, windowOriginalTransparency);
			BFS.Window.SetWindowStyleEx(BFS.Window.GetWindowStyleEx(windowHandle) & ~BFS.WindowEnum.WindowStyleEx.WS_EX_LAYERED & ~BFS.WindowEnum.WindowStyleEx.WS_EX_TRANSPARENT, windowHandle);
			BFS.Window.SetAlwaysOnTop(windowHandle, isWindowAlwaysOnTop);
		}
		else
		{
			// If the window is already transparent, maintain that level, else set it to 75%
			BFS.Window.SetTransparency(windowHandle, windowOriginalTransparency < 100m ? windowOriginalTransparency : 75m);
			BFS.Window.SetWindowStyleEx(BFS.Window.GetWindowStyleEx(windowHandle) | BFS.WindowEnum.WindowStyleEx.WS_EX_LAYERED | BFS.WindowEnum.WindowStyleEx.WS_EX_TRANSPARENT, windowHandle);
			BFS.Window.SetAlwaysOnTop(windowHandle, true);
		}
	}
}