using System;
using System.Drawing;
using System.Collections.Generic;
public static class DisplayFusionFunction
{
public static void Run(IntPtr windowHandle)
{
// Set the amount of time (in milliseconds) between loops (lowering this time will increase CPU usage)
uint waitTime = 1000;
// Script setup stuff
var previousList = new List<IntPtr>();
var currentList = new List<IntPtr>();
while (true) // Loop forever (exit the script via its icon in the system tray)
{
// Clear the current list of windows
currentList.Clear();
BFS.General.LogText("MoveOutlookReminderWindows: Current list cleared: " + currentList.Count.ToString());
// Add the current Outlook or Word window handles to a list
currentList = GetOpenOutlookReminderWindows();
// Compare the list from the previous run to the list from the current run and move any new ones
foreach (IntPtr window in currentList)
{
if (!(previousList.Contains(window)))
{
// Set the window to always on top
BFS.Window.SetAlwaysOnTop(window, true);
// Get the mouse position
Point mousePosition = new Point(BFS.Input.GetMousePositionX(), BFS.Input.GetMousePositionY());
// Get the window size and location
Rectangle windowBounds = BFS.Window.GetBounds(window);
// Get an array of the bounds for all monitors ignoring splits
Rectangle[] monitorBoundsAll = BFS.Monitor.GetMonitorBoundsNoSplits();
// Loop through the array of bounds and move the window to the centre of whichever one the mouse cursor is on
foreach (Rectangle monitorBounds in monitorBoundsAll)
{
if (monitorBounds.Contains(mousePosition))
{
BFS.Window.SetLocation(window, monitorBounds.X + ((monitorBounds.Width - windowBounds.Width) / 2), monitorBounds.Y + ((monitorBounds.Height - windowBounds.Height) / 2));
}
}
// Log the action
BFS.General.LogText("MoveOutlookReminderWindows: Reminder window brought to top and centred: " + window.ToString() + " " + BFS.Window.GetText(window));
previousList.Add(window);
BFS.General.LogText("MoveOutlookReminderWindows: Window added to previous list: " + window.ToString() + " " + previousList.Count.ToString());
}
}
// If the previous list has windows that aren't in the new list, mark them for deletion
var closedWindows = new List<IntPtr>();
foreach (IntPtr window in previousList)
{
if (!(currentList.Contains(window)))
{
// Re-check the current list for Outlook windows that were quickly removed/re-added
var refreshedList = new List<IntPtr>();
refreshedList = GetOpenOutlookReminderWindows();
if (!(refreshedList.Contains(window)))
{
closedWindows.Add(window);
BFS.General.LogText("MoveOutlookReminderWindows: Window marked for deletion: " + window.ToString());
}
}
}
// Delete the closed windows from the previous list
foreach (IntPtr window in closedWindows)
{
previousList.Remove(window);
BFS.General.LogText("MoveOutlookReminderWindows: Window deleted: " + window.ToString() + " " + previousList.Count.ToString());
}
// Wait before looping to prevent the CPU from running up
BFS.General.ThreadWait(waitTime);
}
}
private static List<IntPtr> GetOpenOutlookReminderWindows()
{
var windowList = new List<IntPtr>();
foreach (IntPtr window in BFS.Window.GetVisibleAndMinimizedWindowHandles())
{
if (BFS.Application.GetMainFileByWindow(window).ToLower().Contains("outlook.exe") && BFS.Window.GetText(window).Contains(" " + "Reminder(s)"))
{
windowList.Add(window);
BFS.General.LogText("MoveOutlookReminderWindows: Window added to current list: " + window.ToString() + " " + windowList.Count.ToString());
}
}
return windowList;
}
}