Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

Emulated Win+Left in Surround Mode

Description
This function brings back the multi-monitor behaviour of the Win+Left command, while in Eyefinity or Nvidia Surround modes. It will also save and restore the size of a single program that is moved through this or its partner function.
Language
C#.net
Minimum Version
Created By
DragRedSim
Contributors
-
Date Created
Jul 17, 2015
Date Last Modified
Jul 17, 2015

Scripted Function (Macro) 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)
	{	
		//check to see if there was an error, if there was, exit function
		if (windowHandle == IntPtr.Zero)
			return;

		//get the position of the window in the monitor, and the current monitor
		Rectangle windowRect = BFS.Window.GetBounds(windowHandle);
		Rectangle currentMonitorRect = BFS.Monitor.GetMonitorBoundsByWindow(windowHandle);
		decimal winTransparency = BFS.Window.GetTransparency(windowHandle);

		// if the window is not already in halfscreen, move to the left half.
		// is window already in left halfscreen mode?
		if ( ( windowRect.Width == currentMonitorRect.Width / 2 ) && ( windowRect.X == currentMonitorRect.X ) ) 
		{
			//if we got this far then the window is in left halfscreen mode	
			//move the window to the right side of the previous monitor
			BFS.Window.SetTransparency(windowHandle, 0);
			BFS.Window.MoveToPreviousMonitor(windowHandle);
			BFS.Window.MoveToRightMonitorHalf(windowHandle);
			BFS.Window.SetTransparency(windowHandle, winTransparency);
			return;
		}

		// so it's not in left halfscreen mode. is it in right halfscreen?
		if ( ( windowRect.Width == currentMonitorRect.Width / 2 ) && ( windowRect.X == currentMonitorRect.X + ( currentMonitorRect.Width / 2 ) ) )
		{
			//right halfscreen. we want this one to restore to user size, based on the earlier details. 
			// does this window match the last one recorded?
			if ( BFS.Window.GetText(windowHandle) == BFS.ScriptSettings.ReadValue("EmuWinLRWindowName") )
			{
				//okay, the info is for this window. let's get the values out and resize/move the window.
				int NewXPos = Convert.ToInt32(BFS.ScriptSettings.ReadValue("EmuWinLRXPos"));
				int NewYPos = Convert.ToInt32(BFS.ScriptSettings.ReadValue("EmuWinLRYPos"));
				int NewWidth = Convert.ToInt32(BFS.ScriptSettings.ReadValue("EmuWinLRWidth"));
				int NewHeight = Convert.ToInt32(BFS.ScriptSettings.ReadValue("EmuWinLRHeight"));
				// Got the values, but they're for monitor 1. No matter, we'll get the offset, then add it back in.
				NewXPos = NewXPos + currentMonitorRect.X;
				BFS.Window.SetSizeAndLocation(windowHandle, NewXPos, NewYPos, NewWidth, NewHeight);
				return;
			}
			
			// nope, the info isn't for this window. move on to sending it to left halfscreen.
			BFS.Window.MoveToLeftMonitorHalf(windowHandle);
			return;
		}

		// Not left halfscreen, not right halfscreen. Save the details, and then send it to left halfscreen.
		// We need the info to be monitor-agnostic, so the XPos value needs to be no more than the width of the screen. How do we do that? By mod division by the width of the screen.
		int CalculatedXPos = windowRect.X % currentMonitorRect.Width;

		BFS.ScriptSettings.WriteValue("EmuWinLRWindowName", BFS.Window.GetText(windowHandle));
		BFS.ScriptSettings.WriteValue("EmuWinLRXPos", Convert.ToString(CalculatedXPos));
		BFS.ScriptSettings.WriteValue("EmuWinLRYPos", Convert.ToString(windowRect.Y));
		BFS.ScriptSettings.WriteValue("EmuWinLRWidth", Convert.ToString(windowRect.Width));
		BFS.ScriptSettings.WriteValue("EmuWinLRHeight", Convert.ToString(windowRect.Height));

		BFS.Window.MoveToLeftMonitorHalf(windowHandle);
	}
}