Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

User Image
solaris765
40 discussion posts
I'm Writing a bit of Code to replace my "Update Monitor Profile Automatically" Function but I'm running into a similar set of bugs.

The problem is that if I try to change my monitor profile within my function it'll throw this error.

Code

An error has occurred while applying your new Monitor configuration.
Please check your settings and try again.
Error: CurrentMonitor is NULL [1]: Current: [NVIDIA GeForce GTX 970\Generic PnP Monitor (ID: 2 • Primary: False • Attached: False • Extra: False • Split: False • Split Padding: L=0, R=0, T=0, B=0 • Bounds: {X=0,Y=0,Width=0,Height=0} • WorkArea: {X=0,Y=0,Width=0,Height=0} • Clone: {X=0,Y=0,Width=0,Height=0} • Driver: Unknown • Device: \\.\DISPLAY30 • TA:ID: 0 • TA:AID: 0:0 • Output: Other • DPIScaleX: 0 • DPIScaleY: 0 • Orientation: Landscape)] All: Count: 4
- NVIDIA GeForce GTX 970\IPS236 (ID: 1 • Primary: False • Attached: False • Extra: False • Split: False • Split Padding: L=0, R=0, T=0, B=0 • Bounds: {X=0,Y=0,Width=0,Height=0} • WorkArea: {X=0,Y=0,Width=0,Height=0} • Clone: {X=0,Y=0,Width=0,Height=0} • Driver: Unknown • Device:  • TA:ID: 1048850 • TA:AID: 359663079:0 • Output: DisplayPortExternal • DPIScaleX: 0 • DPIScaleY: 0 • Orientation: Landscape)
- NVIDIA GeForce GTX 970\IPS236 (ID: 2 • Primary: True • Attached: True • Extra: False • Split: False • Split Padding: L=0, R=0, T=0, B=0 • Bounds: {X=0,Y=0,Width=1920,Height=1080} • WorkArea: {X=0,Y=0,Width=1920,Height=1040} • Clone: {X=0,Y=0,Width=0,Height=0} • Driver: Builtin • Device: \\.\DISPLAY29 • TA:ID: 1048852 • TA:AID: 359663079:0 • Output: DisplayPortExternal • DPIScaleX: 0 • DPIScaleY: 0 • Orientation: Landscape)
- NVIDIA GeForce GTX 970\IPS236 (ID: 3 • Primary: False • Attached: False • Extra: False • Split: False • Split Padding: L=0, R=0, T=0, B=0 • Bounds: {X=0,Y=0,Width=0,Height=0} • WorkArea: {X=0,Y=0,Width=0,Height=0} • Clone: {X=0,Y=0,Width=0,Height=0} • Driver: Unknown • Device:  • TA:ID: 1048849 • TA:AID: 359663079:0 • Output: HDMI • DPIScaleX: 0 • DPIScaleY: 0 • Orientation: Landscape)
- NVIDIA GeForce GTX 970\DELL 2005FPW (ID: 4 • Primary: False • Attached: False • Extra: False • Split: False • Split Padding: L=0, R=0, T=0, B=0 • Bounds: {X=0,Y=0,Width=0,Height=0} • WorkArea: {X=0,Y=0,Width=0,Height=0} • Clone: {X=0,Y=0,Width=0,Height=0} • Driver: Unknown • Device:  • TA:ID: 1048848 • TA:AID: 359663079:0 • Output: DVI • DPIScaleX: 0 • DPIScaleY: 0 • Orientation: Landscape)


or this error

Code

An error has occurred while applying your new Monitor configuration.
Please check your settings and try again.
Error: Failed to call SetDisplayConfig. [HR: 87]


Depending on which profile its calling.

It should be noted that if I run the profile switch from the monitor configuration control panel or its own function it runs fine.
Mar 14, 2015  • #1
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Could you attach a copy of the script so that we can test this out here?

Thanks!
Mar 16, 2015  • #2
User Image
solaris765
40 discussion posts
Absolutely!

I'm actually working on this as we speak.

Code

using System;
using System.Drawing;

// The 'windowHandle' parameter will contain the window handle for the:
//   - Active window when run by hotkey
//   - Window Location target when run by a Window Location 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
{
public static void Run(IntPtr windowHandle)
{
//Nvidia control panel executable location.
string nvctl = "A:\\Program Files\\NVIDIA Corporation\\Control Panel Client\\nvcplui.exe";

//Can add to or remove from list to fit needs.
string[] predictedPrograms = {
"A:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",
"A:\\Program Files\\Logitech Gaming Software\\LCore.exe",
"A:\\Program Files (x86)\\Skype\\Phone\\Skype.exe"
};

//Saves all running Programs
string[] arr = BFS.Application.GetAllRunningApplicationFiles();

//Close predicted Programs.
for (int i = 0; i < predictedPrograms.Length; ++i)
BFS.Application.Kill(BFS.Application.GetAppIDByFile(predictedPrograms[i]));

BFS.Application.Start(nvctl, "");
System.Threading.Thread.Sleep(800); //Wait

BFS.Window.SetLocation(BFS.Window.GetWindowByText("NVIDIA Control Panel"),0,0);

if (BFS.ScriptSettings.ReadValue("Surround") == "true")
DisableSurround();
else
EnableSurround();

//Wait for nvctl to get closed by user.
BFS.Application.WaitForExitByFile(nvctl,0);

//Re-Open predicted Programs.
for (int i = 0; i < arr.Length; ++i)
if (!BFS.Application.IsAppRunningByFile(arr[i]))
BFS.Application.Start(arr[i], "");
/*
// default Resolution
if (BFS.ScriptSettings.ReadValue("Surround") == "false")
BFS.DisplayFusion.RunFunction("Load Monitor Profile: Default");

// nVidia Surround / AMD Eyefinity
else if (BFS.ScriptSettings.ReadValue("Surround") == "true")
BFS.DisplayFusion.RunFunction("Load Wallpaper Profile: Nvidia Surround");*/

BFS.DisplayFusion.RunFunction("Update Monitor Profile");

//included toggle
if (BFS.ScriptSettings.ReadValue("Surround") == "false")
BFS.ScriptSettings.WriteValue("Surround", "true");
else
BFS.ScriptSettings.WriteValue("Surround", "false");

}

//Manipulates Nvidia control panel to Enable Surround.
public static void EnableSurround()
{

BFS.Input.SetMousePosition(337, 279);
BFS.Input.LeftClickMouse();
System.Threading.Thread.Sleep(500); //Wait

BFS.Input.SetMousePosition(831, 685);
BFS.Input.LeftClickMouse();
System.Threading.Thread.Sleep(500); //Wait
}

//Manipulates Nvidia control panel to Disable Surround.
public static void DisableSurround()
{

BFS.Input.SetMousePosition(337, 258);
BFS.Input.LeftClickMouse();
System.Threading.Thread.Sleep(500); //Wait

BFS.Input.SetMousePosition(831, 685);
BFS.Input.LeftClickMouse();
System.Threading.Thread.Sleep(500); //Wait

}

}


And this is currently the code its calling that's causing the bugs above. It works the same integrated into the end of the above in place of the function call or as it is now.

Code

using System;
using System.Drawing;
using System.Windows.Forms;

//Code brought to you by: solaris765
//Because numbers after my screen name are fun.
//Automatically changes Monitor Profile based on resolution changes.
//
// The 'windowHandle' parameter will contain the window handle for the:
//   - Active window when run by hotkey
//   - Window Location target when run by a Window Location 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
{
public static void Run(IntPtr windowHandle)
{
int defaultResolutionWidth = 1920;
int nonstandardReslolutionWidth = 5760;

// default Resolution
if (Screen.PrimaryScreen.Bounds.Width == defaultResolutionWidth)
{
BFS.DisplayFusion.LoadMonitorProfile("Default");
BFS.ScriptSettings.WriteValue("Profile", "Default");
}

// nVidia Surround / AMD Eyefinity
else if (Screen.PrimaryScreen.Bounds.Width == nonstandardReslolutionWidth)
{
BFS.DisplayFusion.LoadMonitorProfile("Nvidia Surround");
BFS.ScriptSettings.WriteValue("Profile", "Nvidia Surround");
}
}
}
Mar 16, 2015  • #3
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Thanks! We'll check this out and see what we can find :)
Mar 16, 2015  • #4
User Image
solaris765
40 discussion posts
Thank you
I feel like I may need to add that in order for the program to continue the nvidia control panel must be closed.
Mar 16, 2015  • #5
User Image
solaris765
40 discussion posts
After my original post I did make some changes on how the script interacted with itself, monitor profiles and the primary screen resolution. And at this point with my own testing I haven't run into any more of the same errors.

I'm going to continue stress testing the script and if I can't break it you can drop this thread.

The version of the script I gave you was yet untested as I was working on it when you replied to the thread so it might actually work fine at this point.

Edit: As a side note. Sometimes when I do run the script to change the monitor profile. The windows task bar disappears and the Display Fusion task bars appear half height. Its easily fixed by moving the windows task bar to a different side of the screen and back. But it is a bit annoying.

Edit 2: I've done my testing and everything is in order. It looks like I was applying the monitor profiles to the wrong resolution before.
Thanks for taking a look though! :D
Mar 16, 2015 (modified Mar 16, 2015)  • #6
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Awesome, glad to hear you got it sorted out! We received the submissions for those scripts this morning too, so we'll add them to the repository as soon as we've had a chance to test them here :)

Thanks!
Mar 17, 2015  • #7
Subscribe to this discussion topic using RSS
Was this helpful?  Login to Vote(-)  Login to Vote(-)