Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

Set Window Always On Top and Fade Into/Out of 90% Transparency

Description
Sets window to be Always on Top and fades to 90% transparency. Second click disables Always on Top and returns transparency to 100%.
Language
C#.net
Minimum Version
Created By
Gilad Barnea
Contributors
-
Date Created
Apr 4, 2018
Date Last Modified
Apr 9, 2018

Scripted Function (Macro) Code

using System;
using System.Drawing;

public static class DisplayFusionFunction {

    public static int target_transparency = 90;
    public static void Run (IntPtr windowHandle) {

        //if we couldn't get the window then exit
        if (windowHandle == IntPtr.Zero)
            return;
        int current_transparency = (int) Math.Floor (BFS.Window.GetTransparency (windowHandle));

        if (current_transparency != target_transparency - 1) {
            BFS.Window.SetAlwaysOnTop(windowHandle, true);
            SetTrans (current_transparency, target_transparency, windowHandle);
        } else {
            BFS.Window.SetAlwaysOnTop(windowHandle, false);
            SetTrans (current_transparency, 100, windowHandle);
        }

    }

    private static void SetTrans (int origin, int target, IntPtr windowHandle) {
        // INCREASE FOR SLOWER ANIMATION, DECEREASE FOR FASTER
        int animation_rate_factor = 2;

        // Tries to keep the time it takes for the animation to complete constant,
        // regardless of how big the difference between origin and target is.
        // So going from 10 to 100 would approx. take the same time as from 90 to 100. (based on animation_rate_factor)
        uint thread_wait = (uint) (animation_rate_factor * 100 / (Math.Abs (origin - target)));
        if (origin < 90) {
            for (int i = origin; i <= target; i++) {
                BFS.General.ThreadWait (thread_wait);
                BFS.Window.SetTransparency (windowHandle, i);
            }
        } else {
            for (int i = origin; i >= target; i--) {
                BFS.General.ThreadWait (thread_wait);
                BFS.Window.SetTransparency (windowHandle, i);
            }
        }
        BFS.Window.SetTransparency (windowHandle, target);
    }
}