Quote:
Which mirror function are you using?
Yep it looks like I am Mirroring the window, The Script i am using is below
using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
using System.Drawing;
public static class DisplayFusionFunction
{
// -----------------------------------------------------------
// P/Invoke declarations for window manipulation
// -----------------------------------------------------------
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
private static extern IntPtr GetAncestor(IntPtr hwnd, uint gaFlags);
private const uint GA_ROOT = 2;
[DllImport("user32.dll")]
private static extern bool IsWindowVisible(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = true)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", SetLastError = true)]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
private const int GWL_STYLE = -16;
private const int GWL_EXSTYLE = -20;
[DllImport("user32.dll", SetLastError = true)]
private static extern bool SetWindowPos(
IntPtr hWnd,
IntPtr hWndInsertAfter,
int X, int Y, int cx, int cy,
uint uFlags);
// Standard window style constants.
private const int WS_BORDER = 0x00800000;
private const int WS_DLGFRAME = 0x00400000;
private const int WS_CAPTION = WS_BORDER | WS_DLGFRAME;
private const int WS_THICKFRAME = 0x00040000;
private const int WS_POPUP = unchecked((int)0x80000000);
private const int WS_VISIBLE = 0x10000000;
// Extended window style constants.
private const int WS_EX_NOACTIVATE = 0x08000000;
private const int WS_EX_TOOLWINDOW = 0x00000080;
// SetWindowPos flags.
private const uint SWP_NOMOVE = 0x0002;
private const uint SWP_NOSIZE = 0x0001;
private const uint SWP_NOZORDER = 0x0004;
private const uint SWP_FRAMECHANGED= 0x0020;
private const uint SWP_SHOWWINDOW = 0x0040;
public static void Run()
{
try
{
// -----------------------------------------------------------
// STEP 1: Immediately store the active (target) window handle.
// This ensures we capture the desired window, not a previous one.
// -----------------------------------------------------------
IntPtr targetWindow = GetForegroundWindow();
if (targetWindow == IntPtr.Zero || !IsWindowVisible(targetWindow))
{
MessageBox.Show("No valid window in the foreground.", "Mirror Error");
return;
}
// -----------------------------------------------------------
// STEP 2: Close any existing mirror windows.
// -----------------------------------------------------------
IntPtr[] oldMirrors = BFS.Window.GetWindowsByText("*mirror window*");
if (oldMirrors != null)
{
foreach (IntPtr m in oldMirrors)
{
if (m != IntPtr.Zero)
BFS.Window.Close(m);
}
}
for (int i = 0; i < 10; i++)
{
IntPtr[] check = BFS.Window.GetWindowsByText("*mirror window*");
if (check == null || check.Length == 0)
break;
Thread.Sleep(50);
}
Thread.Sleep(500);
// -----------------------------------------------------------
// STEP 3: Create the mirror by mirroring the stored target window.
// -----------------------------------------------------------
BFS.DisplayFusion.MirrorWindow(targetWindow);
Thread.Sleep(300);
// -----------------------------------------------------------
// STEP 4: Retrieve the new mirror window.
// -----------------------------------------------------------
IntPtr[] newMirrors = BFS.Window.GetWindowsByText("*mirror window*");
if (newMirrors == null || newMirrors.Length == 0)
{
MessageBox.Show("Mirror window not found.", "Mirror Error");
return;
}
IntPtr mirrorHandle = newMirrors[0];
// -----------------------------------------------------------
// STEP 5: Remove borders and adjust window style.
// Also add extended styles to keep it non-activating.
// -----------------------------------------------------------
int style = GetWindowLong(mirrorHandle, GWL_STYLE);
int newStyle = style & ~(WS_CAPTION | WS_THICKFRAME);
newStyle |= WS_POPUP | WS_VISIBLE;
SetWindowLong(mirrorHandle, GWL_STYLE, newStyle);
SetWindowPos(mirrorHandle, IntPtr.Zero, 0, 0, 0, 0,
SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
int exStyle = GetWindowLong(mirrorHandle, GWL_EXSTYLE);
exStyle |= WS_EX_NOACTIVATE | WS_EX_TOOLWINDOW;
SetWindowLong(mirrorHandle, GWL_EXSTYLE, exStyle);
// -----------------------------------------------------------
// STEP 6: Force the mirror window onto monitor 3.
// (This uses DisplayFusion’s built-in function to reposition
// and maximize the mirror window on monitor 3.)
// -----------------------------------------------------------
Screen[] screens = Screen.AllScreens;
if (screens.Length < 3)
{
MessageBox.Show("Monitor 3 not found.", "Mirror Error");
return;
}
BFS.Window.MoveToMonitorMaximized(3, mirrorHandle);
}
catch (Exception ex)
{
MessageBox.Show("An error occurred: " + ex.Message, "Mirror Error");
}
}
}