
DarkKnight777
2 discussion posts
Hey Everyone! Just got this software today, so im a little overwhelmed with all the features. I did however figure out how to mirror specific windows which is what i was looking to do with this software but when I mirror another window the other one is still there and im looking to do one at a time... Let me explain my reasoning.
I have OBS and I have a capture card that I am using as an extended monitor to only capture what I want to be shown, I dont want to manually have to switch the input of my monitor in order to see whats on the screen in order to close out of a previous mirror. So lets say for example I am capturing gameplay, I use the Mirror Function, how I want to show a specific window like chrome I will then mirror that window... now there are 2 mirrors but I just want it to replace the current one with the most recent mirror is this possible? If it is possible how would I go about setting this up?

DarkKnight777
2 discussion posts
I figured it out with writing a # Script I will post it down below in case anyone else ever wants/needs this:
using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
using System.Drawing;
public static class DisplayFusionFunction
{
// Retrieves the window handle at a given screen coordinate.
[DllImport("user32.dll")]
private static extern IntPtr WindowFromPoint(Point p);
// Retrieves the top level (root) window for a given window handle.
[DllImport("user32.dll")]
private static extern IntPtr GetAncestor(IntPtr hwnd, uint gaFlags);
private const uint GA_ROOT = 2;
// Checks if a window is visible.
[DllImport("user32.dll")]
private static extern bool IsWindowVisible(IntPtr hWnd);
public static void Run()
{
try
{
// STEP 1: Close any existing mirror windows.
// We search for windows that have a title text matching "*mirror window*".
// (Adjust this search string if your mirror windows are labeled differently.)
IntPtr[] mirrorWindows = BFS.Window.GetWindowsByText("*mirror window*");
if (mirrorWindows != null && mirrorWindows.Length > 0)
{
foreach (IntPtr wnd in mirrorWindows)
{
if (wnd != IntPtr.Zero)
BFS.Window.Close(wnd);
}
}
// Allow time for any existing mirror windows to close.
Thread.Sleep(500);
// STEP 2: Get the mouse cursor's screen position.
int mouseX = BFS.Input.GetMousePositionX();
int mouseY = BFS.Input.GetMousePositionY();
Point cursorPoint = new Point(mouseX, mouseY);
// STEP 3: Get the window handle directly under the cursor.
IntPtr candidateWindow = WindowFromPoint(cursorPoint);
// STEP 4: Get the top-level (root) window of that candidate.
IntPtr targetWindow = GetAncestor(candidateWindow, GA_ROOT);
if (targetWindow == IntPtr.Zero)
{
MessageBox.Show("No window was detected under the cursor.", "Mirror Error");
return;
}
// STEP 5: Verify that the window is visible.
if (!IsWindowVisible(targetWindow))
{
MessageBox.Show("The window under your cursor is not visible.", "Mirror Error");
return;
}
// STEP 6: Mirror the target window.
BFS.DisplayFusion.MirrorWindow(targetWindow);
}
catch (Exception ex)
{
MessageBox.Show("An error occurred: " + ex.Message, "Script Error");
}
}
}