using System;
using System.Drawing;
using System.Runtime.InteropServices;
// 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
{
//this is the function that we will use to enumerate through child windows
[DllImport("user32.dll", PreserveSig = true, SetLastError = false, CharSet = CharSet.Unicode)]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, IntPtr lpszWindow );
public static void Run(IntPtr windowHandle)
{
string site1 = "https://www.displayfusion.com/";
string site2 = "https://www.checkcentral.cc/";
string site3 = "https://www.voicebot.net/";
//open site1 and move it to monitor 1
BFS.Application.Start("C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe", site1);
BFS.General.ThreadWait(3000);
BFS.Window.MoveToMonitorMaximized(1, GetIE11WindowByURL(site1));
BFS.General.ThreadWait(1000);
//open site2 and move it to monitor 2
BFS.Application.Start("C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe", site2);
BFS.General.ThreadWait(3000);
BFS.Window.MoveToMonitorMaximized(2, GetIE11WindowByURL(site2));
BFS.General.ThreadWait(1000);
//open site3 and move it to monitor 3
BFS.Application.Start("C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe", site3);
BFS.General.ThreadWait(3000);
BFS.Window.MoveToMonitorMaximized(3, GetIE11WindowByURL(site3));
}
//this function will accept a url and try to find an IE11 window with this url open in it
private static IntPtr GetIE11WindowByURL(string url)
{
//enumerate through all windows
foreach(IntPtr handle in BFS.Window.GetAllWindowHandles())
{
//if it isn't a IE window, continue
if(BFS.Application.GetMainFileByWindow(handle).IndexOf("iexplore.exe", StringComparison.OrdinalIgnoreCase) == -1)
continue;
//if it's not the type of IE window we want, continue
if(!BFS.Window.GetClass(handle).Equals("IEFrame", StringComparison.Ordinal))
continue;
//we found the IE window, try to find the address bar by searching through the levels. The address bar's class is called "Edit"
IntPtr addressBarHandle = FindWindowEx(handle, IntPtr.Zero, "WorkerW", IntPtr.Zero);
addressBarHandle = FindWindowEx(addressBarHandle, IntPtr.Zero, "ReBarWindow32", IntPtr.Zero);
addressBarHandle = FindWindowEx(addressBarHandle, IntPtr.Zero, "Address Band Root", IntPtr.Zero);
addressBarHandle = FindWindowEx(addressBarHandle, IntPtr.Zero, "Edit", IntPtr.Zero);
//if we couldn't find the address bar, continue
if(addressBarHandle == IntPtr.Zero)
continue;
//if the addressbar contains the url, return the parent window
if(BFS.Window.GetText(addressBarHandle).Equals(url, StringComparison.OrdinalIgnoreCase))
return handle;
}
//if we got this far we couldnt find anything. return IntPtr.Zero (null)
return IntPtr.Zero;
}
}