cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the FullName of current focus/VisibleOnScreen window?

SOLVED
Highlighted
Contributor

How to get the FullName of current focus/VisibleOnScreen window?

Hi all,

 

In VBScript, we used to hard-coded the parameter like this:

Set sDlg = Sys.Process("notepad").Window("Notepad", "New Text Document.txt - Notepad", 1)

 

Instead of hard-coded it, can we get the FullName of the object (window) which is currently focus / topmost on the screen?

 

Thanks.

 

-------

Edited:

Basically I want to make this parameter as a dynamic parameter which a function will get the current focus window's FullName and pass into the script. Is there any function able to do this?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: How to get the FullName of current focus/VisibleOnScreen window?

Hi,

 

Something like this (untested pseudocode):

  arWindows = <process>.FindAllChildren("WndClass", "*", 1).toArray(); // top-level children

  var strFullName = '';
  if (arWindows.length > 0)
  {
    for (var i = 0; i < arWindows.length; i++)
      if (arWindows[i].Focused)
      {
        strFullName = arWindows[i].FullName;
        break;
      }
  }

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

5 REPLIES 5
Highlighted
Community Hero

Re: How to get the FullName of current focus/VisibleOnScreen window?

Use Object Spy on the window - can you see FullName in there?

Highlighted
Contributor

Re: How to get the FullName of current focus/VisibleOnScreen window?

Hi @Marsha_R ,

 

Sorry that I should write the question in more details. I had updated the question.

 

I 'm looking for how to make the parameter (FullName) as a dynamic parameter. Which means we run the script and it will get the FullName of current focused window, then pass the parameter back into the script.

Highlighted
Community Hero

Re: How to get the FullName of current focus/VisibleOnScreen window?

Hi,

 

This is not possible out of the box. But you can search for all windows of the tested application up to certain depth and iterate through the obtained list and check the value of the .Focused property to determine the window that currently has input focus.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
Highlighted
Contributor

Re: How to get the FullName of current focus/VisibleOnScreen window?

Hi @AlexKaras ,

 

Thanks for the idea, it seems like possible to work on it. Is there any example to show how can we get the FullName of the window that currently has input focus?

Highlighted
Community Hero

Re: How to get the FullName of current focus/VisibleOnScreen window?

Hi,

 

Something like this (untested pseudocode):

  arWindows = <process>.FindAllChildren("WndClass", "*", 1).toArray(); // top-level children

  var strFullName = '';
  if (arWindows.length > 0)
  {
    for (var i = 0; i < arWindows.length; i++)
      if (arWindows[i].Focused)
      {
        strFullName = arWindows[i].FullName;
        break;
      }
  }

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors