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?

Show List of Functions (One-Click and Coloured)

Description
This script will show a list of functions that you can choose from. You can customize the list (and colours) by editing the "MenuEntries" array in the script.
Language
C#.net
Minimum Version
Created By
DS1508
Contributors
-
Date Created
Jun 15, 2015
Date Last Modified
Jun 18, 2015

Scripted Function (Macro) Code

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

// 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)
		{
			//these are all of the functions from the "Window Management" functions list
			//the function are just called by their names. to find their names, you can copy them
			//from the context menus, or type "BFS.DisplayFusion.RunFunction(" and a window will come up
			//with all of the available functions
			//Regarding the "--- Cancel ---" entries, these are used to cancel the action, see below "MenuItem_Click"
			string[, ,] MenuEntries = 
				{
					//	{{ "Background-Color", "Foreground-Color", "Function-Name" }}
					{{ "Pink", "Maroon", "--- Cancel ---" }},
					{{ "Khaki", "Black", "Move Window to Next Monitor" }},
					{{ "Khaki", "Black", "Move Window to Previous Monitor" }},
					{{ "PaleGreen", "Black", "Size and Move Window to Left Side of Monitor" }},
					{{ "PaleGreen", "Black", "Size and Move Window to Right Side of Monitor" }},
					{{ "PaleGreen", "Black", "Size and Move Window to Top Side of Monitor" }},
					{{ "PaleGreen", "Black", "Size and Move Window to Bottom Side of Monitor" }},
					{{ "Aquamarine", "Black", "Move Window to Top-Left Corner and Size 50%" }},
					{{ "Aquamarine", "Black", "Move Window to Top-Right Corner and Size 50%" }},
					{{ "Aquamarine", "Black", "Move Window to Bottom-Left Corner and Size 50%" }},
					{{ "Aquamarine", "Black", "Move Window to Bottom-Right Corner and Size 50%" }},
					{{ "Pink", "Maroon", "--- Cancel ---" }}
				};

			//create a new ContextMenuStrip to show the items
			using(ContextMenuStrip menu = new ContextMenuStrip())
				{
					//dont show the padding on the left of the menu
					menu.ShowCheckMargin = false;
					menu.ShowImageMargin = false;

					//add items to the menu, and use our custom function when a user clicks on the items
					for ( int i = 0; i < ( MenuEntries.Length / MenuEntries.Rank ); i++ )
						{
							menu.Items.Add(MenuEntries[i, 0, 2]);
							menu.Items[menu.Items.Count - 1].Click += MenuItem_Click;
							menu.Items[menu.Items.Count - 1].BackColor = Color.FromName( MenuEntries[i, 0, 0]);
							menu.Items[menu.Items.Count - 1].ForeColor = Color.FromName( MenuEntries[i, 0, 1]);
						}

					//if the menu will show on the screen, show it. otherwise, show it above the mouse
					if(BFS.Monitor.GetMonitorBoundsByMouseCursor().Contains(new Point(BFS.Input.GetMousePositionX(), BFS.Input.GetMousePositionY() + menu.Height)))
					menu.Show(BFS.Input.GetMousePositionX(), BFS.Input.GetMousePositionY());
					else
					menu.Show(new Point(BFS.Input.GetMousePositionX(), BFS.Input.GetMousePositionY()), ToolStripDropDownDirection.AboveRight);

					//set focus to the menu
					BFS.Window.Focus(menu.Handle);

					//wait for the menu to close
					while(menu.Visible)
					Application.DoEvents();
				}
		}

			//this function will get the text of the item and try to run it as a DisplayFusion function
			//"--- Cancel ---", change it to what you used in MenuEntries-List
			private static void MenuItem_Click(object sender, EventArgs e)
				{
					ToolStripItem item = sender as ToolStripItem;
					if (item == null || item.Text == "--- Cancel ---")
					return;

					BFS.DisplayFusion.RunFunction(item.Text);
				}
	}