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
// - Trigger target when run by a Trigger 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
{
[DllImport("User32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool IsWindowEnabled(IntPtr hWnd);
public static void Run(IntPtr windowHandle)
{
foreach(IntPtr window in BFS.Window.GetAllWindowHandles())
{
if(!IsPopupWindow(window))
continue;
//BFS.Dialog.ShowMessageInfo(BFS.Window.GetText(window));
BFS.Window.Focus(window);
}
}
private static bool IsPopupWindow(IntPtr handle)
{
// child windows cannot have owners
if((BFS.Window.GetWindowStyle(handle) & BFS.WindowEnum.WindowStyle.WS_CHILD__CHILDWINDOW) == BFS.WindowEnum.WindowStyle.WS_CHILD__CHILDWINDOW)
return false;
IntPtr owner = BFS.Window.GetOwner(handle);
// not an owned window
if(owner == IntPtr.Zero)
return false;
// window is enabled
if(!IsWindowEnabled(handle))
return false;
// window has text
if(String.IsNullOrEmpty(BFS.Window.GetText(handle)))
return false;
// owner is disabled
if(IsWindowEnabled(owner))
return false;
return true;
}
}