KnowBrainer Speech Recognition
Decrease font size
Increase font size
Topic Title: Bring window to front
Topic Summary: A Script helper which forces a named window to the front
Created On: 04/05/2021 02:08 PM
Status: Post and Reply
Linear : Threading : Single : Branch
 Bring window to front   - Edgar - 04/05/2021 02:08 PM  
 Bring window to front   - Edgar - 04/05/2021 04:36 PM  
 Bring window to front   - Edgar - 04/05/2021 04:38 PM  
 Bring window to front   - Edgar - 04/05/2021 05:45 PM  
 Bring window to front   - kkkwj - 04/06/2021 01:06 AM  
 Bring window to front   - Edgar - 04/06/2021 10:10 AM  
 Bring window to front   - kkkwj - 04/06/2021 02:44 PM  
 Bring window to front   - Edgar - 04/06/2021 02:59 PM  
 Bring window to front   - PG LTU - 04/06/2021 04:07 PM  
 Bring window to front   - kkkwj - 04/06/2021 04:15 PM  
 Bring window to front   - Edgar - 04/06/2021 05:47 PM  
 Bring window to front   - alexander - 04/10/2021 09:34 PM  
 Bring window to front   - R. Wilke - 04/11/2021 01:06 PM  
 Bring window to front   - quintijn - 04/13/2021 11:09 AM  
 Bring window to front   - alexander - 04/13/2021 01:04 PM  
 Bring window to front   - R. Wilke - 04/13/2021 06:10 PM  
 Bring window to front   - alexander - 04/15/2021 04:26 PM  
 Bring window to front   - kkkwj - 04/14/2021 02:11 AM  
 Bring window to front   - R. Wilke - 04/14/2021 11:00 AM  
 Bring window to front   - kkkwj - 04/14/2021 11:00 PM  
 Bring window to front   - quintijn - 04/20/2021 12:07 PM  
 Bring window to front   - kkkwj - 04/20/2021 02:28 PM  
 Bring window to front   - Edgar - 04/20/2021 02:44 PM  
 Bring window to front   - BigTech - 04/20/2021 11:27 PM  
 Bring window to front   - BigTech - 04/22/2021 11:13 PM  
 Bring window to front   - quintijn - 04/28/2021 10:48 AM  
 Bring window to front   - BigTech - 05/03/2021 11:04 PM  
 Bring window to front   - kkkwj - 05/18/2021 03:01 PM  
 Bring window to front   - BigTech - 12/11/2021 05:22 PM  
 Bring window to front   - R. Wilke - 05/18/2021 04:05 PM  
 Bring window to front   - dilligence - 05/19/2021 10:25 AM  
 Bring window to front   - R. Wilke - 05/19/2021 03:19 PM  
 Bring window to front   - dilligence - 05/20/2021 11:49 AM  
 Bring window to front   - alexander - 06/17/2021 11:05 AM  
Keyword
 04/05/2021 02:08 PM
User is offline View Users Profile Print this message

Author Icon
Edgar
Top-Tier Member

Posts: 1265
Joined: 04/03/2009

Recent changes to Windows and/or Visual Studio has made it problematical - with both Dragon® and KnowBrainer, if you use "ShellExecute…" or "AppBringUp…" in a DVC or Advanced Scripting script AND the application opens a custom window/Form, the form probably will not display on the screen but it will in the taskbar.

I've been struggling with this and just thought of a solution… I have written a tiny console-style application (which does not open a console) which accepts a command line argument consisting of the title of the window you want to force to the front. Here is an example of a Dragon® DVC script:

ShellExecute "D:\\GetMousePosition\\GetMousePosition\\bin\\Release\\GetMousePosition.exe" & " " & _Arg1, 7

Wait 500

 

ShellExecute "D:\\BringWindowToFront\\BringWindowToFront\\BringWindowToFront\\bin\\Release\\BringWindowToFront.exe" & " " & "Mouse Coordinates"

In this case it forces a window with the title "Mouse Coordinates" (exact spelling is critical but capitalization is not) to come to the front of everything. The functional part of the code is only a few lines (here I have left out some error checking and the helper method "StringContainsPhrase"):

 

      static void Main(string[] args) {

         string inputParameter = string.Join(" ", args).Trim();

         Process[] processlist = Process.GetProcesses();

 

         foreach (Process process in processlist) {

            if (!String.IsNullOrEmpty(process.MainWindowTitle)) {

               if (StringContainsPhrase(inputParameter, process.MainWindowTitle)) {

                  NativeMethods.ShowWindowAsync(process.MainWindowHandle, NativeMethods.ShowWindowCommands.SW_SHOWDEFAULT);

                  NativeMethods.ShowWindowAsync(process.MainWindowHandle, NativeMethods.ShowWindowCommands.SW_SHOW);

                  NativeMethods.SetForegroundWindow(process.MainWindowHandle);

               }

            }

         }

      }

The complete Visual Studio 2019 solution is attached.






-------------------------

-Edgar
DPI 15.3, 64-bit Windows 10 Pro, OpenOffice & Office 365, Norton Security, Shure X2U XLR to USB mic adapter with Audio Technica DB135 vocal mic, Asus X299-Deluxe Prime, Intel Core i9-7940X (14 core, 4.3 GHz overclocked to 4.9 GHz), G.SKILL TridentZ Series 64GB (4 x 16GB) DDR4 3333 (PC4 26600) F4-3333C16Q-64GTZ, NVIDIA GIGABYTE GeForce GTX 1060 GV-N1060G1 GAMING-6GD REV 2.0 6GB graphics card with 3 1920x1080 monitors

Statistics
32307 users are registered to the KnowBrainer Speech Recognition forum.
There are currently 0 users logged in.
The most users ever online was 12124 on 09/09/2020 at 04:59 AM.
There are currently 419 guests browsing this forum, which makes a total of 419 users using this forum.

FuseTalk Standard Edition v4.0 - © 1999-2022 FuseTalk™ Inc. All rights reserved.