Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

User Image
nei
2 discussion posts
Hi, I found this toggle. But I would like to be able to apply it to the scripts section, in #C or Visual Basic. So that the rest of people can enjoy the advantages of being able to change from normal mode to surround easily.

; Toggle-off routine (switch to Extended Desktop mode)
Run C:\Program Files (x86)\DisplayFusion\displayfusioncommand.exe -monitorloadprofile "Here put the profile you have saved"

Code

;==============================================================================================
; First-run configuration
;==============================================================================================
IniRead, FirstRunVar, %appdata%\NVSToggle\NVSToggle.ini, NVSToggle, FirstRun
IF (FirstRunVar = "Completed")
{
Goto, DetectNow
}

MsgBox, 65, Nvidia Surround Toggle, To allow this application to configure itself for first-time use, please enable Nvidia Surround using the Nvidia Control Panel now. `n`nClick "OK" when ready, or "Cancel" to quit.
IfMsgBox Ok
Goto, DoubleCheck
else
Exit

DoubleCheck:
IF (A_ScreenWidth/A_ScreenHeight > 1.8)
{
Goto, FirstRun
}

MsgBox, 21, Nvidia Surround Toggle, Error: Nvidia Surround is not enabled.
IfMsgBox Retry
Goto, DoubleCheck
else
Exit

FirstRun:
FileCreateDir, %appdata%\NVSToggle
IniWrite, Completed, %appdata%\NVSToggle\NVSToggle.ini, NVSToggle, FirstRun

;==============================================================================================
; Determine current display state
;==============================================================================================
DetectNow:
IF (A_ScreenWidth/A_ScreenHeight > 1.8)
{
Goto, ToggleOff
}

IF (A_ScreenWidth/A_ScreenHeight < 1.8)
{
Goto, ToggleOn
}

IF (A_ScreenWidth/A_ScreenHeight = 1.8)
{
Goto, ToggleOn
}

Exit

;==============================================================================================
; Toggle-off routine (switch to Extended Desktop mode)
;==============================================================================================
ToggleOff:
Send {Volume_Mute}
WinActivate ahk_class Shell_TrayWnd
Send {LCtrl down}
Send {LAlt down}
Send {s down}
Sleep 100
Send {LCtrl up}{LAlt up}{s up}
Sleep 3500
Send {Volume_Mute}
Run C:\Program Files (x86)\DisplayFusion\displayfusioncommand.exe -monitorloadprofile "144hz y 60hz"
Exit

;==============================================================================================
; Toggle-on routine (switch to Surround mode)
;==============================================================================================
ToggleOn:
WinActivate ahk_class Shell_TrayWnd
Send {LCtrl down}
Send {LAlt down}
Send {s down}
Sleep 100
Send {LCtrl up}{LAlt up}{s up}
Sleep 3500
IF (A_ScreenWidth/A_ScreenHeight < 1.8)
{
Goto, SurroundFail
}
IF (A_ScreenWidth/A_ScreenHeight = 1.8)
{
Goto, SurroundFail
}
Exit

SurroundFail:
MsgBox, 21, Nvidia Surround Toggle, Error: Nvidia Surround could not be enabled!
FileDelete, %appdata%\NVSToggle\NVSToggle.ini
Exit
Feb 4, 2017 (modified Feb 4, 2017)  • #1
Thomas Malloch (BFS)'s profile on WallpaperFusion.com
Thanks for the AHK script! I put together a DisplayFusion scripted function that should do the same thing as the script above. Here's how to get it working:

  • Download the file attached to this post
  • Set up NVidia Surround on your computer, so the HotKey (ctrl+alt+s) will toggle properly
  • Open the DisplayFusion Settings window to the 'Functions' tab
  • Click the 'Add Scripted' button
  • Copy the code from the file you download in the first step to the window that pops up
  • Change the profile names on lines 39 & 41 to something that exists on your computer
  • Give the script a key combination if you want, then click OK to close and save the script, then OK again in the Settings window to save and apply your changes

I hope this works for everyone!
• Attachment: Toggle NVidia Surround and Load Profile.cs [1,783 bytes]
Feb 9, 2017  • #2
User Image
nei
2 discussion posts
If you enable Surround from the NVidia Panel, and run the script, you return to the normal profile.

But then the script no longer returns to the Surround profile

Code

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

// The 'windowHandle' parameter will contain the window handle for the:
//   - Active window when run by hotkey
//   - Trigger target when run by a Trigger rule
//   - TitleBar Button owner when run by a TitleBar Button
//   - Jump List owner when run from a Taskbar Jump List
//   - Currently focused window if none of these match
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)
{
        //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(3500);
        
        //unmute the computer
        BFS.Input.SendKeys("{VK_173}");
        
        //load a monitor profile
        //NOTE: Change the profile names with profiles for your computer
        if(IsSurroundEnabled())
            BFS.DisplayFusion.LoadMonitorProfileHideErrors("Surround");
        else
            BFS.DisplayFusion.LoadMonitorProfileHideErrors("144hz y 60hz");
}

    private static bool IsSurroundEnabled()
    {
        return (BFS.Monitor.GetPrimaryMonitorBounds().Width / (double)BFS.Monitor.GetPrimaryMonitorBounds().Height > 1.8d);
    }
}
Feb 10, 2017  • #3
Thomas Malloch (BFS)'s profile on WallpaperFusion.com
Sorry for the late reply!

It seems like scripting is pretty unreliable with nVidia surround. We'll look for a better way to do this in the future.

Thanks!
Feb 28, 2018  • #4
Subscribe to this discussion topic using RSS
Was this helpful?  Login to Vote(-)  Login to Vote(-)