<commit_before>###############################################################################
#                                                                             #
#   File name       Window.ps1                                                #
#                                                                             #
#   Description     Manage windows (the rectangular screen areas, not the OS) #
#                                                                             #
#   Notes           Known issues with PowerShell v2:                          #
#                   * The default table columns ordering does not work.       #
#                   Workaround:                                               #
#                   Window.ps1 | ft -a hWnd,Program,Left,Top,Width,Height,Title
#                   * The window screen capture does not work.                #
#                                                                             #
#   History                                                                   #
#    2015-06-09 JFL Created this script.                                      #
#    2016-03-02 JFL Allow specifying either the title or the program name.    #
#    2016-03-30 JFL Allow specifying also the hWnd.			      #
#                   Display the program name by default, but not its path.    #
#    2016-06-01 JFL Made -Get the default command switch.		      #
#                   Allow passing in Window objects via the input pipe.       #
#                   Added the -Step switch to all spacing windows regularly.  #
#                   Added the -WhatIf switch to allow testing moves.          #
#    2016-06-02 JFL Added the -Capture command switch.			      #
#                   Added limited support for PowerShell v2.                  #
#                   Added the -Children switch to enumerate immediate children.
#                   Added the -All switch to enumerate all windows.           #
#    2016-06-03 JFL Get the Program name for all windows in the -All case.    #
#                   Added fields PID and Class to the window objects.         #
#                   Also enumerate popup windows by default.                  #
#                   Added a 100ms delay before screen captures, to give time  #
#                   to the system to redraw all fields that are reactivated.  #
#    2019-12-03 JFL Avoid displaying an error if there is no matching window. #
#    2020-04-23 JFL Avoid errors when modern apps (?) don't report a path.    #
#    2021-09-28 JFL Added WIN32 API RealGetWindowType().                      #
#                   Option -V displays the window Class and RealClass.        #
#                   Avoid listing Windows twice.                              #
#    2021-09-30 JFL Added the ability to select real File Explorer windows.   #
#    2021-10-01 JFL Added a ShellIndex field for File Explorer windows.       #
#    2021-10-02 JFL Improved the File Explorer/Control Panel distinction.     #
#    2021-10-04 JFL Added a Visible field. List only visible windows by dflt. #
#    2021-10-07 JFL Rewrote the siblings enumeration in C# to improve perf.   #
#    2021-10-08 JFL Moved all File Explorer-specific code to new ShellApp.ps1.#
#                   Factored-out the new Window object creation.              #
#                   Added back the hRootWnd and hTopWnd fields.               #
#                   Improved performance when receiving windows handles.      #
#                   Fixed the -Ontop operation.                               #
#                   Added a -Popups option to list popups.                    #
#    2021-10-11 JFL Added the thread start time.                              #
#                                                                             #
#          Copyright 2016 Hewlett Packard Enterprise Development LP          #
# Licensed under the Apache 2.0 license - www.apache.org/licenses/LICENSE-2.0 #
###############################################################################
#Requires -version 2

<#
  .SYNOPSIS
  Manage windows (the rectangular screen areas, not the Windows OS)

  .DESCRIPTION
  List windows, move them around, resize them, etc.

  .PARAMETER Get
  Command switch.
  This is the default action in the absence of other command arguments.
  Enumerate the main visible windows.
  In Verbose mode, also list non-visible windows.

  .PARAMETER MoveTo
  Command argument, optional.
  A pair of integers defining a screen coordinate: $left, $top
  Move the window top-left corner to that location. 
  Alias: -MT

  .PARAMETER Resize
  Command argument, optional.
  A pair of integers defining a size in pixels: $width, $height
  Set the window size. 
  Alias: -R

  .PARAMETER OnTop
  Command argument, optional.
  Redraw the window on top of the others.

  .PARAMETER Step
  Command argument, optional.
  A pair of integers: $horizonal, $vertical
  How much to shift each window top-left corner when moving several windows. 
  Alias: -S

  .PARAMETER Capture
  Command switch.
  Captures a window image, and copies it to the clipboard.
  Side effect: Moves the window on top of others.
  Note: If multiple windows are selected, only the last one will remain in the clipboard.
  This allows to easily capture popups, which are enumerated last, when selecting windows by program name or process ID.
  Alias: -C

  .PARAMETER Children
  Switch forcing the Get command to also enumerate the first level child windows.

  .PARAMETER Popups
  Switch forcing the Get command to also enumerate popup windows.

  .PARAMETER All
  Switch forcing the Get command to enumerate all top-level windows.
  This lists many minor windows not listed by default, like tray icons.
  Caution: This outputs a lot of data, and can take a significant amount of time.
  Note: Still ignores windows with 0 or 1 pixels, as these usually are hidden
  windows used for internal events processing.

  .PARAMETER InputObject
  A list of input objects defining the windows to work on. One of:
  - PSObjects returned by this script's -Get command.
  - Integers defining the window handle. 0 = Alias for the desktop window.
  - Strings defining the window title. Wildcards allowed.
  - Strings defining the program name. Wildcards allowed.
  Can also come from the input pipeline.

  .PARAMETER D
  Debug mode. Display lots of internal data about the windows enumeration.
  Alias: -Debug

  .PARAMETER V
  Verbose mode. Eumerate more windows, and display additional fields by default.
  Alias: -Verbose

  .PARAMETER X
  No-eXec mode. Display what windows would be moved, but don't move them.
  Alias: -WhatIf

  .PARAMETER Version
  Display this script version and exit.

  .EXAMPLE
  .\Window.ps1 | ft -a
  List all windows in a table, showing only the default data fields

  .EXAMPLE
  .\Window.ps1 ServerManager.exe | fl *
  List all Server Manager windows, showing all data fields

  .EXAMPLE
  .\Window.ps1 "Windows Update" -MoveTo 400,200 -Resize 875,640
  Move the Windows Update window to location (400,200) and resize it.

  .EXAMPLE
  .\Window.ps1 iexplore.exe -MoveTo 200,100 -OnTop
  Move the Internet Explorer window to location (200,100), and put it on top.

  .EXAMPLE
  .\Window.ps1 notepad* -MoveTo 200,100 -OnTop
  Move all Notepad windows, spacing them regularly, starting from location (200,100), and put them on top.

  .EXAMPLE
  .\Window.ps1 irc.exe | sort Title | .\Window.ps1 -MoveTo 200,100 -OnTop
  Idem for all iLO Remote Consoles, sorting them by title (= iLO name) first.
#>

[CmdletBinding(DefaultParameterSetName='Get')]
Param (
  [Parameter(ParameterSetName='Get', Mandatory=$false)]
  [Switch]$Get = $($PSCmdlet.ParameterSetName -eq 'Get'),	# Enumerate all windows

  [Parameter(ParameterSetName='Get', Mandatory=$false, ValueFromPipeline=$true, Position=0)]	# Default $InputObject is all in this case
  [Parameter(ParameterSetName='Move', Mandatory=$true, ValueFromPipeline=$true, Position=0)]	# Default $InputObject would be none in this case
  [Parameter(ParameterSetName='Capture', Mandatory=$true, ValueFromPipeline=$true, Position=0)] # Default $InputObject would be none in this case
  [AllowEmptyCollection()]
  [Object[]]$InputObject = @(),		# Windows to work on, or criteria for selecting them

  [Parameter(ParameterSetName='Move', Mandatory=$false)]
  [Int[]][alias("MT")]$MoveTo,		# Location where to move to

  [Parameter(ParameterSetName='Move', Mandatory=$false)]
  [Int[]][alias("R")]$Resize,		# New size to set

  [Parameter(ParameterSetName='Move', Mandatory=$false)]
  [Switch]$OnTop,			# Redraw it on top of the others

  [Parameter(ParameterSetName='Move', Mandatory=$false)]
  [Int[]][alias("S")]$Step = (100, 30),	# Step when moving multiple windows

  [Parameter(ParameterSetName='Capture', Mandatory=$true)]
  [Switch][alias("C")]$Capture,		# Capture the window image and copy it to the clipboard

  [Parameter(ParameterSetName='Get', Mandatory=$false)]
  [Switch]$Children,			# Also list child windows

  [Parameter(ParameterSetName='Get', Mandatory=$false)]
  [Switch]$Popups,			# Also list popup windows

  [Parameter(ParameterSetName='Get', Mandatory=$false)]
  [Switch]$All,				# List all top windows
<commit_msg>Updated a comment<commit_after>###############################################################################
#                                                                             #
#   File name       Window.ps1                                                #
#                                                                             #
#   Description     Manage windows (the rectangular screen areas, not the OS) #
#                                                                             #
#   Notes           Known issues with PowerShell v2:                          #
#                   * The default table columns ordering does not work.       #
#                   Workaround:                                               #
#                   Window.ps1 | ft -a hWnd,Program,Left,Top,Width,Height,Title
#                   * The window screen capture does not work.                #
#                                                                             #
#   History                                                                   #
#    2015-06-09 JFL Created this script.                                      #
#    2016-03-02 JFL Allow specifying either the title or the program name.    #
#    2016-03-30 JFL Allow specifying also the hWnd.			      #
#                   Display the program name by default, but not its path.    #
#    2016-06-01 JFL Made -Get the default command switch.		      #
#                   Allow passing in Window objects via the input pipe.       #
#                   Added the -Step switch to all spacing windows regularly.  #
#                   Added the -WhatIf switch to allow testing moves.          #
#    2016-06-02 JFL Added the -Capture command switch.			      #
#                   Added limited support for PowerShell v2.                  #
#                   Added the -Children switch to enumerate immediate children.
#                   Added the -All switch to enumerate all windows.           #
#    2016-06-03 JFL Get the Program name for all windows in the -All case.    #
#                   Added fields PID and Class to the window objects.         #
#                   Also enumerate popup windows by default.                  #
#                   Added a 100ms delay before screen captures, to give time  #
#                   to the system to redraw all fields that are reactivated.  #
#    2019-12-03 JFL Avoid displaying an error if there is no matching window. #
#    2020-04-23 JFL Avoid errors when modern apps (?) don't report a path.    #
#    2021-09-28 JFL Added WIN32 API RealGetWindowType().                      #
#                   Option -V displays the window Class and RealClass.        #
#                   Avoid listing Windows twice.                              #
#    2021-09-30 JFL Added the ability to select real File Explorer windows.   #
#    2021-10-01 JFL Added a ShellIndex field for File Explorer windows.       #
#    2021-10-02 JFL Improved the File Explorer/Control Panel distinction.     #
#    2021-10-04 JFL Added a Visible field. List only visible windows by dflt. #
#    2021-10-07 JFL Rewrote the siblings enumeration in C# to improve perf.   #
#    2021-10-08 JFL Moved all File Explorer-specific code to new ShellApp.ps1.#
#                   Factored-out the new Window object creation.              #
#                   Added back the hRootWnd and hTopWnd fields.               #
#                   Improved performance when receiving windows handles.      #
#                   Fixed the -Ontop operation.                               #
#                   Added a -Popups option to list popups.                    #
#    2021-10-11 JFL Added the thread start time.                              #
#                                                                             #
#          Copyright 2016 Hewlett Packard Enterprise Development LP          #
# Licensed under the Apache 2.0 license - www.apache.org/licenses/LICENSE-2.0 #
###############################################################################
#Requires -version 2

<#
  .SYNOPSIS
  Manage windows (the rectangular screen areas, not the Windows OS)

  .DESCRIPTION
  List windows, move them around, resize them, etc.

  .PARAMETER Get
  Command switch.
  This is the default action in the absence of other command arguments.
  Enumerate the main visible windows.
  In Verbose mode, also list non-visible windows.

  .PARAMETER MoveTo
  Command argument, optional.
  A pair of integers defining a screen coordinate: $left, $top
  Move the window top-left corner to that location. 
  Alias: -MT

  .PARAMETER Resize
  Command argument, optional.
  A pair of integers defining a size in pixels: $width, $height
  Set the window size. 
  Alias: -R

  .PARAMETER OnTop
  Command argument, optional.
  Redraw the window on top of the others.

  .PARAMETER Step
  Command argument, optional.
  A pair of integers: $horizonal, $vertical
  How much to shift each window top-left corner when moving several windows. 
  Alias: -S

  .PARAMETER Capture
  Command switch.
  Captures a window image, and copies it to the clipboard.
  Side effect: Moves the window on top of others.
  Note: If multiple windows are selected, only the last one will remain in the clipboard.
  This allows to easily capture popups, which are enumerated last, when selecting windows by program name or process ID.
  Alias: -C

  .PARAMETER Children
  Switch forcing the Get command to also enumerate the first level child windows.

  .PARAMETER Popups
  Switch forcing the Get command to also enumerate popup windows.

  .PARAMETER All
  Switch forcing the Get command to enumerate all top-level windows.
  This lists many minor windows not listed by default, like tray icons.
  Caution: This outputs a lot of data, and can take a significant amount of time.
  Note: Still ignores windows with 0 or 1 pixels, as these usually are hidden
  windows used for internal events processing.

  .PARAMETER InputObject
  A list of input objects defining the windows to work on. One of:
  - PSObjects returned by this script's -Get command.
  - Integers defining the window handle. 0 = Alias for the desktop window.
  - Strings defining the window title. Wildcards allowed.
  - Strings defining the program name. Wildcards allowed.
  Can also come from the input pipeline.

  .PARAMETER D
  Debug mode. Display lots of internal data about the windows enumeration.
  Alias: -Debug

  .PARAMETER V
  Verbose mode. Eumerate more windows, and display additional fields by default.
  Alias: -Verbose

  .PARAMETER X
  No-eXec mode. Display what windows would be moved, but don't move them.
  Alias: -WhatIf

  .PARAMETER Version
  Display this script version and exit.

  .EXAMPLE
  .\Window.ps1 | ft -a
  List all windows in a table, showing only the default data fields

  .EXAMPLE
  .\Window.ps1 ServerManager.exe | fl *
  List all Server Manager windows, showing all data fields

  .EXAMPLE
  .\Window.ps1 "Windows Update" -MoveTo 400,200 -Resize 875,640
  Move the Windows Update window to location (400,200) and resize it.

  .EXAMPLE
  .\Window.ps1 iexplore.exe -MoveTo 200,100 -OnTop
  Move the Internet Explorer window to location (200,100), and put it on top.

  .EXAMPLE
  .\Window.ps1 notepad* -MoveTo 200,100 -OnTop
  Move all Notepad windows, spacing them regularly, starting from location (200,100), and put them on top.

  .EXAMPLE
  .\Window.ps1 irc.exe | sort Title | .\Window.ps1 -MoveTo 200,100 -OnTop
  Idem for all iLO Remote Consoles, sorting them by title (= iLO name) first.
#>

[CmdletBinding(DefaultParameterSetName='Get')]
Param (
  [Parameter(ParameterSetName='Get', Mandatory=$false)]
  [Switch]$Get = $($PSCmdlet.ParameterSetName -eq 'Get'),	# Enumerate all windows

  [Parameter(ParameterSetName='Get', Mandatory=$false, ValueFromPipeline=$true, Position=0)]	# Default $InputObject is all in this case
  [Parameter(ParameterSetName='Move', Mandatory=$true, ValueFromPipeline=$true, Position=0)]	# Default $InputObject would be none in this case
  [Parameter(ParameterSetName='Capture', Mandatory=$true, ValueFromPipeline=$true, Position=0)] # Default $InputObject would be none in this case
  [AllowEmptyCollection()]
  [Object[]]$InputObject = @(),		# Windows to work on, or criteria for selecting them

  [Parameter(ParameterSetName='Move', Mandatory=$false)]
  [Int[]][alias("MT")]$MoveTo,		# Location where to move to

  [Parameter(ParameterSetName='Move', Mandatory=$false)]
  [Int[]][alias("R")]$Resize,		# New size to set

  [Parameter(ParameterSetName='Move', Mandatory=$false)]
  [Switch]$OnTop,			# Redraw it on top of the others

  [Parameter(ParameterSetName='Move', Mandatory=$false)]
  [Int[]][alias("S")]$Step = (100, 30),	# Step when moving multiple windows. Windows 10 defaults to (26, 26) when creating windows.

  [Parameter(ParameterSetName='Capture', Mandatory=$true)]
  [Switch][alias("C")]$Capture,		# Capture the window image and copy it to the clipboard

  [Parameter(ParameterSetName='Get', Mandatory=$false)]
  [Switch]$Children,			# Also list child windows

  [Parameter(ParameterSetName='Get', Mandatory=$false)]
  [Switch]$Popups,			# Also list popup windows

  [Parameter(ParameterSetName='Get', Mandatory=$false)]
  [Switch]$All,				# List all top windows

{'fraction_non_alphanumeric': 0.08957883369330454, 'fraction_numerical': 0.023326133909287255, 'mean_word_length': 2.1201145552560647, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 46, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3354062', 'n_tokens_mistral': 5116, 'n_tokens_neox': 4606, 'n_words': 1941}