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)
{
//location of MS Excel and file name
string excelLocation = "C:\\Program Files (x86)\\Microsoft Office\\Office14\\EXCEL.EXE";
string excelFile = "\"C:\\Documents\\Excel File Name.xlsx\"";
//shortFileText is a piece of the file's name, can be the whole file name without path
string shortFileText = "*Excel File*";
//check for the file, and if not open, do so
// if the file is already open, don't open another copy (Excel won't like it!)
IntPtr excelWindow = BFS.Window.GetWindowByText(shortFileText);
if (excelWindow == IntPtr.Zero)
{
uint appId = BFS.Application.Start(excelLocation, excelFile);
excelWindow = BFS.Application.GetMainWindowByAppID(appId);
//if we couldn't get the Excel window, exit the function
if (excelWindow == IntPtr.Zero)
return;
//make sure that the program is all the way open on the current monitor
BFS.General.ThreadWait(1200);
//then find it
excelWindow = BFS.Window.GetWindowByText(shortFileText);
//move file to Monitor 2
BFS.Window.MoveToMonitor(2, excelWindow);
}
//otherwise, just highlight the file
else
BFS.Window.Focus(excelWindow);
}
}