Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure you want to delete this item?

Auto Win+Left/Right (Modified)

Description
This is a customer modified Auto Win+Left/Right switcher which will snap your application to the left or right of the screen based on which half of your screen your application is mostly in at the moment.
Language
C#.net
Minimum Version
Created By
Mark Ozga
Contributors
Thomas Malloch (BFS)
Date Created
Nov 19, 2019
Date Last Modified
Nov 20, 2019

Scripted Function (Macro) Code

// This is a  customer modified Auto Win+Left/Right switcher which will snap your application to the left or right of the screen based 
// on which half of your screen your application is mostly in at the moment.

// BFS customer Mark Ozga (markozga@alumni.depaul.edu) has made changes to the original code to allow for 70%/30% splits 
// as one does in userspace via keyboard shortcuts and mouse gestures.

// The script is invoked cleanly as a TitleBar Button or mapped to key auch as the seldom used Apps key.

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 monitorRect = BFS.Monitor.GetMonitorBoundsByWindow(windowHandle);		
		
		//maths to imagine an imaginary dot at the top of every window
		int MiddleOfWindow = (windowRect.Width / 2);
		//maths used to determine if the imaginary dot will be on either side of an imaginery fence.
		int MiddleOfMonitor = (monitorRect.Width / 2);
		//maths used to determine the actual position of our imaginary dot within the confines of the screen 
		int PositionOfWindow = (windowRect.X + MiddleOfWindow);
		
		//a test to determine if the middle of our application is closer to right side of the screen
		if(  PositionOfWindow >= MiddleOfMonitor )
            {
                //if we are here then the middle of our applications must be closer to the RIGHT side of the screen
                //let Windows to use its routines to snap it, restore it, or otherwise move the window
                BFS.Input.SendKeys("{WIN}({VK_39})");
            }
    
        if(  PositionOfWindow < MiddleOfMonitor  ) 
            {
                //if we are here we can assume the imaginary dot is closer to the LEFT side of the screen
                //let Windows to use its routines to snap it, restore it, or otherwise move the window
                BFS.Input.SendKeys("{WIN}({VK_37})");
			}			
	}
}