move-windows / get-process не возвращает все окна - PullRequest
0 голосов
/ 26 июня 2019

Я хочу переместить 2 окна приложения, и у меня есть следующий скрипт (который работает):

  Add-Type @"
  using System;
  using System.Runtime.InteropServices;
  public class Win32 {
    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);
    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
  }
  public struct RECT
  {
    public int Left;        // x position of upper-left corner
    public int Top;         // y position of upper-left corner
    public int Right;       // x position of lower-right corner
    public int Bottom;      // y position of lower-right corner
  }
"@


$rcWindow = New-Object RECT
$rcClient = New-Object RECT

function Move-Window ($handle, $x, $y, $w, $h) {
    [Win32]::GetWindowRect($handle,[ref]$rcWindow)
    [Win32]::GetClientRect($handle,[ref]$rcClient)

    $width = 1905
    $height = 900

    $dx = ($rcWindow.Right - $rcWindow.Left) - $rcClient.Right
    $dy = ($rcWindow.Bottom - $rcWindow.Top) - $rcClient.Bottom

    [Win32]::MoveWindow($handle, 0, 0, $width + $dx, $height + $dy, $true )
}

$l = @(Get-Process | where {$_.MainWindowTitle -like "App Name*"})
$h = $l[0].MainWindowHandle

Move-Window $h, 0, 0, 1905, 900

Моя проблема в том, что я не получаю дескрипторы для обоих окон, только для одного из2 окна.2. Заголовок окна 2. теперь переименован, но все равно я не получаю его через get-process.

Есть идеи, что я могу сделать, чтобы переместить второе окно?

МойВерсия Powershell (и у меня нет возможности обновить powershell):

Имя Значение
---- -----
CLRVersion 2.0.50727.8806
BuildVersion 6.1.7601.17514
PSVersion 2.0
WSManStackVersion 2.0
PSCompatibleVersions {1.0, 2.0}
SerializationVersion 1.1.0.1
PSRemotingProtocolVersion 2.1

Спасибо,

Ingo

...