Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Toggle NVIDIA Surround and Load the Appropriate Monitor Profile

Description
This script will toggle NVIDIA Surround mode, and then load the appropriate Monitor Profile, because when toggling Surround off, usually only one monitor ends up enabled. Before running this script, you need to save DisplayFusion Monitor Profiles for when Surround is enabled, and also when it's disabled, then update the names in the script to match the names of your Monitor Profiles. You also need to make sure to enable the Ctrl + Alt + S hotkey for toggling Surround in the NVIDIA Control Panel.
Language
C#.net
Minimum Version
Created By
Thomas Malloch (BFS)
Contributors
-
Date Created
Jun 13, 2017
Date Last Modified
Jun 13, 2017

Scripted Function (Macro) Code

using System;
using System.Drawing;
using System.Runtime.InteropServices;

public static class DisplayFusionFunction
{
    [DllImport("User32.dll", CharSet = CharSet.Unicode, PreserveSig = true)]
    private static extern IntPtr FindWindow([MarshalAs(UnmanagedType.LPWStr)] string lpClassName, [MarshalAs(UnmanagedType.LPWStr)] string lpWindowName);

	public static void Run(IntPtr windowHandle)
	{
        //set these to the names of your extended and surround Monitor Profiles
        string surroundProfile = "NVidia Surround Profile";
        string extendedProfile = "Extended Profile";

        //get the system tray window
        IntPtr trayWnd = FindWindow("Shell_TrayWnd", null);

        //focus the window
        BFS.Window.Focus(trayWnd);
        
        //mute the computer
        BFS.Input.SendKeys("{VK_173}");
        
        //send the nvidia surround hotkey
        BFS.Input.SendKeys("%(^(S))");
        
        //wait for surround to be applied
        BFS.General.ThreadWait(10000);
        
        //unmute the computer
        BFS.Input.SendKeys("{VK_173}");
        
        //load a monitor profile
        if(IsSurroundEnabled())
            BFS.DisplayFusion.LoadMonitorProfileHideErrors(surroundProfile);
        else
            BFS.DisplayFusion.LoadMonitorProfileHideErrors(extendedProfile);
	}

    private static bool IsSurroundEnabled()
    {
        return (BFS.Monitor.GetPrimaryMonitorBounds().Width / (double)BFS.Monitor.GetPrimaryMonitorBounds().Height > 1.8d);
    }
}