Binary Fortress
Binary Fortress Software
CheckCentral
ClipboardFusion
CloudShow
CloudShow Manager
DisplayFusion
FileSeek
HashTools
LogFusion
Notepad Replacer
Online Base64 Decoder
Online Base64 Encoder
Online JSON Formatter
ShellSend
TrayStatus
VoiceBot
WallpaperFusion
Window Inspector
More Apps...
DisplayFusion
CheckCentral
CloudShow
ClipboardFusion
FileSeek
TrayStatus
VoiceBot
WallpaperFusion
Display
Fusion
by Binary Fortress Software
Download
Download
Change Log
Download Beta
Beta Change Log
License (EULA)
Features
Free vs Pro
More
Screenshots
Scripted Functions (Macros)
Languages
Help
Help Guide
FAQ
Discussions
Contact Us
Find My License
Mailing Address
Advanced Settings
Purchase
Login / Register
WARNING: You currently have Javascript disabled!
This website will not function correctly without Javascript enabled.
Title
Message
OK
Confirm
Yes
No
Search for Window by File Name or Title if File Not Found
Return to DisplayFusion Scripted Functions (Macros)
Description
This script searches for a window by file name with a fall back to window text.
Language
C#.net
Minimum Version
9.2.2+
Created By
Gilad Barnea
Contributors
-
Date Created
May 25, 2018
Date Last Modified
May 25, 2018
Scripted Function (Macro) Code
Copy
Select All
using System; using System.Drawing; public static class DisplayFusionFunction { // Based on "Search for Window by Title" by Keith Lammers public static void Run (IntPtr windowHandle) { // OPTIONAL CUSTOMIZATION PARAMETERS // Will focus the window with a matching file rather than window title. If no file was found, will focus based on title. // For example, this will focus the actual spotify window if both spotify, and a chrome page about spotify, are running. // Set to false to reverse priority bool prioritize_file_over_title = false; // Set some value to if you want a common app to be available just by pressing enter. // Personally I set it to "chrome". string default_app = ""; // END CUSTOMIZATION // Prompt for the text to search for string searchText = BFS.Dialog.GetUserInput ("Enter part of the window title:", default_app); // Find the window with the matching file name IntPtr window_by_file = BFS.Application.GetMainWindowByFile ("*" + searchText + "*"); // Find by window title IntPtr window_by_title = BFS.Window.GetWindowByText ("*" + searchText + "*"); // If file name is prioritzed over window title (i.e. "spotify" over "beatles") if (prioritize_file_over_title) { FocusIfFound (window_by_file, window_by_title); // If window title was prioritized over file name ("beatles" over "spotify") } else { FocusIfFound (window_by_title, window_by_file); } } // Focus first_option if found. Else, focus second_option public static void FocusIfFound (IntPtr first_option, IntPtr second_option) { if (first_option.ToString () != "0") { BFS.Window.Focus (first_option); } else { BFS.Window.Focus (second_option); } } }